serde-rs/test

Serialize to `Vec<serde_test::Token>`

Kinrany opened this issue · 2 comments

I wanted to write a unit test that would check all JSON fields for following camelCase.

I thought this would be very easy if I could serialize an example value as a raw stream of Serde values and check their contents directly, without having to recursively visit a tree structure.

serde_test::assert_tokens almost does this, except there's no way to convert a value into tokens.
I wish it could be assert_eq!(tokens(value), vec![...]).

Before this, at one point I considered having a trie with Serde values instead of string characters for storing a large number of similar serialized values and deduplicating them without paying the full cost of deserialization every time.

Is there something that does this? Are these reasonable things to want at all?

This functionality is not provided by serde_test, but Serializer impls defined outside of serde_test can produce Vec<serde_test::Token> as output. Example: https://docs.rs/serde_assert/0.5.0/serde_assert/struct.Serializer.html

Thank you!