You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am loving this crate. Thank you! But I think I found an issue in the Readable/Compact wrappers.
I am building a custom data structure that acts like a Map of UUIDs to integers. UUIDs from the UUID crate serialize as strings when human readable and plain bytes when compact, so I am calling Configure::readable() to mark the test case. However, when running the test, I still get the error that tells me I have not marked the case:
Types which have different human-readable and compact representations must explicitly mark their test cases with serde_test::Configure
Minimum Working Example
[dependencies]
serde = { version = "1.0.198", features = ["derive"] }
uuid = { version = "1.8.0", features = ["v4", "serde"] }
[dev-dependencies]
serde_test = "1.0.176"
#[cfg(test)]mod test_mwe {use std::collections::BTreeMap;use serde_test::{assert_tokens,Configure,Token};use uuid::{uuid,Uuid};/// Normal Uuid test shows difference between readable and compact./// This test passes.#[test]fntest_uuid(){constID_A:Uuid = uuid!("ae32aa4f-144f-44b1-a3cf-8a0f0b4ba44d");assert_tokens(&ID_A.readable(),// <-- Test case is marked&[Token::String("ae32aa4f-144f-44b1-a3cf-8a0f0b4ba44d")],);assert_tokens(&ID_A.compact(),&[Token::Bytes(ID_A.as_bytes())]);}// || test test_mwe::test_uuid ... ok/// A test with a Uuid inside a map./// Even though we do explicitly call `readable`, the test fails/// with an error telling us that we need to call `readable` or `compact`.#[test]fntest_map_of_uuid(){letmut vmap = BTreeMap::new();
vmap.insert(uuid!("ae32aa4f-144f-44b1-a3cf-8a0f0b4ba44d"),1asu64);assert_tokens(&vmap.readable(),// <-- Test case is marked&[Token::Map{len:Some(1)},Token::String("ae32aa4f-144f-44b1-a3cf-8a0f0b4ba44d"),Token::U64(1),Token::MapEnd,],);}// || test test_mwe::test_map_of_uuid ... FAILED// || failures:// || ---- model::test_serde::test_map_of_uuid stdout ----// || thread 'model::test_serde::test_map_of_uuid' panicked at// serde_test-1.0.176/src/ser.rs:307:9:// || Types which have different human-readable and compact representations// must explicitly mark their test cases with `serde_test::Configure`}
Possible Cause
I believe this has to do with the way Readable and Compact delegate to the unconfigured serde_test::ser::Serializer.
I followed the flow with gdb and saw this...
Readable::serialize_entry() delegates to Serializer::serialize_entry()
Hello,
I am loving this crate. Thank you! But I think I found an issue in the Readable/Compact wrappers.
I am building a custom data structure that acts like a Map of UUIDs to integers. UUIDs from the UUID crate serialize as strings when human readable and plain bytes when compact, so I am calling
Configure::readable()
to mark the test case. However, when running the test, I still get the error that tells me I have not marked the case:Minimum Working Example
Possible Cause
I believe this has to do with the way
Readable
andCompact
delegate to the unconfiguredserde_test::ser::Serializer
.I followed the flow with
gdb
and saw this...Readable::serialize_entry()
delegates toSerializer::serialize_entry()
Serializer::serialize_entry()
uses the default implementation in theserde::ser::SerializeMap
trait, which calls its ownserialize_key()
Serializer::serialize_key()
serializes the key, in this case a&Uuid
We make a brief stop in the generic
serde
crate'sderef_impl
macro,I think to dereference the
&Uuid
impl to get to theUuid
impl.The
serialize()
function for theUuid
checksis_human_readable()
on the originalSerializer
, not theReadable
wrapper.Serializer::is_human_readable()
panics.What do you think?
Thanks again!
-Murph
The text was updated successfully, but these errors were encountered: