Compare commits
1 commit
Author | SHA1 | Date | |
---|---|---|---|
e1d512e82f |
3 changed files with 48 additions and 56 deletions
16
Cargo.toml
16
Cargo.toml
|
@ -8,18 +8,14 @@ description = "Reimplementation of the Scansion project in Rust"
|
|||
|
||||
[dependencies]
|
||||
nom = "7.1"
|
||||
jid = { version = "*", features = [ "minidom" ] }
|
||||
jid = { version = "*", features = [ "minidom", "quote" ] }
|
||||
minidom = "*"
|
||||
xmpp-parsers = "0.20"
|
||||
nom_locate = "4.0.0"
|
||||
rand = "0.8"
|
||||
quote = { version = "1.0", optional = true }
|
||||
proc-macro2 = { version = "1.0", optional = true }
|
||||
proc-macro2 = "*"
|
||||
quote = "1.0"
|
||||
|
||||
[features]
|
||||
quote = ["dep:quote", "dep:proc-macro2", "jid/quote"]
|
||||
|
||||
[patch.crates-io]
|
||||
jid = { git = "https://gitlab.com/xmpp-rs/xmpp-rs" }
|
||||
minidom = { git = "https://gitlab.com/xmpp-rs/xmpp-rs" }
|
||||
xmpp-parsers = { git = "https://gitlab.com/xmpp-rs/xmpp-rs" }
|
||||
# [patch.crates-io]
|
||||
# jid = { path = "../xmpp-rs/jid" }
|
||||
# minidom = { path = "../xmpp-rs/minidom" }
|
||||
|
|
|
@ -715,7 +715,9 @@ mod tests {
|
|||
let elem3: Element = "<presence scansion:strict='false' xmlns='foo'><foo/>\n</presence>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem4: Element = "<presence xmlns='foo'><foo/>\t</presence>".parse().unwrap();
|
||||
let elem4: Element = "<presence xmlns='foo'><foo/>\t</presence>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let scan2 = ScanElement::new(elem3);
|
||||
|
||||
assert_eq!(scan2, elem4);
|
||||
|
@ -723,7 +725,9 @@ mod tests {
|
|||
let elem5: Element = "<presence scansion:strict='false' xmlns='foo'> <foo/>\n</presence>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem6: Element = "<presence xmlns='foo'><foo/>\t</presence>".parse().unwrap();
|
||||
let elem6: Element = "<presence xmlns='foo'><foo/>\t</presence>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let scan3 = ScanElement::new(elem5);
|
||||
|
||||
assert_eq!(scan3, elem6);
|
||||
|
@ -744,7 +748,9 @@ mod tests {
|
|||
let elem3: Element = "<presence scansion:strict='true' xmlns='foo'><foo/>\n</presence>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem4: Element = "<presence xmlns='foo'><foo/>\t</presence>".parse().unwrap();
|
||||
let elem4: Element = "<presence xmlns='foo'><foo/>\t</presence>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let scan2 = ScanElement::new(elem3);
|
||||
|
||||
assert_eq!(scan2, elem4);
|
||||
|
@ -752,7 +758,9 @@ mod tests {
|
|||
let elem5: Element = "<presence scansion:strict='true' xmlns='foo'> <foo/>\n</presence>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem6: Element = "<presence xmlns='foo'><foo/>\t</presence>".parse().unwrap();
|
||||
let elem6: Element = "<presence xmlns='foo'><foo/>\t</presence>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let scan3 = ScanElement::new(elem5);
|
||||
|
||||
assert_eq!(scan3, elem6);
|
||||
|
@ -763,7 +771,9 @@ mod tests {
|
|||
let elem1: Element = "<presence scansion:strict='false' xmlns='foo'>abc</presence>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem2: Element = "<presence xmlns='foo'> abc </presence>".parse().unwrap();
|
||||
let elem2: Element = "<presence xmlns='foo'> abc </presence>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let scan1 = ScanElement::new(elem1);
|
||||
|
||||
assert_ne!(scan1, elem2);
|
||||
|
@ -771,7 +781,9 @@ mod tests {
|
|||
let elem3: Element = "<presence scansion:strict='false' xmlns='foo'> </presence>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem4: Element = "<presence xmlns='foo'></presence>".parse().unwrap();
|
||||
let elem4: Element = "<presence xmlns='foo'></presence>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let scan2 = ScanElement::new(elem3);
|
||||
|
||||
assert_ne!(scan2, elem4);
|
||||
|
@ -782,7 +794,9 @@ mod tests {
|
|||
let elem1: Element = "<presence scansion:strict='true' xmlns='foo'>abc</presence>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem2: Element = "<presence xmlns='foo'> abc </presence>".parse().unwrap();
|
||||
let elem2: Element = "<presence xmlns='foo'> abc </presence>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let scan1 = ScanElement::new(elem1);
|
||||
|
||||
assert_ne!(scan1, elem2);
|
||||
|
@ -790,7 +804,9 @@ mod tests {
|
|||
let elem3: Element = "<presence scansion:strict='true' xmlns='foo'> </presence>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem4: Element = "<presence xmlns='foo'></presence>".parse().unwrap();
|
||||
let elem4: Element = "<presence xmlns='foo'></presence>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let scan2 = ScanElement::new(elem3);
|
||||
|
||||
assert_ne!(scan2, elem4);
|
||||
|
|
56
src/types.rs
56
src/types.rs
|
@ -7,9 +7,7 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use jid::Jid;
|
||||
#[cfg(feature = "quote")]
|
||||
use proc_macro2::TokenStream;
|
||||
#[cfg(feature = "quote")]
|
||||
use quote::{quote, ToTokens};
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
|
@ -71,39 +69,22 @@ impl Client {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "quote")]
|
||||
impl ToTokens for Client {
|
||||
fn to_tokens(&self, tokens: &mut TokenStream) {
|
||||
let jid = &self.jid;
|
||||
let password = &self.password;
|
||||
let custom_host = {
|
||||
let tmp = &self.custom_host;
|
||||
if self.custom_host.is_none() {
|
||||
quote! { None }
|
||||
} else {
|
||||
quote! { #tmp }
|
||||
}
|
||||
};
|
||||
let custom_port = {
|
||||
let tmp = &self.custom_port;
|
||||
if self.custom_port.is_none() {
|
||||
quote! { None }
|
||||
} else {
|
||||
quote! { #tmp }
|
||||
}
|
||||
};
|
||||
fn to_tokens(&self, tokens: &mut TokenStream) {
|
||||
let custom_host = if self.custom_host.is_none() { quote! { None } } else { quote! { #self.custom_host } };
|
||||
let custom_port = if self.custom_port.is_none() { quote! { None } } else { quote! { #self.custom_port } };
|
||||
|
||||
let t = quote! {
|
||||
Client {
|
||||
jid: #jid,
|
||||
password: String::from(#password),
|
||||
custom_host: #custom_host,
|
||||
custom_port: #custom_port,
|
||||
}
|
||||
};
|
||||
let t = quote! {
|
||||
Client {
|
||||
jid: #self.jid,
|
||||
password: String::from(#self.password),
|
||||
custom_host: #custom_host,
|
||||
custom_port: #custom_port,
|
||||
}
|
||||
};
|
||||
|
||||
tokens.extend(t);
|
||||
}
|
||||
tokens.extend(t);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
|
@ -111,13 +92,12 @@ pub enum Entity {
|
|||
Client(Client),
|
||||
}
|
||||
|
||||
#[cfg(feature = "quote")]
|
||||
impl ToTokens for Entity {
|
||||
fn to_tokens(&self, tokens: &mut TokenStream) {
|
||||
tokens.extend(match self {
|
||||
Entity::Client(client) => quote! { Entity::Client(#client) },
|
||||
});
|
||||
}
|
||||
fn to_tokens(&self, tokens: &mut TokenStream) {
|
||||
tokens.extend(match self {
|
||||
Entity::Client(client) => quote! { Entity::Client(#client) },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
pub type Context = HashMap<Name, Entity>;
|
||||
|
|
Loading…
Reference in a new issue