From e9066c353dde3426ca3a07fd01d6c4e4be1aa530 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Mon, 14 Aug 2023 19:59:28 +0200 Subject: [PATCH] jid: Replace serde_json with serde_test in tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- jid/Cargo.toml | 4 ++-- jid/src/lib.rs | 45 +++++++-------------------------------------- 2 files changed, 9 insertions(+), 40 deletions(-) diff --git a/jid/Cargo.toml b/jid/Cargo.toml index df0f0fc2..f614c2f4 100644 --- a/jid/Cargo.toml +++ b/jid/Cargo.toml @@ -25,5 +25,5 @@ serde = { version = "1.0", features = ["derive"], optional = true } stringprep = "0.1.3" [dev-dependencies] -serde_json = "1" -jid = { path = ".", features = [ "serde" ] } \ No newline at end of file +serde_test = "1" +jid = { path = ".", features = [ "serde" ] } diff --git a/jid/src/lib.rs b/jid/src/lib.rs index f28ca3b9..59de6cd7 100644 --- a/jid/src/lib.rs +++ b/jid/src/lib.rs @@ -912,46 +912,15 @@ mod tests { assert_eq!(fulljid, FullJid::new("node@domain/resource").unwrap()); } - #[cfg(feature = "serde")] - #[derive(Serialize, Deserialize)] - struct JidContainer { - jid: T, - } - - #[cfg(feature = "serde")] - impl From for JidContainer { - fn from(jid: T) -> JidContainer { - 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] #[cfg(feature = "serde")] - fn jid_serialize() { - let jid: JidContainer = Jid::new("node@domain").unwrap().into(); - assert_eq!(BARE_JSON_STR, serde_json::to_string(&jid).unwrap()); - let jid: JidContainer = BareJid::new("node@domain").unwrap().into(); - assert_eq!(BARE_JSON_STR, serde_json::to_string(&jid).unwrap()); - let jid: JidContainer = FullJid::new("node@domain/resource").unwrap().into(); - assert_eq!(FULL_JSON_STR, serde_json::to_string(&jid).unwrap()); - } + fn jid_ser_de() { + let jid: Jid = Jid::new("node@domain").unwrap(); + serde_test::assert_tokens(&jid, &[serde_test::Token::Str("node@domain")]); + let jid: BareJid = BareJid::new("node@domain").unwrap(); + serde_test::assert_tokens(&jid, &[serde_test::Token::Str("node@domain")]); - #[test] - #[cfg(feature = "serde")] - fn jid_deserialize() { - let jid = Jid::new("node@domain").unwrap(); - let deser_jid: JidContainer = 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 = 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 = serde_json::from_str(FULL_JSON_STR).unwrap(); - assert_eq!(jid, deser_jid.jid); + let jid: FullJid = FullJid::new("node@domain/resource").unwrap(); + serde_test::assert_tokens(&jid, &[serde_test::Token::Str("node@domain/resource")]); } }