Assert tokens are empty after reaching error
This commit is contained in:
parent
6d64104375
commit
093201abfb
@ -22,13 +22,14 @@ pub fn assert_ser_tokens<T>(value: &T, tokens: &[Token])
|
||||
assert_eq!(ser.next_token(), None);
|
||||
}
|
||||
|
||||
// Expect an error deserializing tokens into a T
|
||||
// Expect an error serializing T
|
||||
pub fn assert_ser_tokens_error<T>(value: &T, tokens: &[Token], error: Error)
|
||||
where T: Serialize + PartialEq + Debug,
|
||||
{
|
||||
let mut ser = Serializer::new(tokens.iter());
|
||||
let v: Result<(), Error> = Serialize::serialize(value, &mut ser);
|
||||
assert_eq!(v.as_ref(), Err(&error));
|
||||
assert_eq!(ser.next_token(), None);
|
||||
}
|
||||
|
||||
pub fn assert_de_tokens<T>(value: &T, tokens: Vec<Token<'static>>)
|
||||
@ -47,4 +48,7 @@ pub fn assert_de_tokens_error<T>(tokens: Vec<Token<'static>>, error: Error)
|
||||
let mut de = Deserializer::new(tokens.into_iter());
|
||||
let v: Result<T, Error> = Deserialize::deserialize(&mut de);
|
||||
assert_eq!(v, Err(error));
|
||||
// There may be one token left if a peek caused the error
|
||||
de.next_token();
|
||||
assert_eq!(de.next_token(), None);
|
||||
}
|
||||
|
@ -342,9 +342,6 @@ fn test_ignore_unknown() {
|
||||
|
||||
Token::StructSep,
|
||||
Token::Str("whoops"),
|
||||
Token::I32(2),
|
||||
|
||||
Token::StructEnd,
|
||||
],
|
||||
Error::UnknownFieldError("whoops".to_owned())
|
||||
);
|
||||
|
@ -786,8 +786,6 @@ declare_error_tests! {
|
||||
Token::SeqSep, Token::I32(1),
|
||||
Token::SeqSep, Token::I32(2),
|
||||
Token::SeqSep, Token::I32(3),
|
||||
Token::SeqSep, Token::I32(4),
|
||||
Token::SeqEnd,
|
||||
],
|
||||
Error::UnexpectedToken(Token::SeqSep),
|
||||
}
|
||||
@ -800,8 +798,6 @@ declare_error_tests! {
|
||||
|
||||
Token::MapSep,
|
||||
Token::Str("a"),
|
||||
Token::I32(3),
|
||||
Token::MapEnd,
|
||||
],
|
||||
Error::DuplicateFieldError("a"),
|
||||
}
|
||||
@ -814,8 +810,6 @@ declare_error_tests! {
|
||||
|
||||
Token::EnumMapSep,
|
||||
Token::Str("a"),
|
||||
Token::I32(3),
|
||||
Token::EnumMapEnd,
|
||||
],
|
||||
Error::DuplicateFieldError("a"),
|
||||
}
|
||||
|
@ -362,7 +362,7 @@ fn test_cannot_serialize_paths() {
|
||||
};
|
||||
assert_ser_tokens_error(
|
||||
&Path::new(path),
|
||||
&[Token::Str("Hello <20>World")],
|
||||
&[],
|
||||
Error::InvalidValue("Path contains invalid UTF-8 characters".to_owned()));
|
||||
|
||||
let mut path_buf = PathBuf::new();
|
||||
@ -370,6 +370,6 @@ fn test_cannot_serialize_paths() {
|
||||
|
||||
assert_ser_tokens_error(
|
||||
&path_buf,
|
||||
&[Token::Str("Hello <20>World")],
|
||||
&[],
|
||||
Error::InvalidValue("Path contains invalid UTF-8 characters".to_owned()));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user