WIP2: Scansion codegen
Signed-off-by: pep <pep@bouah.net>
This commit is contained in:
parent
e432c8b17e
commit
b5c7c2b579
7 changed files with 20 additions and 107 deletions
|
@ -22,14 +22,14 @@ jid = { version = "*" }
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
syntect = "5.0"
|
syntect = "5.0"
|
||||||
diff = "0.1"
|
diff = "0.1"
|
||||||
scansion = { version = "*" }
|
scansion = { version = "0.1" }
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
jid = { version = "*", features = ["minidom"] }
|
jid = { version = "*", features = ["minidom"] }
|
||||||
minidom = { version = "*" }
|
minidom = { version = "*" }
|
||||||
quote = "1.0"
|
quote = "1.0"
|
||||||
rand = "0.8"
|
rand = "0.8"
|
||||||
scansion = { version = "*" }
|
scansion = { version = "0.1", features = ["quote"] }
|
||||||
|
|
||||||
[patch.crates-io]
|
[patch.crates-io]
|
||||||
sasl = { git = "https://code.bouah.net/pep/xmpp-rs.git" }
|
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" }
|
minidom = { git = "https://code.bouah.net/pep/xmpp-rs.git" }
|
||||||
xmpp-parsers = { 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" }
|
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" }
|
||||||
|
|
27
build.rs
27
build.rs
|
@ -77,20 +77,15 @@ fn generate_spec_tokens(spec: Spec) -> Result<impl TokenStreamExt + Display, Min
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
println!("FOO1");
|
let (keys, values) =
|
||||||
|
context
|
||||||
let (context_keys, context_values) = context
|
.clone()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.fold((vec![], vec![]), |(mut keys, mut vals), (k, v)| {
|
.fold((vec![], vec![]), |(mut keys, mut values), (k, v)| {
|
||||||
println!("BAR0");
|
keys.push(quote! { #k });
|
||||||
keys.push(quote! { #k });
|
values.push(quote! { #v });
|
||||||
println!("BAR1");
|
(keys, values)
|
||||||
vals.push(quote! { #v });
|
});
|
||||||
println!("BAR2: {:?}; {:?}", keys, vals);
|
|
||||||
(keys, vals)
|
|
||||||
});
|
|
||||||
|
|
||||||
println!("FOO2");
|
|
||||||
|
|
||||||
Ok(quote! {
|
Ok(quote! {
|
||||||
#![doc = #docstr]
|
#![doc = #docstr]
|
||||||
|
@ -105,8 +100,8 @@ fn generate_spec_tokens(spec: Spec) -> Result<impl TokenStreamExt + Display, Min
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn spec() {
|
async fn spec() {
|
||||||
let context: ::scansion::Context = {
|
let context: ::scansion::Context = {
|
||||||
let tmp = ::std::collections::HashMap::new();
|
let mut tmp = ::std::collections::HashMap::new();
|
||||||
let (keys, values) = (vec![#(#context_keys),*], vec![#(#context_values),*]);
|
let (keys, values) = (vec![#(#keys),*], vec![#(#values),*]);
|
||||||
for (k, v) in keys.iter().zip(values.iter()) {
|
for (k, v) in keys.iter().zip(values.iter()) {
|
||||||
tmp.insert(String::from(*k), v.clone());
|
tmp.insert(String::from(*k), v.clone());
|
||||||
}
|
}
|
||||||
|
|
15
src/room.rs
15
src/room.rs
|
@ -462,14 +462,14 @@ impl Room {
|
||||||
let presence_join = Presence::new(PresenceType::None)
|
let presence_join = Presence::new(PresenceType::None)
|
||||||
.with_from(Jid::Full(new_session.participant().clone()));
|
.with_from(Jid::Full(new_session.participant().clone()));
|
||||||
|
|
||||||
let _presence_join_to_others = presence_join.clone().with_payloads(vec![MucUser {
|
let presence_join_to_others = presence_join.clone().with_payloads(vec![MucUser {
|
||||||
status: vec![],
|
status: vec![],
|
||||||
items: vec![MucItem::new(Affiliation::Owner, Role::Moderator)],
|
items: vec![MucItem::new(Affiliation::Owner, Role::Moderator)],
|
||||||
}
|
}
|
||||||
.into()]);
|
.into()]);
|
||||||
|
|
||||||
let occupant = self.get_occupant(&new_session)?;
|
let occupant = self.get_occupant(&new_session)?;
|
||||||
let _mucuser = MucUser {
|
let mucuser = MucUser {
|
||||||
status: vec![],
|
status: vec![],
|
||||||
items: {
|
items: {
|
||||||
occupant
|
occupant
|
||||||
|
@ -482,16 +482,6 @@ impl Room {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
self.broadcast_presence(
|
|
||||||
component,
|
|
||||||
self.get_occupant(&new_session)?,
|
|
||||||
new_session.presence.clone(),
|
|
||||||
BroadcastPresence::Update,
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
/*
|
|
||||||
for (nick, occupant) in self.occupants.iter() {
|
for (nick, occupant) in self.occupants.iter() {
|
||||||
for session in occupant.iter() {
|
for session in occupant.iter() {
|
||||||
// Self occupant
|
// Self occupant
|
||||||
|
@ -532,7 +522,6 @@ impl Room {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1 @@
|
||||||
#[doc = r" Scansion tests module."]
|
# [doc = r" Scansion tests module."] # [doc = r" These tests are generated by the build script, DO NOT EDIT."] # [cfg (test)] mod muc_create_destroy ; # [cfg (test)] mod muc_creation ; # [cfg (test)] mod self_ping_answer ;
|
||||||
#[doc = r" These tests are generated by the build script, DO NOT EDIT."]
|
|
||||||
#[cfg(test)]
|
|
||||||
mod muc_create_destroy;
|
|
||||||
#[cfg(test)]
|
|
||||||
mod muc_creation;
|
|
File diff suppressed because one or more lines are too long
|
@ -1,18 +1 @@
|
||||||
#![doc = "MUC Creation\nSingle user MUC creation\ntag: muc\n"]
|
# ! [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 ("<presence xmlns='jabber:client' from=\"louise@localhost/209\" to=\"room@muc.localhost/louise\">\n\t\t<x xmlns='http://jabber.org/protocol/muc'/>\n\t</presence>" . parse :: < Element > () . unwrap ()) . apply_context (& context)] ; let mut component = TestComponent :: new_scan (stanzas_in) ; let mut rooms : HashMap < BareJid , Room > = HashMap :: new () ; component . expect ("<presence xmlns='jabber:client' from=\"muc.localhost\" id=\"{scansion:any}\" to=\"louise@localhost/209\">\n\t\t<x xmlns='http://jabber.org/protocol/muc#user'>\n\t\t\t<status code=\"201\"/>\n\t\t\t<item affiliation=\"owner\" jid=\"louise@localhost/209\" role=\"moderator\"/>\n\t\t\t<statuc code=\"110\"/>\n\t\t</x>\n\t</presence>" . parse :: < ScanElement > () . unwrap () . apply_context (& context)) ; println ! ("FOO: {component:?}") ; handle_stanza (& mut component , & mut rooms) . await . unwrap () ; }
|
||||||
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 ("<presence xmlns='jabber:client' from=\"${louise's full JID}\" to=\"room@muc.localhost/louise\">\n\t\t<x xmlns='http://jabber.org/protocol/muc'/>\n\t</presence>" . parse :: < Element > () . unwrap ()) . with_context (Some (& context))] ;
|
|
||||||
let mut component = TestComponent::new_scan(stanzas_in);
|
|
||||||
let mut rooms: HashMap<BareJid, Room> = HashMap::new();
|
|
||||||
component . expect ("<presence xmlns='jabber:client' from=\"muc.localhost\" id=\"{scansion:any}\" to=\"${louise's full JID}\">\n\t\t<x xmlns='http://jabber.org/protocol/muc#user'>\n\t\t\t<status code=\"201\"/>\n\t\t\t<item affiliation=\"owner\" jid=\"${louise's full JID}\" role=\"moderator\"/>\n\t\t\t<statuc code=\"110\"/>\n\t\t</x>\n\t</presence>" . parse :: < ScanElement > () . unwrap () . with_context (Some (& context))) ;
|
|
||||||
println!("FOO: {component:?}");
|
|
||||||
handle_stanza(&mut component, &mut rooms).await.unwrap();
|
|
||||||
}
|
|
1
src/tests/scansion/self_ping_answer.rs
Normal file
1
src/tests/scansion/self_ping_answer.rs
Normal file
|
@ -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 ("<presence xmlns='jabber:client' from=\"louise@localhost/166\" to=\"news@muc.localhost/louise\">\n\t\t<x xmlns='http://jabber.org/protocol/muc'/>\n\t</presence>" . parse :: < Element > () . unwrap ()) . apply_context (& context) , ScanElement :: new ("<iq xmlns='jabber:client' from=\"louise@localhost/166\" id=\"foo\" to=\"news@muc.localhost/louise\">\n\t\t<query xmlns='urn:xmpp:ping'/>\n\t</iq>" . parse :: < Element > () . unwrap ()) . apply_context (& context)] ; let mut component = TestComponent :: new_scan (stanzas_in) ; let mut rooms : HashMap < BareJid , Room > = HashMap :: new () ; component . expect ("<presence xmlns='jabber:client' from=\"news@muc.localhost/louise\" to=\"louise@localhost/166\"/>" . parse :: < ScanElement > () . unwrap () . apply_context (& context)) ; component . expect ("<message xmlns='jabber:client' from=\"news@muc.localhost\" to=\"louise@localhost/166\" type=\"groupchat\"/>" . parse :: < ScanElement > () . unwrap () . apply_context (& context)) ; component . expect ("<iq xmlns='jabber:client' from=\"news@muc.localhost/louise\" id=\"foo\" to=\"louise@localhost/166\"/>" . parse :: < ScanElement > () . unwrap () . apply_context (& context)) ; println ! ("FOO: {component:?}") ; handle_stanza (& mut component , & mut rooms) . await . unwrap () ; }
|
Loading…
Reference in a new issue