From dc172e49ca93460663e57196022f8b9a8d8d6fd1 Mon Sep 17 00:00:00 2001 From: "Heinz N. Gies" Date: Tue, 8 Oct 2024 16:47:16 +0200 Subject: [PATCH] Fix touple varriant serialisation with serde Signed-off-by: Heinz N. Gies --- src/serde/se.rs | 16 +++++++++++++++- src/tests/serde.rs | 3 --- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/serde/se.rs b/src/serde/se.rs index e7987182..d074dbcd 100644 --- a/src/serde/se.rs +++ b/src/serde/se.rs @@ -193,7 +193,7 @@ where if self.first { Ok(()) } else { - iomap!(self.s.write(b"}")) + iomap!(self.s.write(b"]}")) } } } @@ -815,6 +815,20 @@ mod test { #[cfg(not(target_arch = "wasm32"))] use proptest::prelude::*; + #[test] + fn enum_touple() { + #[derive(serde::Serialize, Clone)] + enum ErrType { + Instruction(i64, i64), + } + + let err = ErrType::Instruction(2, 68800); + + assert_eq!( + crate::to_string(&err).expect("failed to serialize"), + "{\"Instruction\":[2,68800]}", + ); + } #[test] fn print_serde() { #[derive(Clone, Debug, PartialEq, serde::Serialize)] diff --git a/src/tests/serde.rs b/src/tests/serde.rs index 8e3fa19b..998bf667 100644 --- a/src/tests/serde.rs +++ b/src/tests/serde.rs @@ -553,7 +553,6 @@ fn map1() { assert_eq!(to_value(d1), Ok(Value::from(h))); } -#[cfg(feature = "serde_impl")] #[test] fn tpl1() { let mut d = String::from("[-65.613616999999977, 43.420273000000009]"); @@ -701,7 +700,6 @@ fn crazy_string() { assert_eq!(v_simd, v_serde); } -#[cfg(feature = "serde_impl")] #[test] fn event() { #[derive(Deserialize, Debug, PartialEq, Eq)] @@ -825,7 +823,6 @@ fn arb_json() -> BoxedStrategy { .boxed() } -#[cfg(feature = "serde_impl")] #[test] fn int_map_key() -> Result<(), crate::Error> { use std::collections::BTreeMap;