From 9d137e5e7dee36ac1f4782bf431499ed0c581a7e Mon Sep 17 00:00:00 2001 From: Fintan Halpenny Date: Thu, 8 Dec 2022 15:17:19 +0000 Subject: [PATCH] test: add roundtrip::json_value Adds a roundtrip helper for going to/from a json value. This can have slightly different semantics in comparison to/from a json string. Signed-off-by: Fintan Halpenny X-Clacks-Overhead: GNU Terry Pratchett --- test/test-helpers/src/roundtrip.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/test-helpers/src/roundtrip.rs b/test/test-helpers/src/roundtrip.rs index 16a7a14..1a102f9 100644 --- a/test/test-helpers/src/roundtrip.rs +++ b/test/test-helpers/src/roundtrip.rs @@ -20,6 +20,16 @@ where ) } +pub fn json_value(a: A) +where + for<'de> A: Clone + Debug + PartialEq + serde::Serialize + serde::Deserialize<'de>, +{ + assert_eq!( + a.clone(), + serde_json::from_value(serde_json::to_value(a).unwrap()).unwrap() + ) +} + pub fn cbor(a: A) where for<'de> A: Debug + PartialEq + minicbor::Encode + minicbor::Decode<'de>,