mirror of
https://gitee.com/openharmony/third_party_rust_serde
synced 2024-11-23 06:50:23 +00:00
Add test of visitor error messages
This commit is contained in:
parent
8932c852a5
commit
82c3eb7ba4
@ -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]
|
||||
|
Loading…
Reference in New Issue
Block a user