Skip to content

Commit

Permalink
Add test of visitor error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Jan 25, 2022
1 parent 8932c85 commit 82c3eb7
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions test_suite/tests/test_de_error.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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>;
Expand Down Expand Up @@ -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]
Expand All @@ -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]
Expand Down

0 comments on commit 82c3eb7

Please sign in to comment.