mirror of
https://gitlab.com/xmpp-rs/xmpp-rs.git
synced 2024-07-12 22:21:53 +00:00
jid: Replace serde_json with serde_test in tests
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
parent
2f808f161f
commit
e9066c353d
2 changed files with 9 additions and 40 deletions
|
@ -25,5 +25,5 @@ serde = { version = "1.0", features = ["derive"], optional = true }
|
||||||
stringprep = "0.1.3"
|
stringprep = "0.1.3"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
serde_json = "1"
|
serde_test = "1"
|
||||||
jid = { path = ".", features = [ "serde" ] }
|
jid = { path = ".", features = [ "serde" ] }
|
|
@ -912,46 +912,15 @@ mod tests {
|
||||||
assert_eq!(fulljid, FullJid::new("node@domain/resource").unwrap());
|
assert_eq!(fulljid, FullJid::new("node@domain/resource").unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "serde")]
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
struct JidContainer<T> {
|
|
||||||
jid: T,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "serde")]
|
|
||||||
impl<T> From<T> for JidContainer<T> {
|
|
||||||
fn from(jid: T) -> JidContainer<T> {
|
|
||||||
JidContainer { jid }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "serde")]
|
|
||||||
const BARE_JSON_STR: &'static str = "{\"jid\":\"node@domain\"}";
|
|
||||||
#[cfg(feature = "serde")]
|
|
||||||
const FULL_JSON_STR: &'static str = "{\"jid\":\"node@domain/resource\"}";
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
fn jid_serialize() {
|
fn jid_ser_de() {
|
||||||
let jid: JidContainer<Jid> = Jid::new("node@domain").unwrap().into();
|
let jid: Jid = Jid::new("node@domain").unwrap();
|
||||||
assert_eq!(BARE_JSON_STR, serde_json::to_string(&jid).unwrap());
|
serde_test::assert_tokens(&jid, &[serde_test::Token::Str("node@domain")]);
|
||||||
let jid: JidContainer<BareJid> = BareJid::new("node@domain").unwrap().into();
|
let jid: BareJid = BareJid::new("node@domain").unwrap();
|
||||||
assert_eq!(BARE_JSON_STR, serde_json::to_string(&jid).unwrap());
|
serde_test::assert_tokens(&jid, &[serde_test::Token::Str("node@domain")]);
|
||||||
let jid: JidContainer<FullJid> = FullJid::new("node@domain/resource").unwrap().into();
|
|
||||||
assert_eq!(FULL_JSON_STR, serde_json::to_string(&jid).unwrap());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
let jid: FullJid = FullJid::new("node@domain/resource").unwrap();
|
||||||
#[cfg(feature = "serde")]
|
serde_test::assert_tokens(&jid, &[serde_test::Token::Str("node@domain/resource")]);
|
||||||
fn jid_deserialize() {
|
|
||||||
let jid = Jid::new("node@domain").unwrap();
|
|
||||||
let deser_jid: JidContainer<Jid> = serde_json::from_str(BARE_JSON_STR).unwrap();
|
|
||||||
assert_eq!(jid, deser_jid.jid);
|
|
||||||
let jid = BareJid::new("node@domain").unwrap();
|
|
||||||
let deser_jid: JidContainer<BareJid> = serde_json::from_str(BARE_JSON_STR).unwrap();
|
|
||||||
assert_eq!(jid, deser_jid.jid);
|
|
||||||
let jid = FullJid::new("node@domain/resource").unwrap();
|
|
||||||
let deser_jid: JidContainer<FullJid> = serde_json::from_str(FULL_JSON_STR).unwrap();
|
|
||||||
assert_eq!(jid, deser_jid.jid);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue