diff --git a/Cargo.toml b/Cargo.toml index 9cf386d..85951bf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,14 +22,14 @@ jid = { version = "*" } [dev-dependencies] syntect = "5.0" diff = "0.1" -scansion = { version = "*" } +scansion = { version = "0.1" } [build-dependencies] jid = { version = "*", features = ["minidom"] } minidom = { version = "*" } quote = "1.0" rand = "0.8" -scansion = { version = "*" } +scansion = { version = "0.1", features = ["quote"] } [patch.crates-io] sasl = { git = "https://code.bouah.net/pep/xmpp-rs.git" } @@ -37,4 +37,4 @@ jid = { git = "https://code.bouah.net/pep/xmpp-rs.git", branch = "jid-quote" } minidom = { git = "https://code.bouah.net/pep/xmpp-rs.git" } xmpp-parsers = { git = "https://code.bouah.net/pep/xmpp-rs.git" } tokio-xmpp = { git = "https://code.bouah.net/pep/xmpp-rs.git" } -scansion = { git = "https://code.bouah.net/pep/scansion-rs", branch = "quote" } +scansion = { git = "https://code.bouah.net/pep/scansion-rs.git" } diff --git a/build.rs b/build.rs index f07018a..7d75d81 100644 --- a/build.rs +++ b/build.rs @@ -77,20 +77,15 @@ fn generate_spec_tokens(spec: Spec) -> Result>(); - println!("FOO1"); - - let (context_keys, context_values) = context - .into_iter() - .fold((vec![], vec![]), |(mut keys, mut vals), (k, v)| { - println!("BAR0"); - keys.push(quote! { #k }); - println!("BAR1"); - vals.push(quote! { #v }); - println!("BAR2: {:?}; {:?}", keys, vals); - (keys, vals) - }); - - println!("FOO2"); + let (keys, values) = + context + .clone() + .into_iter() + .fold((vec![], vec![]), |(mut keys, mut values), (k, v)| { + keys.push(quote! { #k }); + values.push(quote! { #v }); + (keys, values) + }); Ok(quote! { #![doc = #docstr] @@ -105,8 +100,8 @@ fn generate_spec_tokens(spec: Spec) -> Result\n\t\t\n\t" . parse :: < Element > () . unwrap ()) . with_context (Some (& context)) , ScanElement :: new ("\n\t\t\n\t\t\t\n\t\t\n\t" . parse :: < Element > () . unwrap ()) . with_context (Some (& context)) , ScanElement :: new ("\n\t\tWhere are thou my Juliet?\n\t" . parse :: < Element > () . unwrap ()) . with_context (Some (& context)) , ScanElement :: new ("\n\t\t\n\t" . parse :: < Element > () . unwrap ()) . with_context (Some (& context)) , ScanElement :: new ("\n\t\t/me jumps out from behind a tree\n\t" . parse :: < Element > () . unwrap ()) . with_context (Some (& context)) , ScanElement :: new ("\n\t\tHere I am!\n\t" . parse :: < Element > () . unwrap ()) . with_context (Some (& context)) , ScanElement :: new ("\n\t\tWhat is this place?\n\t" . parse :: < Element > () . unwrap ()) . with_context (Some (& context)) , ScanElement :: new ("\n\t\tI think we're in a script!\n\t" . parse :: < Element > () . unwrap ()) . with_context (Some (& context)) , ScanElement :: new ("\n\t\tOh no! Does that mean our love is not real?!\n\t" . parse :: < Element > () . unwrap ()) . with_context (Some (& context)) , ScanElement :: new ("\n\t\tI refuse to accept this! Let's burn this place to the ground!\n\t" . parse :: < Element > () . unwrap ()) . with_context (Some (& context)) , ScanElement :: new ("\n\t\tYes!\n\t" . parse :: < Element > () . unwrap ()) . with_context (Some (& context)) , ScanElement :: new ("\n\t\t\n\t\t\t\n\t\t\t\tWe refuse to live in this fantasy!\n\t\t\t\n\t\t\n\t" . parse :: < Element > () . unwrap ()) . with_context (Some (& context)) , ScanElement :: new ("\n\t\t\n\t" . parse :: < Element > () . unwrap ()) . with_context (Some (& context)) , ScanElement :: new ("\n\t\t\n\t\t\t\n\t\t\n\t" . parse :: < Element > () . unwrap ()) . with_context (Some (& context)) , ScanElement :: new ("\n\t\t\n\t\t\t\n\t\t\t\t\n\t\t\t\t\telsewhere@conference.localhost\n\t\t\t\t\n\t\t\t\n\t\t\n\t" . parse :: < Element > () . unwrap ()) . with_context (Some (& context))] ; - let mut component = TestComponent::new_scan(stanzas_in); - let mut rooms: HashMap = HashMap::new(); - component . expect ("\n\t\t\n\t\t\t\n\t\t\n\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\n\t" . parse :: < ScanElement > () . unwrap () . with_context (Some (& context))) ; - component . expect ("\n\t\t\n\t" . parse :: < ScanElement > () . unwrap () . with_context (Some (& context))) ; - component . expect ("" . parse :: < ScanElement > () . unwrap () . with_context (Some (& context))) ; - component . expect ("\n\t\tWhere are thou my Juliet?\n\t" . parse :: < ScanElement > () . unwrap () . with_context (Some (& context))) ; - component . expect ("\n\t\t\n\t\t\t\n\t\t\n\t\t\n\t\t\t\n\t\t\n\t" . parse :: < ScanElement > () . unwrap () . with_context (Some (& context))) ; - component . expect ("\n\t\t\n\t\t\t\n\t\t\n\t\t\n\t\t\t\n\t\t\t\n\t\t\n\t" . parse :: < ScanElement > () . unwrap () . with_context (Some (& context))) ; - component . expect ("\n\t\tWhere are thou my Juliet?\n\t\t\n\t" . parse :: < ScanElement > () . unwrap () . with_context (Some (& context))) ; - component . expect ("\n\t\t\n\t" . parse :: < ScanElement > () . unwrap () . with_context (Some (& context))) ; - component . expect ("\n\t\t\n\t\t\t\n\t\t\n\t\t\n\t\t\t\n\t\t\n\t" . parse :: < ScanElement > () . unwrap () . with_context (Some (& context))) ; - component . expect ("\n\t\t/me jumps out from behind a tree\n\t" . parse :: < ScanElement > () . unwrap () . with_context (Some (& context))) ; - component . expect ("\n\t\t/me jumps out from behind a tree\n\t" . parse :: < ScanElement > () . unwrap () . with_context (Some (& context))) ; - component . expect ("\n\t\tHere I am!\n\t" . parse :: < ScanElement > () . unwrap () . with_context (Some (& context))) ; - component . expect ("\n\t\tHere I am!\n\t" . parse :: < ScanElement > () . unwrap () . with_context (Some (& context))) ; - component . expect ("\n\t\tWhat is this place?\n\t" . parse :: < ScanElement > () . unwrap () . with_context (Some (& context))) ; - component . expect ("\n\t\tWhat is this place?\n\t" . parse :: < ScanElement > () . unwrap () . with_context (Some (& context))) ; - component . expect ("\n\t\tI think we're in a script!\n\t" . parse :: < ScanElement > () . unwrap () . with_context (Some (& context))) ; - component . expect ("\n\t\tI think we're in a script!\n\t" . parse :: < ScanElement > () . unwrap () . with_context (Some (& context))) ; - component . expect ("\n\t\tOh no! Does that mean our love is not real?!\n\t" . parse :: < ScanElement > () . unwrap () . with_context (Some (& context))) ; - component . expect ("\n\t\tOh no! Does that mean our love is not real?!\n\t" . parse :: < ScanElement > () . unwrap () . with_context (Some (& context))) ; - component . expect ("\n\t\tI refuse to accept this! Let's burn this place to the ground!\n\t" . parse :: < ScanElement > () . unwrap () . with_context (Some (& context))) ; - component . expect ("\n\t\tI refuse to accept this! Let's burn this place to the ground!\n\t" . parse :: < ScanElement > () . unwrap () . with_context (Some (& context))) ; - component . expect ("\n\t\tYes!\n\t" . parse :: < ScanElement > () . unwrap () . with_context (Some (& context))) ; - component . expect ("\n\t\tYes!\n\t" . parse :: < ScanElement > () . unwrap () . with_context (Some (& context))) ; - component . expect ("\n\t\t\n\t\t\t\n\t\t\t\tWe refuse to live in this fantasy!\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\n\t" . parse :: < ScanElement > () . unwrap () . with_context (Some (& context))) ; - component . expect ("\n\t\t\n\t\t\t\n\t\t\t\tWe refuse to live in this fantasy!\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\n\t" . parse :: < ScanElement > () . unwrap () . with_context (Some (& context))) ; - component . expect ("" . parse :: < ScanElement > () . unwrap () . with_context (Some (& context))) ; - component . expect ("\n\t\t\n\t\t\t\n\t\t\n\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\n\t" . parse :: < ScanElement > () . unwrap () . with_context (Some (& context))) ; - component . expect ("\n\t\t\n\t" . parse :: < ScanElement > () . unwrap () . with_context (Some (& context))) ; - component . expect ("" . parse :: < ScanElement > () . unwrap () . with_context (Some (& context))) ; - component . expect ("\n\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\n\t" . parse :: < ScanElement > () . unwrap () . with_context (Some (& context))) ; - component . expect ("\n\t\t\n\t\t\tThe following rooms were destroyed:\nelsewhere@conference.localhost\n\t\t\n\t" . parse :: < ScanElement > () . unwrap () . with_context (Some (& context))) ; - println!("FOO: {component:?}"); - handle_stanza(&mut component, &mut rooms).await.unwrap(); -} +# ! [doc = "MUC creation, basic messages and destruction\n"] use crate :: component :: TestComponent ; use crate :: handlers :: handle_stanza ; use crate :: room :: Room ; use :: std :: collections :: HashMap ; use :: xmpp_parsers :: { Jid , BareJid , FullJid , Element } ; use :: scansion :: { ScanElement , Entity , Client } ; # [tokio :: test] async fn spec () { let context : :: scansion :: Context = { let mut tmp = :: std :: collections :: HashMap :: new () ; let (keys , values) = (vec ! ["Juliet" , "Romeo" , "Admin"] , vec ! [Entity :: Client (Client { jid : Jid :: Full (FullJid :: new ("juliet@localhost/lVwkim_k") . unwrap ()) , password : String :: from ("password") , custom_host : None , custom_port : None , }) , Entity :: Client (Client { jid : Jid :: Full (FullJid :: new ("romeo@localhost/mK0dD6Ha") . unwrap ()) , password : String :: from ("password") , custom_host : None , custom_port : None , }) , Entity :: Client (Client { jid : Jid :: Full (FullJid :: new ("admin@localhost/DfNgg9VE") . unwrap ()) , password : String :: from ("password") , custom_host : None , custom_port : None , })]) ; for (k , v) in keys . iter () . zip (values . iter ()) { tmp . insert (String :: from (* k) , v . clone ()) ; } tmp } ; let stanzas_in = vec ! [ScanElement :: new ("\n\t\t\n\t" . parse :: < Element > () . unwrap ()) . apply_context (& context) , ScanElement :: new ("\n\t\t\n\t\t\t\n\t\t\n\t" . parse :: < Element > () . unwrap ()) . apply_context (& context) , ScanElement :: new ("\n\t\tWhere are thou my Juliet?\n\t" . parse :: < Element > () . unwrap ()) . apply_context (& context) , ScanElement :: new ("\n\t\t\n\t" . parse :: < Element > () . unwrap ()) . apply_context (& context) , ScanElement :: new ("\n\t\t/me jumps out from behind a tree\n\t" . parse :: < Element > () . unwrap ()) . apply_context (& context) , ScanElement :: new ("\n\t\tHere I am!\n\t" . parse :: < Element > () . unwrap ()) . apply_context (& context) , ScanElement :: new ("\n\t\tWhat is this place?\n\t" . parse :: < Element > () . unwrap ()) . apply_context (& context) , ScanElement :: new ("\n\t\tI think we're in a script!\n\t" . parse :: < Element > () . unwrap ()) . apply_context (& context) , ScanElement :: new ("\n\t\tOh no! Does that mean our love is not real?!\n\t" . parse :: < Element > () . unwrap ()) . apply_context (& context) , ScanElement :: new ("\n\t\tI refuse to accept this! Let's burn this place to the ground!\n\t" . parse :: < Element > () . unwrap ()) . apply_context (& context) , ScanElement :: new ("\n\t\tYes!\n\t" . parse :: < Element > () . unwrap ()) . apply_context (& context) , ScanElement :: new ("\n\t\t\n\t\t\t\n\t\t\t\tWe refuse to live in this fantasy!\n\t\t\t\n\t\t\n\t" . parse :: < Element > () . unwrap ()) . apply_context (& context) , ScanElement :: new ("\n\t\t\n\t" . parse :: < Element > () . unwrap ()) . apply_context (& context) , ScanElement :: new ("\n\t\t\n\t\t\t\n\t\t\n\t" . parse :: < Element > () . unwrap ()) . apply_context (& context) , ScanElement :: new ("\n\t\t\n\t\t\t\n\t\t\t\t\n\t\t\t\t\telsewhere@conference.localhost\n\t\t\t\t\n\t\t\t\n\t\t\n\t" . parse :: < Element > () . unwrap ()) . apply_context (& context)] ; let mut component = TestComponent :: new_scan (stanzas_in) ; let mut rooms : HashMap < BareJid , Room > = HashMap :: new () ; component . expect ("\n\t\t\n\t\t\t\n\t\t\n\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\n\t" . parse :: < ScanElement > () . unwrap () . apply_context (& context)) ; component . expect ("\n\t\t\n\t" . parse :: < ScanElement > () . unwrap () . apply_context (& context)) ; component . expect ("" . parse :: < ScanElement > () . unwrap () . apply_context (& context)) ; component . expect ("\n\t\tWhere are thou my Juliet?\n\t" . parse :: < ScanElement > () . unwrap () . apply_context (& context)) ; component . expect ("\n\t\t\n\t\t\t\n\t\t\n\t\t\n\t\t\t\n\t\t\n\t" . parse :: < ScanElement > () . unwrap () . apply_context (& context)) ; component . expect ("\n\t\t\n\t\t\t\n\t\t\n\t\t\n\t\t\t\n\t\t\t\n\t\t\n\t" . parse :: < ScanElement > () . unwrap () . apply_context (& context)) ; component . expect ("\n\t\tWhere are thou my Juliet?\n\t\t\n\t" . parse :: < ScanElement > () . unwrap () . apply_context (& context)) ; component . expect ("\n\t\t\n\t" . parse :: < ScanElement > () . unwrap () . apply_context (& context)) ; component . expect ("\n\t\t\n\t\t\t\n\t\t\n\t\t\n\t\t\t\n\t\t\n\t" . parse :: < ScanElement > () . unwrap () . apply_context (& context)) ; component . expect ("\n\t\t/me jumps out from behind a tree\n\t" . parse :: < ScanElement > () . unwrap () . apply_context (& context)) ; component . expect ("\n\t\t/me jumps out from behind a tree\n\t" . parse :: < ScanElement > () . unwrap () . apply_context (& context)) ; component . expect ("\n\t\tHere I am!\n\t" . parse :: < ScanElement > () . unwrap () . apply_context (& context)) ; component . expect ("\n\t\tHere I am!\n\t" . parse :: < ScanElement > () . unwrap () . apply_context (& context)) ; component . expect ("\n\t\tWhat is this place?\n\t" . parse :: < ScanElement > () . unwrap () . apply_context (& context)) ; component . expect ("\n\t\tWhat is this place?\n\t" . parse :: < ScanElement > () . unwrap () . apply_context (& context)) ; component . expect ("\n\t\tI think we're in a script!\n\t" . parse :: < ScanElement > () . unwrap () . apply_context (& context)) ; component . expect ("\n\t\tI think we're in a script!\n\t" . parse :: < ScanElement > () . unwrap () . apply_context (& context)) ; component . expect ("\n\t\tOh no! Does that mean our love is not real?!\n\t" . parse :: < ScanElement > () . unwrap () . apply_context (& context)) ; component . expect ("\n\t\tOh no! Does that mean our love is not real?!\n\t" . parse :: < ScanElement > () . unwrap () . apply_context (& context)) ; component . expect ("\n\t\tI refuse to accept this! Let's burn this place to the ground!\n\t" . parse :: < ScanElement > () . unwrap () . apply_context (& context)) ; component . expect ("\n\t\tI refuse to accept this! Let's burn this place to the ground!\n\t" . parse :: < ScanElement > () . unwrap () . apply_context (& context)) ; component . expect ("\n\t\tYes!\n\t" . parse :: < ScanElement > () . unwrap () . apply_context (& context)) ; component . expect ("\n\t\tYes!\n\t" . parse :: < ScanElement > () . unwrap () . apply_context (& context)) ; component . expect ("\n\t\t\n\t\t\t\n\t\t\t\tWe refuse to live in this fantasy!\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\n\t" . parse :: < ScanElement > () . unwrap () . apply_context (& context)) ; component . expect ("\n\t\t\n\t\t\t\n\t\t\t\tWe refuse to live in this fantasy!\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\n\t" . parse :: < ScanElement > () . unwrap () . apply_context (& context)) ; component . expect ("" . parse :: < ScanElement > () . unwrap () . apply_context (& context)) ; component . expect ("\n\t\t\n\t\t\t\n\t\t\n\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\n\t" . parse :: < ScanElement > () . unwrap () . apply_context (& context)) ; component . expect ("\n\t\t\n\t" . parse :: < ScanElement > () . unwrap () . apply_context (& context)) ; component . expect ("" . parse :: < ScanElement > () . unwrap () . apply_context (& context)) ; component . expect ("\n\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\n\t" . parse :: < ScanElement > () . unwrap () . apply_context (& context)) ; component . expect ("\n\t\t\n\t\t\tThe following rooms were destroyed:\nelsewhere@conference.localhost\n\t\t\n\t" . parse :: < ScanElement > () . unwrap () . apply_context (& context)) ; println ! ("FOO: {component:?}") ; handle_stanza (& mut component , & mut rooms) . await . unwrap () ; } \ No newline at end of file diff --git a/src/tests/scansion/muc_creation.rs b/src/tests/scansion/muc_creation.rs index 82d5177..752f12c 100644 --- a/src/tests/scansion/muc_creation.rs +++ b/src/tests/scansion/muc_creation.rs @@ -1,18 +1 @@ -#![doc = "MUC Creation\nSingle user MUC creation\ntag: muc\n"] -use crate::component::TestComponent; -use crate::handlers::handle_stanza; -use crate::room::Room; -use scansion::ScanElement; -use std::collections::HashMap; -use xmpp_parsers::{BareJid, Element}; -#[tokio::test] -async fn spec() { - println!("FOO0: {:?}", "louise\n"); - println!("FOO0: {:?}", "louise@localhost/194\n"); - let stanzas_in = vec ! [ScanElement :: new ("\n\t\t\n\t" . parse :: < Element > () . unwrap ()) . with_context (Some (& context))] ; - let mut component = TestComponent::new_scan(stanzas_in); - let mut rooms: HashMap = HashMap::new(); - component . expect ("\n\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\n\t" . parse :: < ScanElement > () . unwrap () . with_context (Some (& context))) ; - println!("FOO: {component:?}"); - handle_stanza(&mut component, &mut rooms).await.unwrap(); -} +# ! [doc = "MUC Creation\nSingle user MUC creation\ntag: muc\n"] use crate :: component :: TestComponent ; use crate :: handlers :: handle_stanza ; use crate :: room :: Room ; use :: std :: collections :: HashMap ; use :: xmpp_parsers :: { Jid , BareJid , FullJid , Element } ; use :: scansion :: { ScanElement , Entity , Client } ; # [tokio :: test] async fn spec () { let context : :: scansion :: Context = { let mut tmp = :: std :: collections :: HashMap :: new () ; let (keys , values) = (vec ! ["louise"] , vec ! [Entity :: Client (Client { jid : Jid :: Full (FullJid :: new ("louise@localhost/209") . unwrap ()) , password : String :: from ("password") , custom_host : None , custom_port : None , })]) ; for (k , v) in keys . iter () . zip (values . iter ()) { tmp . insert (String :: from (* k) , v . clone ()) ; } tmp } ; let stanzas_in = vec ! [ScanElement :: new ("\n\t\t\n\t" . parse :: < Element > () . unwrap ()) . apply_context (& context)] ; let mut component = TestComponent :: new_scan (stanzas_in) ; let mut rooms : HashMap < BareJid , Room > = HashMap :: new () ; component . expect ("\n\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\n\t" . parse :: < ScanElement > () . unwrap () . apply_context (& context)) ; println ! ("FOO: {component:?}") ; handle_stanza (& mut component , & mut rooms) . await . unwrap () ; } \ No newline at end of file diff --git a/src/tests/scansion/self_ping_answer.rs b/src/tests/scansion/self_ping_answer.rs new file mode 100644 index 0000000..d3bf290 --- /dev/null +++ b/src/tests/scansion/self_ping_answer.rs @@ -0,0 +1 @@ +# ! [doc = "XEP-0410: MUC Self-Ping\ntag: XEP-0410\ntag: muc\ntag: self-ping\n"] use crate :: component :: TestComponent ; use crate :: handlers :: handle_stanza ; use crate :: room :: Room ; use :: std :: collections :: HashMap ; use :: xmpp_parsers :: { Jid , BareJid , FullJid , Element } ; use :: scansion :: { ScanElement , Entity , Client } ; # [tokio :: test] async fn spec () { let context : :: scansion :: Context = { let mut tmp = :: std :: collections :: HashMap :: new () ; let (keys , values) = (vec ! ["Louise"] , vec ! [Entity :: Client (Client { jid : Jid :: Full (FullJid :: new ("louise@localhost/166") . unwrap ()) , password : String :: from ("acab") , custom_host : None , custom_port : None , })]) ; for (k , v) in keys . iter () . zip (values . iter ()) { tmp . insert (String :: from (* k) , v . clone ()) ; } tmp } ; let stanzas_in = vec ! [ScanElement :: new ("\n\t\t\n\t" . parse :: < Element > () . unwrap ()) . apply_context (& context) , ScanElement :: new ("\n\t\t\n\t" . parse :: < Element > () . unwrap ()) . apply_context (& context)] ; let mut component = TestComponent :: new_scan (stanzas_in) ; let mut rooms : HashMap < BareJid , Room > = HashMap :: new () ; component . expect ("" . parse :: < ScanElement > () . unwrap () . apply_context (& context)) ; component . expect ("" . parse :: < ScanElement > () . unwrap () . apply_context (& context)) ; component . expect ("" . parse :: < ScanElement > () . unwrap () . apply_context (& context)) ; println ! ("FOO: {component:?}") ; handle_stanza (& mut component , & mut rooms) . await . unwrap () ; } \ No newline at end of file