Allow structs to be deserialized from sequences

This relies on the sequence to have the same ordering as the
struct field order.
This commit is contained in:
Erick Tryzelaar
2015-07-21 21:35:20 -07:00
parent b9a938a01c
commit dbe2beacb0
2 changed files with 101 additions and 5 deletions
+18 -2
View File
@@ -891,7 +891,7 @@ fn test_parse_struct() {
Inner { a: (), b: 2, c: vec!["abc".to_string(), "xyz".to_string()] }
]
},
)
),
]);
let v: Outer = from_str("{}").unwrap();
@@ -902,6 +902,22 @@ fn test_parse_struct() {
inner: vec![],
}
);
let v: Outer = from_str(
"[
[
[ null, 2, [\"abc\", \"xyz\"] ]
]
]").unwrap();
assert_eq!(
v,
Outer {
inner: vec![
Inner { a: (), b: 2, c: vec!["abc".to_string(), "xyz".to_string()] }
],
}
);
}
#[test]
@@ -934,7 +950,7 @@ fn test_parse_enum_errors() {
("{\"unknown\":[]}", Error::SyntaxError(ErrorCode::UnknownField("unknown".to_string()), 1, 11)),
("{\"Dog\":{}}", Error::SyntaxError(ErrorCode::ExpectedSomeValue, 1, 9)),
("{\"Frog\":{}}", Error::SyntaxError(ErrorCode::ExpectedSomeValue, 1, 10)),
("{\"Cat\":[]}", Error::SyntaxError(ErrorCode::ExpectedSomeValue, 1, 9)),
("{\"Cat\":[]}", Error::SyntaxError(ErrorCode::EOFWhileParsingValue, 1, 9)),
]);
}