Add test of visitor error messages

This commit is contained in:
David Tolnay 2022-01-25 11:24:53 -08:00
parent 8932c852a5
commit 82c3eb7ba4
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82

View File

@ -1,6 +1,7 @@
#![allow(clippy::empty_enum, clippy::unreadable_literal)]
#![cfg_attr(feature = "unstable", feature(never_type))]
use serde::de::IntoDeserializer;
use serde::Deserialize;
use serde_test::{assert_de_tokens_error, Token};
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
@ -185,6 +186,16 @@ fn test_i64() {
);
}
#[test]
fn test_i128() {
let deserializer = <i128 as IntoDeserializer>::into_deserializer(1);
let error = <&str>::deserialize(deserializer).unwrap_err();
assert_eq!(
error.to_string(),
"invalid type: i128, expected a borrowed string",
);
}
#[test]
fn test_u8() {
let test = assert_de_tokens_error::<u8>;
@ -326,6 +337,13 @@ fn test_u64() {
&[Token::I64(-1)],
"invalid value: integer `-1`, expected u64",
);
let deserializer = <u64 as IntoDeserializer>::into_deserializer(1);
let error = <&str>::deserialize(deserializer).unwrap_err();
assert_eq!(
error.to_string(),
"invalid type: integer `1`, expected a borrowed string",
);
}
#[test]
@ -349,6 +367,13 @@ fn test_u128() {
&[Token::I64(-1)],
"invalid value: integer `-1`, expected u128",
);
let deserializer = <u128 as IntoDeserializer>::into_deserializer(1);
let error = <&str>::deserialize(deserializer).unwrap_err();
assert_eq!(
error.to_string(),
"invalid type: u128, expected a borrowed string",
);
}
#[test]