-
-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replacing serde_json
by serde_tests
for tests
#549
Comments
Just to provide this as a strarting point: I did try out #[test]
fn test_serialize_fragment() {
let fragments = [
Fragment::Line {
data: b"A LOGIN alice {2}\r\n".to_vec(),
},
Fragment::Literal {
data: b"\xCA\xFE".to_vec(),
mode: LiteralMode::Sync,
},
Fragment::Line {
data: b"\r\n".to_vec(),
},
];
// using serde_json
assert_eq!(
serde_json::to_string(&fragments).unwrap(),
r#"[{"Line":{"data":[65,32,76,79,71,73,78,32,97,108,105,99,101,32,123,50,125,13,10]}},{"Literal":{"data":[202,254],"mode":"Sync"}},{"Line":{"data":[13,10]}}]"#
);
// using serde_test
assert_ser_tokens(
&fragments,
&[
Token::Tuple { len: 3 },
Token::StructVariant {
name: "Fragment",
variant: "Line",
len: 1,
},
Token::Str("data"),
Token::Seq { len: Some(19) },
Token::U8(65),
Token::U8(32),
Token::U8(76),
Token::U8(79),
Token::U8(71),
Token::U8(73),
Token::U8(78),
Token::U8(32),
Token::U8(97),
Token::U8(108),
Token::U8(105),
Token::U8(99),
Token::U8(101),
Token::U8(32),
Token::U8(123),
Token::U8(50),
Token::U8(125),
Token::U8(13),
Token::U8(10),
Token::SeqEnd,
Token::StructVariantEnd,
Token::StructVariant {
name: "Fragment",
variant: "Literal",
len: 2,
},
Token::Str("data"),
Token::Seq { len: Some(2) },
Token::U8(202),
Token::U8(254),
Token::SeqEnd,
Token::Str("mode"),
Token::UnitVariant {
name: "LiteralMode",
variant: "Sync",
},
Token::StructVariantEnd,
Token::StructVariant {
name: "Fragment",
variant: "Line",
len: 1,
},
Token::Str("data"),
Token::Seq { len: Some(2) },
Token::U8(13),
Token::U8(10),
Token::SeqEnd,
Token::StructVariantEnd,
Token::TupleEnd,
],
); |
minor nit: title talks about |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Currently, the unit tests for
Deserialize
/Serialize
implementation are based onserde_json
.serde_test
might to be a more fitting alternative to be used in unit tests.It should be evaluated and, if reasonable, used for replacing all
serde_json
-based unit tests.The text was updated successfully, but these errors were encountered: