From 920a77ad617ea10e69a652047e1451466da81f0e Mon Sep 17 00:00:00 2001 From: Mingun Date: Wed, 28 Oct 2020 00:59:05 +0500 Subject: [PATCH 1/2] Fix incorrect messages in serialized tokens assertions Serializer contains expected tokens, called methods provide actual tokens --- serde_test/src/ser.rs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/serde_test/src/ser.rs b/serde_test/src/ser.rs index 0ff6c8289..a980a046a 100644 --- a/serde_test/src/ser.rs +++ b/serde_test/src/ser.rs @@ -32,18 +32,18 @@ impl<'a> Serializer<'a> { } macro_rules! assert_next_token { - ($ser:expr, $expected:ident) => { - assert_next_token!($ser, stringify!($expected), Token::$expected, true); + ($ser:expr, $actual:ident) => { + assert_next_token!($ser, stringify!($actual), Token::$actual, true); }; - ($ser:expr, $expected:ident($v:expr)) => { + ($ser:expr, $actual:ident($v:expr)) => { assert_next_token!( $ser, - format_args!(concat!(stringify!($expected), "({:?})"), $v), - Token::$expected(v), + format_args!(concat!(stringify!($actual), "({:?})"), $v), + Token::$actual(v), v == $v ); }; - ($ser:expr, $expected:ident { $($k:ident),* }) => { + ($ser:expr, $actual:ident { $($k:ident),* }) => { let compare = ($($k,)*); let field_format = || { use std::fmt::Write; @@ -55,21 +55,21 @@ macro_rules! assert_next_token { }; assert_next_token!( $ser, - format_args!(concat!(stringify!($expected), " {{ {}}}"), field_format()), - Token::$expected { $($k),* }, + format_args!(concat!(stringify!($actual), " {{ {}}}"), field_format()), + Token::$actual { $($k),* }, ($($k,)*) == compare ); }; - ($ser:expr, $expected:expr, $pat:pat, $guard:expr) => { + ($ser:expr, $actual:expr, $pat:pat, $guard:expr) => { match $ser.next_token() { Some($pat) if $guard => {} - Some(other) => { + Some(expected) => { panic!("expected Token::{} but serialized as {}", - $expected, other); + expected, $actual); } None => { - panic!("expected Token::{} after end of serialized tokens", - $expected); + panic!("expected end of tokens, but {} was serialized", + $actual); } } }; From 97c350a95e055be19f71fd5122f12915ef5550a6 Mon Sep 17 00:00:00 2001 From: Mingun Date: Wed, 28 Oct 2020 01:04:30 +0500 Subject: [PATCH 2/2] Forward Readable|Compact next_entry_seed to underlying next_entry_seed instead of usage of default implementation Difference is noticeable for deserializers that rely on call of next_entry_seed (for example, current quick-xml supports only next_entry_seed) --- serde_test/src/configure.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/serde_test/src/configure.rs b/serde_test/src/configure.rs index fb962c39c..d34ad9065 100644 --- a/serde_test/src/configure.rs +++ b/serde_test/src/configure.rs @@ -777,6 +777,17 @@ macro_rules! impl_deserializer { { self.0.next_value_seed($wrapper(seed)) } + fn next_entry_seed( + &mut self, + kseed: K, + vseed: V, + ) -> Result, D::Error> + where + K: DeserializeSeed<'de>, + V: DeserializeSeed<'de>, + { + self.0.next_entry_seed($wrapper(kseed), $wrapper(vseed)) + } fn size_hint(&self) -> Option { self.0.size_hint() }