serde/test_suite/tests/test_de.rs
David Tolnay 28a092261b
Work around test suite dead code warnings in nightly-2024-07-07
warning: struct `Cows` is never constructed
       --> test_suite/tests/test_borrow.rs:165:12
        |
    165 |     struct Cows<'a, 'b> {
        |            ^^^^

    warning: struct `Wrap` is never constructed
       --> test_suite/tests/test_borrow.rs:181:12
        |
    181 |     struct Wrap<'a, 'b> {
        |            ^^^^

    warning: struct `StructSkipDefaultGeneric` is never constructed
      --> test_suite/tests/test_de.rs:96:8
       |
    96 | struct StructSkipDefaultGeneric<T> {
       |        ^^^^^^^^^^^^^^^^^^^^^^^^

    warning: struct `NonAsciiIdents` is never constructed
       --> test_suite/tests/test_gen.rs:290:12
        |
    290 |     struct NonAsciiIdents {
        |            ^^^^^^^^^^^^^^
        |
    note: the lint level is defined here
       --> test_suite/tests/test_gen.rs:5:9
        |
    5   | #![deny(warnings)]
        |         ^^^^^^^^
        = note: `#[warn(dead_code)]` implied by `#[warn(warnings)]`

    warning: struct `EmptyBraced` is never constructed
       --> test_suite/tests/test_gen.rs:295:12
        |
    295 |     struct EmptyBraced {}
        |            ^^^^^^^^^^^

    warning: struct `EmptyBracedDenyUnknown` is never constructed
       --> test_suite/tests/test_gen.rs:299:12
        |
    299 |     struct EmptyBracedDenyUnknown {}
        |            ^^^^^^^^^^^^^^^^^^^^^^

    warning: struct `BracedSkipAll` is never constructed
       --> test_suite/tests/test_gen.rs:302:12
        |
    302 |     struct BracedSkipAll {
        |            ^^^^^^^^^^^^^

    warning: struct `BracedSkipAllDenyUnknown` is never constructed
       --> test_suite/tests/test_gen.rs:309:12
        |
    309 |     struct BracedSkipAllDenyUnknown {
        |            ^^^^^^^^^^^^^^^^^^^^^^^^

    warning: struct `EmptyTuple` is never constructed
       --> test_suite/tests/test_gen.rs:315:12
        |
    315 |     struct EmptyTuple();
        |            ^^^^^^^^^^

    warning: struct `EmptyTupleDenyUnknown` is never constructed
       --> test_suite/tests/test_gen.rs:319:12
        |
    319 |     struct EmptyTupleDenyUnknown();
        |            ^^^^^^^^^^^^^^^^^^^^^

    warning: struct `TupleSkipAll` is never constructed
       --> test_suite/tests/test_gen.rs:322:12
        |
    322 |     struct TupleSkipAll(#[serde(skip_deserializing)] u8);
        |            ^^^^^^^^^^^^

    warning: struct `TupleSkipAllDenyUnknown` is never constructed
       --> test_suite/tests/test_gen.rs:326:12
        |
    326 |     struct TupleSkipAllDenyUnknown(#[serde(skip_deserializing)] u8);
        |            ^^^^^^^^^^^^^^^^^^^^^^^

    warning: enum `EmptyEnum` is never used
       --> test_suite/tests/test_gen.rs:329:10
        |
    329 |     enum EmptyEnum {}
        |          ^^^^^^^^^

    warning: enum `EmptyEnumDenyUnknown` is never used
       --> test_suite/tests/test_gen.rs:333:10
        |
    333 |     enum EmptyEnumDenyUnknown {}
        |          ^^^^^^^^^^^^^^^^^^^^

    warning: enum `EnumSkipAll` is never used
       --> test_suite/tests/test_gen.rs:336:10
        |
    336 |     enum EnumSkipAll {
        |          ^^^^^^^^^^^

    warning: enum `EmptyVariants` is never used
       --> test_suite/tests/test_gen.rs:343:10
        |
    343 |     enum EmptyVariants {
        |          ^^^^^^^^^^^^^

    warning: enum `EmptyVariantsDenyUnknown` is never used
       --> test_suite/tests/test_gen.rs:355:10
        |
    355 |     enum EmptyVariantsDenyUnknown {
        |          ^^^^^^^^^^^^^^^^^^^^^^^^

    warning: struct `UnitDenyUnknown` is never constructed
       --> test_suite/tests/test_gen.rs:367:12
        |
    367 |     struct UnitDenyUnknown;
        |            ^^^^^^^^^^^^^^^

    warning: struct `EmptyArray` is never constructed
       --> test_suite/tests/test_gen.rs:370:12
        |
    370 |     struct EmptyArray {
        |            ^^^^^^^^^^

    warning: enum `Or` is never used
       --> test_suite/tests/test_gen.rs:374:10
        |
    374 |     enum Or<A, B> {
        |          ^^

    warning: enum `OrDef` is never used
       --> test_suite/tests/test_gen.rs:381:10
        |
    381 |     enum OrDef<A, B> {
        |          ^^^^^

    warning: struct `Str` is never constructed
       --> test_suite/tests/test_gen.rs:386:12
        |
    386 |     struct Str<'a>(&'a str);
        |            ^^^

    warning: struct `StrDef` is never constructed
       --> test_suite/tests/test_gen.rs:390:12
        |
    390 |     struct StrDef<'a>(&'a str);
        |            ^^^^^^

    warning: struct `Remote` is never constructed
       --> test_suite/tests/test_gen.rs:393:12
        |
    393 |     struct Remote<'a> {
        |            ^^^^^^

    warning: enum `BorrowVariant` is never used
       --> test_suite/tests/test_gen.rs:401:10
        |
    401 |     enum BorrowVariant<'a> {
        |          ^^^^^^^^^^^^^

    warning: struct `RemoteVisibility` is never constructed
       --> test_suite/tests/test_gen.rs:418:12
        |
    418 |     struct RemoteVisibility {
        |            ^^^^^^^^^^^^^^^^

    warning: struct `FlattenDenyUnknown` is never constructed
       --> test_suite/tests/test_gen.rs:551:12
        |
    551 |     struct FlattenDenyUnknown<T> {
        |            ^^^^^^^^^^^^^^^^^^

    warning: struct `StaticStrStruct` is never constructed
       --> test_suite/tests/test_gen.rs:557:12
        |
    557 |     struct StaticStrStruct<'a> {
        |            ^^^^^^^^^^^^^^^

    warning: struct `StaticStrTupleStruct` is never constructed
       --> test_suite/tests/test_gen.rs:563:12
        |
    563 |     struct StaticStrTupleStruct<'a>(&'a str, &'static str);
        |            ^^^^^^^^^^^^^^^^^^^^

    warning: struct `StaticStrNewtypeStruct` is never constructed
       --> test_suite/tests/test_gen.rs:566:12
        |
    566 |     struct StaticStrNewtypeStruct(&'static str);
        |            ^^^^^^^^^^^^^^^^^^^^^^

    warning: enum `StaticStrEnum` is never used
       --> test_suite/tests/test_gen.rs:569:10
        |
    569 |     enum StaticStrEnum<'a> {
        |          ^^^^^^^^^^^^^

    warning: enum `AdjacentlyTaggedVoid` is never used
       --> test_suite/tests/test_gen.rs:652:10
        |
    652 |     enum AdjacentlyTaggedVoid {}
        |          ^^^^^^^^^^^^^^^^^^^^

    warning: struct `ImplicitlyBorrowedOption` is never constructed
       --> test_suite/tests/test_gen.rs:665:12
        |
    665 |     struct ImplicitlyBorrowedOption<'a> {
        |            ^^^^^^^^^^^^^^^^^^^^^^^^

    warning: enum `UntaggedNewtypeVariantWith` is never used
       --> test_suite/tests/test_gen.rs:672:10
        |
    672 |     enum UntaggedNewtypeVariantWith {
        |          ^^^^^^^^^^^^^^^^^^^^^^^^^^

    warning: struct `TransparentWith` is never constructed
       --> test_suite/tests/test_gen.rs:682:12
        |
    682 |     struct TransparentWith {
        |            ^^^^^^^^^^^^^^^

    warning: struct `FlattenSkipSerializing` is never constructed
       --> test_suite/tests/test_gen.rs:712:12
        |
    712 |     struct FlattenSkipSerializing<T> {
        |            ^^^^^^^^^^^^^^^^^^^^^^

    warning: struct `FlattenSkipSerializingIf` is never constructed
       --> test_suite/tests/test_gen.rs:719:12
        |
    719 |     struct FlattenSkipSerializingIf<T> {
        |            ^^^^^^^^^^^^^^^^^^^^^^^^

    warning: struct `FlattenSkipDeserializing` is never constructed
       --> test_suite/tests/test_gen.rs:725:12
        |
    725 |     struct FlattenSkipDeserializing<T> {
        |            ^^^^^^^^^^^^^^^^^^^^^^^^

    warning: enum `Message` is never used
       --> test_suite/tests/test_gen.rs:732:10
        |
    732 |     enum Message {
        |          ^^^^^^^

    warning: struct `MacroRules` is never constructed
       --> test_suite/tests/test_gen.rs:751:20
        |
    751 |             struct MacroRules<'a> {
        |                    ^^^^^^^^^^
    ...
    758 |     deriving!(&'a str);
        |     ------------------ in this macro invocation
        |
        = note: this warning originates in the macro `deriving` (in Nightly builds, run with -Z macro-backtrace for more info)

    warning: struct `BorrowLifetimeInsideMacro` is never constructed
       --> test_suite/tests/test_gen.rs:767:12
        |
    767 |     struct BorrowLifetimeInsideMacro<'a> {
        |            ^^^^^^^^^^^^^^^^^^^^^^^^^

    warning: struct `GenericUnitStruct` is never constructed
       --> test_suite/tests/test_gen.rs:782:12
        |
    782 |     struct GenericUnitStruct<const N: usize>;
        |            ^^^^^^^^^^^^^^^^^

    warning: enum `InternallyTagged` is never used
       --> test_suite/tests/test_gen.rs:869:6
        |
    869 | enum InternallyTagged {
        |      ^^^^^^^^^^^^^^^^

    warning: function `deserialize_generic` is never used
       --> test_suite/tests/test_gen.rs:880:4
        |
    880 | fn deserialize_generic<'de, T, D>(deserializer: D) -> StdResult<T, D::Error>
        |    ^^^^^^^^^^^^^^^^^^^

    warning: struct `Restricted` is never constructed
       --> test_suite/tests/test_gen.rs:643:20
        |
    643 |             struct Restricted {
        |                    ^^^^^^^^^^

    warning: struct `Test` is never constructed
      --> test_suite/tests/test_remote.rs:95:8
       |
    95 | struct Test {
       |        ^^^^

    warning: struct `UnitDef` is never constructed
       --> test_suite/tests/test_remote.rs:135:8
        |
    135 | struct UnitDef;
        |        ^^^^^^^

    warning: struct `PrimitivePubDef` is never constructed
       --> test_suite/tests/test_remote.rs:143:8
        |
    143 | struct PrimitivePubDef(u8);
        |        ^^^^^^^^^^^^^^^

    warning: struct `NewtypePubDef` is never constructed
       --> test_suite/tests/test_remote.rs:151:8
        |
    151 | struct NewtypePubDef(#[serde(with = "UnitDef")] remote::Unit);
        |        ^^^^^^^^^^^^^

    warning: struct `TuplePubDef` is never constructed
       --> test_suite/tests/test_remote.rs:162:8
        |
    162 | struct TuplePubDef(u8, #[serde(with = "UnitDef")] remote::Unit);
        |        ^^^^^^^^^^^

    warning: struct `StructPubDef` is never constructed
       --> test_suite/tests/test_remote.rs:177:8
        |
    177 | struct StructPubDef {
        |        ^^^^^^^^^^^^

    warning: struct `StructConcrete` is never constructed
       --> test_suite/tests/test_remote.rs:193:8
        |
    193 | struct StructConcrete {
        |        ^^^^^^^^^^^^^^

    warning: enum `EnumConcrete` is never used
       --> test_suite/tests/test_remote.rs:199:6
        |
    199 | enum EnumConcrete {
        |      ^^^^^^^^^^^^

    warning: enum `ErrorKind` is never used
       --> test_suite/tests/test_remote.rs:204:6
        |
    204 | enum ErrorKind {
        |      ^^^^^^^^^

    warning: enum `ErrorKindDef` is never used
       --> test_suite/tests/test_remote.rs:214:6
        |
    214 | enum ErrorKindDef {
        |      ^^^^^^^^^^^^

    warning: struct `PrimitivePub` is never constructed
      --> test_suite/tests/test_remote.rs:10:16
       |
    10 |     pub struct PrimitivePub(pub u8);
       |                ^^^^^^^^^^^^

    warning: struct `NewtypePub` is never constructed
      --> test_suite/tests/test_remote.rs:14:16
       |
    14 |     pub struct NewtypePub(pub Unit);
       |                ^^^^^^^^^^

    warning: struct `TuplePub` is never constructed
      --> test_suite/tests/test_remote.rs:18:16
       |
    18 |     pub struct TuplePub(pub u8, pub Unit);
       |                ^^^^^^^^

    warning: struct `StructPub` is never constructed
      --> test_suite/tests/test_remote.rs:25:16
       |
    25 |     pub struct StructPub {
       |                ^^^^^^^^^

    warning: enum `EnumGeneric` is never used
      --> test_suite/tests/test_remote.rs:89:14
       |
    89 |     pub enum EnumGeneric<T> {
       |              ^^^^^^^^^^^

    warning: struct `Tuple` is never constructed
      --> test_suite/tests/test_self.rs:44:12
       |
    44 |     struct Tuple(
       |            ^^^^^

    warning: associated items `ASSOC` and `assoc` are never used
      --> test_suite/tests/test_self.rs:52:15
       |
    51 |     impl Tuple {
       |     ---------- associated items in this implementation
    52 |         const ASSOC: usize = 1;
       |               ^^^^^
    53 |         const fn assoc() -> usize {
       |                  ^^^^^

    warning: enum `Enum` is never used
      --> test_suite/tests/test_self.rs:63:10
       |
    63 |     enum Enum {
       |          ^^^^

    warning: associated items `ASSOC` and `assoc` are never used
      --> test_suite/tests/test_self.rs:79:15
       |
    78 |     impl Enum {
       |     --------- associated items in this implementation
    79 |         const ASSOC: usize = 1;
       |               ^^^^^
    80 |         const fn assoc() -> usize {
       |                  ^^^^^

    warning: struct `Unit` is never constructed
      --> test_suite/no_std/src/main.rs:26:8
       |
    26 | struct Unit;
       |        ^^^^

    warning: struct `Newtype` is never constructed
      --> test_suite/no_std/src/main.rs:29:8
       |
    29 | struct Newtype(u8);
       |        ^^^^^^^

    warning: struct `Tuple` is never constructed
      --> test_suite/no_std/src/main.rs:32:8
       |
    32 | struct Tuple(u8, u8);
       |        ^^^^^

    warning: struct `Struct` is never constructed
      --> test_suite/no_std/src/main.rs:35:8
       |
    35 | struct Struct {
       |        ^^^^^^

    warning: enum `Enum` is never used
      --> test_suite/no_std/src/main.rs:40:6
       |
    40 | enum Enum {
       |      ^^^^
2024-07-06 19:26:29 -07:00

2389 lines
56 KiB
Rust

#![allow(
clippy::cast_lossless,
clippy::decimal_literal_representation,
clippy::derive_partial_eq_without_eq,
clippy::empty_enum,
clippy::manual_assert,
clippy::needless_pass_by_value,
clippy::uninlined_format_args,
clippy::unreadable_literal
)]
#![cfg_attr(feature = "unstable", feature(never_type))]
use fnv::FnvHasher;
use serde::de::value::{F32Deserializer, F64Deserializer};
use serde::de::{Deserialize, DeserializeOwned, Deserializer, IntoDeserializer};
use serde_derive::Deserialize;
use serde_test::{assert_de_tokens, Configure, Token};
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
use std::default::Default;
use std::ffi::{CStr, CString, OsString};
use std::fmt::Debug;
use std::iter;
use std::net;
use std::num::{
NonZeroI128, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI8, NonZeroIsize, NonZeroU128,
NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize, Saturating, Wrapping,
};
use std::ops::Bound;
use std::path::{Path, PathBuf};
use std::rc::{Rc, Weak as RcWeak};
use std::sync::atomic::{
AtomicBool, AtomicI16, AtomicI32, AtomicI8, AtomicIsize, AtomicU16, AtomicU32, AtomicU8,
AtomicUsize, Ordering,
};
#[cfg(target_arch = "x86_64")]
use std::sync::atomic::{AtomicI64, AtomicU64};
use std::sync::{Arc, Weak as ArcWeak};
use std::time::{Duration, UNIX_EPOCH};
#[macro_use]
mod macros;
//////////////////////////////////////////////////////////////////////////
#[derive(Copy, Clone, PartialEq, Debug, Deserialize)]
struct UnitStruct;
#[derive(Copy, Clone, PartialEq, Debug, Deserialize)]
struct GenericUnitStruct<const N: u8>;
#[derive(PartialEq, Debug, Deserialize)]
struct NewtypeStruct(i32);
#[derive(PartialEq, Debug, Deserialize)]
struct TupleStruct(i32, i32, i32);
#[derive(PartialEq, Debug, Deserialize)]
struct Struct {
a: i32,
b: i32,
#[serde(skip_deserializing)]
c: i32,
}
#[derive(PartialEq, Debug, Deserialize)]
#[serde(default)]
struct StructDefault<T> {
a: i32,
b: T,
}
impl Default for StructDefault<String> {
fn default() -> Self {
StructDefault {
a: 100,
b: "default".to_string(),
}
}
}
#[derive(PartialEq, Debug, Deserialize)]
struct StructSkipAll {
#[serde(skip_deserializing)]
a: i32,
}
#[derive(PartialEq, Debug, Deserialize)]
#[serde(default)]
struct StructSkipDefault {
#[serde(skip_deserializing)]
a: i32,
}
#[derive(PartialEq, Debug, Deserialize)]
#[serde(default)]
pub struct StructSkipDefaultGeneric<T> {
#[serde(skip_deserializing)]
t: T,
}
impl Default for StructSkipDefault {
fn default() -> Self {
StructSkipDefault { a: 16 }
}
}
#[derive(PartialEq, Debug, Deserialize)]
#[serde(deny_unknown_fields)]
struct StructSkipAllDenyUnknown {
#[serde(skip_deserializing)]
a: i32,
}
#[derive(Default, PartialEq, Debug)]
struct NotDeserializable;
#[derive(PartialEq, Debug, Deserialize)]
enum Enum {
#[allow(dead_code)]
#[serde(skip_deserializing)]
Skipped,
Unit,
Simple(i32),
Seq(i32, i32, i32),
Map {
a: i32,
b: i32,
c: i32,
},
SimpleWithSkipped(#[serde(skip_deserializing)] NotDeserializable),
}
#[derive(PartialEq, Debug, Deserialize)]
enum EnumOther {
Unit,
#[serde(other)]
Other,
}
#[derive(PartialEq, Debug)]
struct IgnoredAny;
impl<'de> Deserialize<'de> for IgnoredAny {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
serde::de::IgnoredAny::deserialize(deserializer)?;
Ok(IgnoredAny)
}
}
//////////////////////////////////////////////////////////////////////////
#[track_caller]
fn test<'de, T>(value: T, tokens: &'de [Token])
where
T: Deserialize<'de> + PartialEq + Debug,
{
// Test ser/de roundtripping
assert_de_tokens(&value, tokens);
// Test that the tokens are ignorable
assert_de_tokens_ignore(tokens);
}
#[derive(Debug)]
struct SkipPartialEq<T>(T);
impl<'de, T> Deserialize<'de> for SkipPartialEq<T>
where
T: Deserialize<'de>,
{
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
T::deserialize(deserializer).map(SkipPartialEq)
}
}
impl<T> PartialEq for SkipPartialEq<T> {
fn eq(&self, _other: &Self) -> bool {
true
}
}
#[track_caller]
fn assert_de_tokens_ignore(ignorable_tokens: &[Token]) {
#[derive(PartialEq, Debug, Deserialize)]
struct IgnoreBase {
a: i32,
}
// Embed the tokens to be ignored in the normal token
// stream for an IgnoreBase type
let concated_tokens: Vec<Token> = vec![
Token::Map { len: Some(2) },
Token::Str("a"),
Token::I32(1),
Token::Str("ignored"),
]
.into_iter()
.chain(ignorable_tokens.iter().copied())
.chain(iter::once(Token::MapEnd))
.collect();
let expected = IgnoreBase { a: 1 };
assert_de_tokens(&expected, &concated_tokens);
}
//////////////////////////////////////////////////////////////////////////
#[test]
fn test_bool() {
test(true, &[Token::Bool(true)]);
test(false, &[Token::Bool(false)]);
}
#[test]
fn test_i8() {
let test = test::<i8>;
// from signed
test(-128, &[Token::I8(-128)]);
test(-128, &[Token::I16(-128)]);
test(-128, &[Token::I32(-128)]);
test(-128, &[Token::I64(-128)]);
test(127, &[Token::I8(127)]);
test(127, &[Token::I16(127)]);
test(127, &[Token::I32(127)]);
test(127, &[Token::I64(127)]);
// from unsigned
test(0, &[Token::U8(0)]);
test(0, &[Token::U16(0)]);
test(0, &[Token::U32(0)]);
test(0, &[Token::U64(0)]);
test(127, &[Token::U8(127)]);
test(127, &[Token::U16(127)]);
test(127, &[Token::U32(127)]);
test(127, &[Token::U64(127)]);
}
#[test]
fn test_i16() {
let test = test::<i16>;
// from signed
test(-128, &[Token::I8(-128)]);
test(-32768, &[Token::I16(-32768)]);
test(-32768, &[Token::I32(-32768)]);
test(-32768, &[Token::I64(-32768)]);
test(127, &[Token::I8(127)]);
test(32767, &[Token::I16(32767)]);
test(32767, &[Token::I32(32767)]);
test(32767, &[Token::I64(32767)]);
// from unsigned
test(0, &[Token::U8(0)]);
test(0, &[Token::U16(0)]);
test(0, &[Token::U32(0)]);
test(0, &[Token::U64(0)]);
test(255, &[Token::U8(255)]);
test(32767, &[Token::U16(32767)]);
test(32767, &[Token::U32(32767)]);
test(32767, &[Token::U64(32767)]);
}
#[test]
fn test_i32() {
let test = test::<i32>;
// from signed
test(-128, &[Token::I8(-128)]);
test(-32768, &[Token::I16(-32768)]);
test(-2147483648, &[Token::I32(-2147483648)]);
test(-2147483648, &[Token::I64(-2147483648)]);
test(127, &[Token::I8(127)]);
test(32767, &[Token::I16(32767)]);
test(2147483647, &[Token::I32(2147483647)]);
test(2147483647, &[Token::I64(2147483647)]);
// from unsigned
test(0, &[Token::U8(0)]);
test(0, &[Token::U16(0)]);
test(0, &[Token::U32(0)]);
test(0, &[Token::U64(0)]);
test(255, &[Token::U8(255)]);
test(65535, &[Token::U16(65535)]);
test(2147483647, &[Token::U32(2147483647)]);
test(2147483647, &[Token::U64(2147483647)]);
}
#[test]
fn test_i64() {
let test = test::<i64>;
// from signed
test(-128, &[Token::I8(-128)]);
test(-32768, &[Token::I16(-32768)]);
test(-2147483648, &[Token::I32(-2147483648)]);
test(-9223372036854775808, &[Token::I64(-9223372036854775808)]);
test(127, &[Token::I8(127)]);
test(32767, &[Token::I16(32767)]);
test(2147483647, &[Token::I32(2147483647)]);
test(9223372036854775807, &[Token::I64(9223372036854775807)]);
// from unsigned
test(0, &[Token::U8(0)]);
test(0, &[Token::U16(0)]);
test(0, &[Token::U32(0)]);
test(0, &[Token::U64(0)]);
test(255, &[Token::U8(255)]);
test(65535, &[Token::U16(65535)]);
test(4294967295, &[Token::U32(4294967295)]);
test(9223372036854775807, &[Token::U64(9223372036854775807)]);
}
#[test]
fn test_i128() {
let test = test::<i128>;
// from signed
test(-128, &[Token::I8(-128)]);
test(-32768, &[Token::I16(-32768)]);
test(-2147483648, &[Token::I32(-2147483648)]);
test(-9223372036854775808, &[Token::I64(-9223372036854775808)]);
test(127, &[Token::I8(127)]);
test(32767, &[Token::I16(32767)]);
test(2147483647, &[Token::I32(2147483647)]);
test(9223372036854775807, &[Token::I64(9223372036854775807)]);
// from unsigned
test(0, &[Token::U8(0)]);
test(0, &[Token::U16(0)]);
test(0, &[Token::U32(0)]);
test(0, &[Token::U64(0)]);
test(255, &[Token::U8(255)]);
test(65535, &[Token::U16(65535)]);
test(4294967295, &[Token::U32(4294967295)]);
test(18446744073709551615, &[Token::U64(18446744073709551615)]);
}
#[test]
fn test_isize() {
let test = test::<isize>;
// from signed
test(-10, &[Token::I8(-10)]);
test(-10, &[Token::I16(-10)]);
test(-10, &[Token::I32(-10)]);
test(-10, &[Token::I64(-10)]);
test(10, &[Token::I8(10)]);
test(10, &[Token::I16(10)]);
test(10, &[Token::I32(10)]);
test(10, &[Token::I64(10)]);
// from unsigned
test(0, &[Token::U8(0)]);
test(0, &[Token::U16(0)]);
test(0, &[Token::U32(0)]);
test(0, &[Token::U64(0)]);
test(10, &[Token::U8(10)]);
test(10, &[Token::U16(10)]);
test(10, &[Token::U32(10)]);
test(10, &[Token::U64(10)]);
}
#[test]
fn test_u8() {
let test = test::<u8>;
// from signed
test(0, &[Token::I8(0)]);
test(0, &[Token::I16(0)]);
test(0, &[Token::I32(0)]);
test(0, &[Token::I64(0)]);
test(127, &[Token::I8(127)]);
test(255, &[Token::I16(255)]);
test(255, &[Token::I32(255)]);
test(255, &[Token::I64(255)]);
// from unsigned
test(0, &[Token::U8(0)]);
test(0, &[Token::U16(0)]);
test(0, &[Token::U32(0)]);
test(0, &[Token::U64(0)]);
test(255, &[Token::U8(255)]);
test(255, &[Token::U16(255)]);
test(255, &[Token::U32(255)]);
test(255, &[Token::U64(255)]);
}
#[test]
fn test_u16() {
let test = test::<u16>;
// from signed
test(0, &[Token::I8(0)]);
test(0, &[Token::I16(0)]);
test(0, &[Token::I32(0)]);
test(0, &[Token::I64(0)]);
test(127, &[Token::I8(127)]);
test(32767, &[Token::I16(32767)]);
test(65535, &[Token::I32(65535)]);
test(65535, &[Token::I64(65535)]);
// from unsigned
test(0, &[Token::U8(0)]);
test(0, &[Token::U16(0)]);
test(0, &[Token::U32(0)]);
test(0, &[Token::U64(0)]);
test(255, &[Token::U8(255)]);
test(65535, &[Token::U16(65535)]);
test(65535, &[Token::U32(65535)]);
test(65535, &[Token::U64(65535)]);
}
#[test]
fn test_u32() {
let test = test::<u32>;
// from signed
test(0, &[Token::I8(0)]);
test(0, &[Token::I16(0)]);
test(0, &[Token::I32(0)]);
test(0, &[Token::I64(0)]);
test(127, &[Token::I8(127)]);
test(32767, &[Token::I16(32767)]);
test(2147483647, &[Token::I32(2147483647)]);
test(4294967295, &[Token::I64(4294967295)]);
// from unsigned
test(0, &[Token::U8(0)]);
test(0, &[Token::U16(0)]);
test(0, &[Token::U32(0)]);
test(0, &[Token::U64(0)]);
test(255, &[Token::U8(255)]);
test(65535, &[Token::U16(65535)]);
test(4294967295, &[Token::U32(4294967295)]);
test(4294967295, &[Token::U64(4294967295)]);
}
#[test]
fn test_u64() {
let test = test::<u64>;
// from signed
test(0, &[Token::I8(0)]);
test(0, &[Token::I16(0)]);
test(0, &[Token::I32(0)]);
test(0, &[Token::I64(0)]);
test(127, &[Token::I8(127)]);
test(32767, &[Token::I16(32767)]);
test(2147483647, &[Token::I32(2147483647)]);
test(9223372036854775807, &[Token::I64(9223372036854775807)]);
// from unsigned
test(0, &[Token::U8(0)]);
test(0, &[Token::U16(0)]);
test(0, &[Token::U32(0)]);
test(0, &[Token::U64(0)]);
test(255, &[Token::U8(255)]);
test(65535, &[Token::U16(65535)]);
test(4294967295, &[Token::U32(4294967295)]);
test(18446744073709551615, &[Token::U64(18446744073709551615)]);
}
#[test]
fn test_u128() {
let test = test::<u128>;
// from signed
test(0, &[Token::I8(0)]);
test(0, &[Token::I16(0)]);
test(0, &[Token::I32(0)]);
test(0, &[Token::I64(0)]);
test(127, &[Token::I8(127)]);
test(32767, &[Token::I16(32767)]);
test(2147483647, &[Token::I32(2147483647)]);
test(9223372036854775807, &[Token::I64(9223372036854775807)]);
// from unsigned
test(0, &[Token::U8(0)]);
test(0, &[Token::U16(0)]);
test(0, &[Token::U32(0)]);
test(0, &[Token::U64(0)]);
test(255, &[Token::U8(255)]);
test(65535, &[Token::U16(65535)]);
test(4294967295, &[Token::U32(4294967295)]);
test(18446744073709551615, &[Token::U64(18446744073709551615)]);
}
#[test]
fn test_usize() {
let test = test::<usize>;
// from signed
test(0, &[Token::I8(0)]);
test(0, &[Token::I16(0)]);
test(0, &[Token::I32(0)]);
test(0, &[Token::I64(0)]);
test(10, &[Token::I8(10)]);
test(10, &[Token::I16(10)]);
test(10, &[Token::I32(10)]);
test(10, &[Token::I64(10)]);
// from unsigned
test(0, &[Token::U8(0)]);
test(0, &[Token::U16(0)]);
test(0, &[Token::U32(0)]);
test(0, &[Token::U64(0)]);
test(10, &[Token::U8(10)]);
test(10, &[Token::U16(10)]);
test(10, &[Token::U32(10)]);
test(10, &[Token::U64(10)]);
}
#[test]
fn test_nonzero_i8() {
let test = |value, tokens| test(NonZeroI8::new(value).unwrap(), tokens);
// from signed
test(-128, &[Token::I8(-128)]);
test(-128, &[Token::I16(-128)]);
test(-128, &[Token::I32(-128)]);
test(-128, &[Token::I64(-128)]);
test(127, &[Token::I8(127)]);
test(127, &[Token::I16(127)]);
test(127, &[Token::I32(127)]);
test(127, &[Token::I64(127)]);
// from unsigned
test(1, &[Token::U8(1)]);
test(1, &[Token::U16(1)]);
test(1, &[Token::U32(1)]);
test(1, &[Token::U64(1)]);
test(127, &[Token::U8(127)]);
test(127, &[Token::U16(127)]);
test(127, &[Token::U32(127)]);
test(127, &[Token::U64(127)]);
}
#[test]
fn test_nonzero_i16() {
let test = |value, tokens| test(NonZeroI16::new(value).unwrap(), tokens);
// from signed
test(-128, &[Token::I8(-128)]);
test(-32768, &[Token::I16(-32768)]);
test(-32768, &[Token::I32(-32768)]);
test(-32768, &[Token::I64(-32768)]);
test(127, &[Token::I8(127)]);
test(32767, &[Token::I16(32767)]);
test(32767, &[Token::I32(32767)]);
test(32767, &[Token::I64(32767)]);
// from unsigned
test(1, &[Token::U8(1)]);
test(1, &[Token::U16(1)]);
test(1, &[Token::U32(1)]);
test(1, &[Token::U64(1)]);
test(255, &[Token::U8(255)]);
test(32767, &[Token::U16(32767)]);
test(32767, &[Token::U32(32767)]);
test(32767, &[Token::U64(32767)]);
}
#[test]
fn test_nonzero_i32() {
let test = |value, tokens| test(NonZeroI32::new(value).unwrap(), tokens);
// from signed
test(-128, &[Token::I8(-128)]);
test(-32768, &[Token::I16(-32768)]);
test(-2147483648, &[Token::I32(-2147483648)]);
test(-2147483648, &[Token::I64(-2147483648)]);
test(127, &[Token::I8(127)]);
test(32767, &[Token::I16(32767)]);
test(2147483647, &[Token::I32(2147483647)]);
test(2147483647, &[Token::I64(2147483647)]);
// from unsigned
test(1, &[Token::U8(1)]);
test(1, &[Token::U16(1)]);
test(1, &[Token::U32(1)]);
test(1, &[Token::U64(1)]);
test(255, &[Token::U8(255)]);
test(65535, &[Token::U16(65535)]);
test(2147483647, &[Token::U32(2147483647)]);
test(2147483647, &[Token::U64(2147483647)]);
}
#[test]
fn test_nonzero_i64() {
let test = |value, tokens| test(NonZeroI64::new(value).unwrap(), tokens);
// from signed
test(-128, &[Token::I8(-128)]);
test(-32768, &[Token::I16(-32768)]);
test(-2147483648, &[Token::I32(-2147483648)]);
test(-9223372036854775808, &[Token::I64(-9223372036854775808)]);
test(127, &[Token::I8(127)]);
test(32767, &[Token::I16(32767)]);
test(2147483647, &[Token::I32(2147483647)]);
test(9223372036854775807, &[Token::I64(9223372036854775807)]);
// from unsigned
test(1, &[Token::U8(1)]);
test(1, &[Token::U16(1)]);
test(1, &[Token::U32(1)]);
test(1, &[Token::U64(1)]);
test(255, &[Token::U8(255)]);
test(65535, &[Token::U16(65535)]);
test(4294967295, &[Token::U32(4294967295)]);
test(9223372036854775807, &[Token::U64(9223372036854775807)]);
}
#[test]
fn test_nonzero_i128() {
let test = |value, tokens| test(NonZeroI128::new(value).unwrap(), tokens);
// from signed
test(-128, &[Token::I8(-128)]);
test(-32768, &[Token::I16(-32768)]);
test(-2147483648, &[Token::I32(-2147483648)]);
test(-9223372036854775808, &[Token::I64(-9223372036854775808)]);
test(127, &[Token::I8(127)]);
test(32767, &[Token::I16(32767)]);
test(2147483647, &[Token::I32(2147483647)]);
test(9223372036854775807, &[Token::I64(9223372036854775807)]);
// from unsigned
test(1, &[Token::U8(1)]);
test(1, &[Token::U16(1)]);
test(1, &[Token::U32(1)]);
test(1, &[Token::U64(1)]);
test(255, &[Token::U8(255)]);
test(65535, &[Token::U16(65535)]);
test(4294967295, &[Token::U32(4294967295)]);
test(18446744073709551615, &[Token::U64(18446744073709551615)]);
}
#[test]
fn test_nonzero_isize() {
let test = |value, tokens| test(NonZeroIsize::new(value).unwrap(), tokens);
// from signed
test(-10, &[Token::I8(-10)]);
test(-10, &[Token::I16(-10)]);
test(-10, &[Token::I32(-10)]);
test(-10, &[Token::I64(-10)]);
test(10, &[Token::I8(10)]);
test(10, &[Token::I16(10)]);
test(10, &[Token::I32(10)]);
test(10, &[Token::I64(10)]);
// from unsigned
test(1, &[Token::U8(1)]);
test(1, &[Token::U16(1)]);
test(1, &[Token::U32(1)]);
test(1, &[Token::U64(1)]);
test(10, &[Token::U8(10)]);
test(10, &[Token::U16(10)]);
test(10, &[Token::U32(10)]);
test(10, &[Token::U64(10)]);
}
#[test]
fn test_nonzero_u8() {
let test = |value, tokens| test(NonZeroU8::new(value).unwrap(), tokens);
// from signed
test(1, &[Token::I8(1)]);
test(1, &[Token::I16(1)]);
test(1, &[Token::I32(1)]);
test(1, &[Token::I64(1)]);
test(127, &[Token::I8(127)]);
test(255, &[Token::I16(255)]);
test(255, &[Token::I32(255)]);
test(255, &[Token::I64(255)]);
// from unsigned
test(1, &[Token::U8(1)]);
test(1, &[Token::U16(1)]);
test(1, &[Token::U32(1)]);
test(1, &[Token::U64(1)]);
test(255, &[Token::U8(255)]);
test(255, &[Token::U16(255)]);
test(255, &[Token::U32(255)]);
test(255, &[Token::U64(255)]);
}
#[test]
fn test_nonzero_u16() {
let test = |value, tokens| test(NonZeroU16::new(value).unwrap(), tokens);
// from signed
test(1, &[Token::I8(1)]);
test(1, &[Token::I16(1)]);
test(1, &[Token::I32(1)]);
test(1, &[Token::I64(1)]);
test(127, &[Token::I8(127)]);
test(32767, &[Token::I16(32767)]);
test(65535, &[Token::I32(65535)]);
test(65535, &[Token::I64(65535)]);
// from unsigned
test(1, &[Token::U8(1)]);
test(1, &[Token::U16(1)]);
test(1, &[Token::U32(1)]);
test(1, &[Token::U64(1)]);
test(255, &[Token::U8(255)]);
test(65535, &[Token::U16(65535)]);
test(65535, &[Token::U32(65535)]);
test(65535, &[Token::U64(65535)]);
}
#[test]
fn test_nonzero_u32() {
let test = |value, tokens| test(NonZeroU32::new(value).unwrap(), tokens);
// from signed
test(1, &[Token::I8(1)]);
test(1, &[Token::I16(1)]);
test(1, &[Token::I32(1)]);
test(1, &[Token::I64(1)]);
test(127, &[Token::I8(127)]);
test(32767, &[Token::I16(32767)]);
test(2147483647, &[Token::I32(2147483647)]);
test(4294967295, &[Token::I64(4294967295)]);
// from unsigned
test(1, &[Token::U8(1)]);
test(1, &[Token::U16(1)]);
test(1, &[Token::U32(1)]);
test(1, &[Token::U64(1)]);
test(255, &[Token::U8(255)]);
test(65535, &[Token::U16(65535)]);
test(4294967295, &[Token::U32(4294967295)]);
test(4294967295, &[Token::U64(4294967295)]);
}
#[test]
fn test_nonzero_u64() {
let test = |value, tokens| test(NonZeroU64::new(value).unwrap(), tokens);
// from signed
test(1, &[Token::I8(1)]);
test(1, &[Token::I16(1)]);
test(1, &[Token::I32(1)]);
test(1, &[Token::I64(1)]);
test(127, &[Token::I8(127)]);
test(32767, &[Token::I16(32767)]);
test(2147483647, &[Token::I32(2147483647)]);
test(9223372036854775807, &[Token::I64(9223372036854775807)]);
// from unsigned
test(1, &[Token::U8(1)]);
test(1, &[Token::U16(1)]);
test(1, &[Token::U32(1)]);
test(1, &[Token::U64(1)]);
test(255, &[Token::U8(255)]);
test(65535, &[Token::U16(65535)]);
test(4294967295, &[Token::U32(4294967295)]);
test(18446744073709551615, &[Token::U64(18446744073709551615)]);
}
#[test]
fn test_nonzero_u128() {
let test = |value, tokens| test(NonZeroU128::new(value).unwrap(), tokens);
// from signed
test(1, &[Token::I8(1)]);
test(1, &[Token::I16(1)]);
test(1, &[Token::I32(1)]);
test(1, &[Token::I64(1)]);
test(127, &[Token::I8(127)]);
test(32767, &[Token::I16(32767)]);
test(2147483647, &[Token::I32(2147483647)]);
test(9223372036854775807, &[Token::I64(9223372036854775807)]);
// from unsigned
test(1, &[Token::U8(1)]);
test(1, &[Token::U16(1)]);
test(1, &[Token::U32(1)]);
test(1, &[Token::U64(1)]);
test(255, &[Token::U8(255)]);
test(65535, &[Token::U16(65535)]);
test(4294967295, &[Token::U32(4294967295)]);
test(18446744073709551615, &[Token::U64(18446744073709551615)]);
}
#[test]
fn test_nonzero_usize() {
let test = |value, tokens| test(NonZeroUsize::new(value).unwrap(), tokens);
// from signed
test(1, &[Token::I8(1)]);
test(1, &[Token::I16(1)]);
test(1, &[Token::I32(1)]);
test(1, &[Token::I64(1)]);
test(10, &[Token::I8(10)]);
test(10, &[Token::I16(10)]);
test(10, &[Token::I32(10)]);
test(10, &[Token::I64(10)]);
// from unsigned
test(1, &[Token::U8(1)]);
test(1, &[Token::U16(1)]);
test(1, &[Token::U32(1)]);
test(1, &[Token::U64(1)]);
test(10, &[Token::U8(10)]);
test(10, &[Token::U16(10)]);
test(10, &[Token::U32(10)]);
test(10, &[Token::U64(10)]);
}
#[test]
fn test_f32() {
let test = test::<f32>;
test(1.11, &[Token::F32(1.11)]);
test(1.11, &[Token::F64(1.11)]);
}
#[test]
fn test_f64() {
let test = test::<f64>;
test(1.11f32 as f64, &[Token::F32(1.11)]);
test(1.11, &[Token::F64(1.11)]);
}
#[test]
fn test_nan() {
let f32_deserializer = F32Deserializer::<serde::de::value::Error>::new;
let f64_deserializer = F64Deserializer::<serde::de::value::Error>::new;
let pos_f32_nan = f32_deserializer(f32::NAN.copysign(1.0));
let pos_f64_nan = f64_deserializer(f64::NAN.copysign(1.0));
assert!(f32::deserialize(pos_f32_nan).unwrap().is_sign_positive());
assert!(f32::deserialize(pos_f64_nan).unwrap().is_sign_positive());
assert!(f64::deserialize(pos_f32_nan).unwrap().is_sign_positive());
assert!(f64::deserialize(pos_f64_nan).unwrap().is_sign_positive());
let neg_f32_nan = f32_deserializer(f32::NAN.copysign(-1.0));
let neg_f64_nan = f64_deserializer(f64::NAN.copysign(-1.0));
assert!(f32::deserialize(neg_f32_nan).unwrap().is_sign_negative());
assert!(f32::deserialize(neg_f64_nan).unwrap().is_sign_negative());
assert!(f64::deserialize(neg_f32_nan).unwrap().is_sign_negative());
assert!(f64::deserialize(neg_f64_nan).unwrap().is_sign_negative());
}
#[test]
fn test_char() {
test('a', &[Token::Char('a')]);
test('a', &[Token::Str("a")]);
test('a', &[Token::String("a")]);
}
#[test]
fn test_string() {
test("abc".to_owned(), &[Token::Str("abc")]);
test("abc".to_owned(), &[Token::String("abc")]);
test("a".to_owned(), &[Token::Char('a')]);
}
#[test]
fn test_option() {
test(None::<i32>, &[Token::Unit]);
test(None::<i32>, &[Token::None]);
test(Some(1), &[Token::Some, Token::I32(1)]);
}
#[test]
fn test_result() {
test(
Ok::<i32, i32>(0),
&[
Token::Enum { name: "Result" },
Token::Str("Ok"),
Token::I32(0),
],
);
test(
Err::<i32, i32>(1),
&[
Token::Enum { name: "Result" },
Token::Str("Err"),
Token::I32(1),
],
);
}
#[test]
fn test_unit() {
test((), &[Token::Unit]);
}
#[test]
fn test_unit_struct() {
test(UnitStruct, &[Token::Unit]);
test(UnitStruct, &[Token::UnitStruct { name: "UnitStruct" }]);
}
#[test]
fn test_generic_unit_struct() {
test(GenericUnitStruct::<8>, &[Token::Unit]);
test(
GenericUnitStruct::<8>,
&[Token::UnitStruct {
name: "GenericUnitStruct",
}],
);
}
#[test]
fn test_newtype_struct() {
test(
NewtypeStruct(1),
&[
Token::NewtypeStruct {
name: "NewtypeStruct",
},
Token::I32(1),
],
);
}
#[test]
fn test_tuple_struct() {
test(
TupleStruct(1, 2, 3),
&[
Token::Seq { len: Some(3) },
Token::I32(1),
Token::I32(2),
Token::I32(3),
Token::SeqEnd,
],
);
test(
TupleStruct(1, 2, 3),
&[
Token::Seq { len: None },
Token::I32(1),
Token::I32(2),
Token::I32(3),
Token::SeqEnd,
],
);
test(
TupleStruct(1, 2, 3),
&[
Token::TupleStruct {
name: "TupleStruct",
len: 3,
},
Token::I32(1),
Token::I32(2),
Token::I32(3),
Token::TupleStructEnd,
],
);
test(
TupleStruct(1, 2, 3),
&[
Token::TupleStruct {
name: "TupleStruct",
len: 3,
},
Token::I32(1),
Token::I32(2),
Token::I32(3),
Token::TupleStructEnd,
],
);
}
#[test]
fn test_btreeset() {
test(
BTreeSet::<isize>::new(),
&[Token::Seq { len: Some(0) }, Token::SeqEnd],
);
test(
btreeset![btreeset![], btreeset![1], btreeset![2, 3]],
&[
Token::Seq { len: Some(3) },
Token::Seq { len: Some(0) },
Token::SeqEnd,
Token::Seq { len: Some(1) },
Token::I32(1),
Token::SeqEnd,
Token::Seq { len: Some(2) },
Token::I32(2),
Token::I32(3),
Token::SeqEnd,
Token::SeqEnd,
],
);
test(
BTreeSet::<isize>::new(),
&[
Token::TupleStruct {
name: "Anything",
len: 0,
},
Token::TupleStructEnd,
],
);
}
#[test]
fn test_hashset() {
test(
HashSet::<isize>::new(),
&[Token::Seq { len: Some(0) }, Token::SeqEnd],
);
test(
hashset![1, 2, 3],
&[
Token::Seq { len: Some(3) },
Token::I32(1),
Token::I32(2),
Token::I32(3),
Token::SeqEnd,
],
);
test(
HashSet::<isize>::new(),
&[
Token::TupleStruct {
name: "Anything",
len: 0,
},
Token::TupleStructEnd,
],
);
test(
hashset![FnvHasher @ 1, 2, 3],
&[
Token::Seq { len: Some(3) },
Token::I32(1),
Token::I32(2),
Token::I32(3),
Token::SeqEnd,
],
);
}
#[test]
fn test_vec() {
test(
Vec::<isize>::new(),
&[Token::Seq { len: Some(0) }, Token::SeqEnd],
);
test(
vec![vec![], vec![1], vec![2, 3]],
&[
Token::Seq { len: Some(3) },
Token::Seq { len: Some(0) },
Token::SeqEnd,
Token::Seq { len: Some(1) },
Token::I32(1),
Token::SeqEnd,
Token::Seq { len: Some(2) },
Token::I32(2),
Token::I32(3),
Token::SeqEnd,
Token::SeqEnd,
],
);
test(
Vec::<isize>::new(),
&[
Token::TupleStruct {
name: "Anything",
len: 0,
},
Token::TupleStructEnd,
],
);
}
#[test]
fn test_array() {
test([0; 0], &[Token::Seq { len: Some(0) }, Token::SeqEnd]);
test([0; 0], &[Token::Tuple { len: 0 }, Token::TupleEnd]);
test(
([0; 0], [1], [2, 3]),
&[
Token::Seq { len: Some(3) },
Token::Seq { len: Some(0) },
Token::SeqEnd,
Token::Seq { len: Some(1) },
Token::I32(1),
Token::SeqEnd,
Token::Seq { len: Some(2) },
Token::I32(2),
Token::I32(3),
Token::SeqEnd,
Token::SeqEnd,
],
);
test(
([0; 0], [1], [2, 3]),
&[
Token::Tuple { len: 3 },
Token::Tuple { len: 0 },
Token::TupleEnd,
Token::Tuple { len: 1 },
Token::I32(1),
Token::TupleEnd,
Token::Tuple { len: 2 },
Token::I32(2),
Token::I32(3),
Token::TupleEnd,
Token::TupleEnd,
],
);
test(
[0; 0],
&[
Token::TupleStruct {
name: "Anything",
len: 0,
},
Token::TupleStructEnd,
],
);
}
#[test]
fn test_tuple() {
test(
(1,),
&[Token::Seq { len: Some(1) }, Token::I32(1), Token::SeqEnd],
);
test(
(1, 2, 3),
&[
Token::Seq { len: Some(3) },
Token::I32(1),
Token::I32(2),
Token::I32(3),
Token::SeqEnd,
],
);
test(
(1,),
&[Token::Tuple { len: 1 }, Token::I32(1), Token::TupleEnd],
);
test(
(1, 2, 3),
&[
Token::Tuple { len: 3 },
Token::I32(1),
Token::I32(2),
Token::I32(3),
Token::TupleEnd,
],
);
}
#[test]
fn test_btreemap() {
test(
BTreeMap::<isize, isize>::new(),
&[Token::Map { len: Some(0) }, Token::MapEnd],
);
test(
btreemap![1 => 2],
&[
Token::Map { len: Some(1) },
Token::I32(1),
Token::I32(2),
Token::MapEnd,
],
);
test(
btreemap![1 => 2, 3 => 4],
&[
Token::Map { len: Some(2) },
Token::I32(1),
Token::I32(2),
Token::I32(3),
Token::I32(4),
Token::MapEnd,
],
);
test(
btreemap![1 => btreemap![], 2 => btreemap![3 => 4, 5 => 6]],
&[
Token::Map { len: Some(2) },
Token::I32(1),
Token::Map { len: Some(0) },
Token::MapEnd,
Token::I32(2),
Token::Map { len: Some(2) },
Token::I32(3),
Token::I32(4),
Token::I32(5),
Token::I32(6),
Token::MapEnd,
Token::MapEnd,
],
);
test(
BTreeMap::<isize, isize>::new(),
&[
Token::Struct {
name: "Anything",
len: 0,
},
Token::StructEnd,
],
);
}
#[test]
fn test_hashmap() {
test(
HashMap::<isize, isize>::new(),
&[Token::Map { len: Some(0) }, Token::MapEnd],
);
test(
hashmap![1 => 2],
&[
Token::Map { len: Some(1) },
Token::I32(1),
Token::I32(2),
Token::MapEnd,
],
);
test(
hashmap![1 => 2, 3 => 4],
&[
Token::Map { len: Some(2) },
Token::I32(1),
Token::I32(2),
Token::I32(3),
Token::I32(4),
Token::MapEnd,
],
);
test(
hashmap![1 => hashmap![], 2 => hashmap![3 => 4, 5 => 6]],
&[
Token::Map { len: Some(2) },
Token::I32(1),
Token::Map { len: Some(0) },
Token::MapEnd,
Token::I32(2),
Token::Map { len: Some(2) },
Token::I32(3),
Token::I32(4),
Token::I32(5),
Token::I32(6),
Token::MapEnd,
Token::MapEnd,
],
);
test(
HashMap::<isize, isize>::new(),
&[
Token::Struct {
name: "Anything",
len: 0,
},
Token::StructEnd,
],
);
test(
hashmap![FnvHasher @ 1 => 2, 3 => 4],
&[
Token::Map { len: Some(2) },
Token::I32(1),
Token::I32(2),
Token::I32(3),
Token::I32(4),
Token::MapEnd,
],
);
}
#[test]
fn test_struct() {
test(
Struct { a: 1, b: 2, c: 0 },
&[
Token::Map { len: Some(3) },
Token::Str("a"),
Token::I32(1),
Token::Str("b"),
Token::I32(2),
Token::MapEnd,
],
);
test(
Struct { a: 1, b: 2, c: 0 },
&[
Token::Map { len: Some(3) },
Token::U8(0),
Token::I32(1),
Token::U8(1),
Token::I32(2),
Token::MapEnd,
],
);
test(
Struct { a: 1, b: 2, c: 0 },
&[
Token::Map { len: Some(3) },
Token::U16(0),
Token::I32(1),
Token::U16(1),
Token::I32(2),
Token::MapEnd,
],
);
test(
Struct { a: 1, b: 2, c: 0 },
&[
Token::Map { len: Some(3) },
Token::U32(0),
Token::I32(1),
Token::U32(1),
Token::I32(2),
Token::MapEnd,
],
);
test(
Struct { a: 1, b: 2, c: 0 },
&[
Token::Map { len: Some(3) },
Token::U64(0),
Token::I32(1),
Token::U64(1),
Token::I32(2),
Token::MapEnd,
],
);
// Mixed key types
test(
Struct { a: 1, b: 2, c: 0 },
&[
Token::Map { len: Some(3) },
Token::U8(0),
Token::I32(1),
Token::U64(1),
Token::I32(2),
Token::MapEnd,
],
);
test(
Struct { a: 1, b: 2, c: 0 },
&[
Token::Map { len: Some(3) },
Token::U8(0),
Token::I32(1),
Token::Str("b"),
Token::I32(2),
Token::MapEnd,
],
);
test(
Struct { a: 1, b: 2, c: 0 },
&[
Token::Struct {
name: "Struct",
len: 2,
},
Token::Str("a"),
Token::I32(1),
Token::Str("b"),
Token::I32(2),
Token::StructEnd,
],
);
test(
Struct { a: 1, b: 2, c: 0 },
&[
Token::Seq { len: Some(3) },
Token::I32(1),
Token::I32(2),
Token::SeqEnd,
],
);
}
#[test]
fn test_struct_borrowed_keys() {
test(
Struct { a: 1, b: 2, c: 0 },
&[
Token::Map { len: Some(3) },
Token::BorrowedStr("a"),
Token::I32(1),
Token::BorrowedStr("b"),
Token::I32(2),
Token::MapEnd,
],
);
test(
Struct { a: 1, b: 2, c: 0 },
&[
Token::Struct {
name: "Struct",
len: 2,
},
Token::BorrowedStr("a"),
Token::I32(1),
Token::BorrowedStr("b"),
Token::I32(2),
Token::StructEnd,
],
);
}
#[test]
fn test_struct_owned_keys() {
test(
Struct { a: 1, b: 2, c: 0 },
&[
Token::Map { len: Some(3) },
Token::String("a"),
Token::I32(1),
Token::String("b"),
Token::I32(2),
Token::MapEnd,
],
);
test(
Struct { a: 1, b: 2, c: 0 },
&[
Token::Struct {
name: "Struct",
len: 2,
},
Token::String("a"),
Token::I32(1),
Token::String("b"),
Token::I32(2),
Token::StructEnd,
],
);
}
#[test]
fn test_struct_with_skip() {
test(
Struct { a: 1, b: 2, c: 0 },
&[
Token::Map { len: Some(3) },
Token::Str("a"),
Token::I32(1),
Token::Str("b"),
Token::I32(2),
Token::Str("c"),
Token::I32(3),
Token::Str("d"),
Token::I32(4),
Token::MapEnd,
],
);
test(
Struct { a: 1, b: 2, c: 0 },
&[
Token::Map { len: Some(3) },
Token::U8(0),
Token::I32(1),
Token::U16(1),
Token::I32(2),
Token::U32(2),
Token::I32(3),
Token::U64(3),
Token::I32(4),
Token::MapEnd,
],
);
test(
Struct { a: 1, b: 2, c: 0 },
&[
Token::Struct {
name: "Struct",
len: 2,
},
Token::Str("a"),
Token::I32(1),
Token::Str("b"),
Token::I32(2),
Token::Str("c"),
Token::I32(3),
Token::Str("d"),
Token::I32(4),
Token::StructEnd,
],
);
}
#[test]
fn test_struct_skip_all() {
test(
StructSkipAll { a: 0 },
&[
Token::Struct {
name: "StructSkipAll",
len: 0,
},
Token::StructEnd,
],
);
test(
StructSkipAll { a: 0 },
&[
Token::Struct {
name: "StructSkipAll",
len: 0,
},
Token::Str("a"),
Token::I32(1),
Token::Str("b"),
Token::I32(2),
Token::StructEnd,
],
);
}
#[test]
fn test_struct_skip_default() {
test(
StructSkipDefault { a: 16 },
&[
Token::Struct {
name: "StructSkipDefault",
len: 0,
},
Token::StructEnd,
],
);
}
#[test]
fn test_struct_skip_all_deny_unknown() {
test(
StructSkipAllDenyUnknown { a: 0 },
&[
Token::Struct {
name: "StructSkipAllDenyUnknown",
len: 0,
},
Token::StructEnd,
],
);
}
#[test]
fn test_struct_default() {
test(
StructDefault {
a: 50,
b: "overwritten".to_string(),
},
&[
Token::Struct {
name: "StructDefault",
len: 2,
},
Token::Str("a"),
Token::I32(50),
Token::Str("b"),
Token::String("overwritten"),
Token::StructEnd,
],
);
test(
StructDefault {
a: 100,
b: "default".to_string(),
},
&[
Token::Struct {
name: "StructDefault",
len: 2,
},
Token::StructEnd,
],
);
}
#[test]
fn test_enum_unit() {
test(
Enum::Unit,
&[Token::UnitVariant {
name: "Enum",
variant: "Unit",
}],
);
}
#[test]
fn test_enum_simple() {
test(
Enum::Simple(1),
&[
Token::NewtypeVariant {
name: "Enum",
variant: "Simple",
},
Token::I32(1),
],
);
}
#[test]
fn test_enum_simple_with_skipped() {
test(
Enum::SimpleWithSkipped(NotDeserializable),
&[Token::UnitVariant {
name: "Enum",
variant: "SimpleWithSkipped",
}],
);
}
#[test]
fn test_enum_seq() {
test(
Enum::Seq(1, 2, 3),
&[
Token::TupleVariant {
name: "Enum",
variant: "Seq",
len: 3,
},
Token::I32(1),
Token::I32(2),
Token::I32(3),
Token::TupleVariantEnd,
],
);
}
#[test]
fn test_enum_map() {
test(
Enum::Map { a: 1, b: 2, c: 3 },
&[
Token::StructVariant {
name: "Enum",
variant: "Map",
len: 3,
},
Token::Str("a"),
Token::I32(1),
Token::Str("b"),
Token::I32(2),
Token::Str("c"),
Token::I32(3),
Token::StructVariantEnd,
],
);
}
#[test]
fn test_enum_unit_usize() {
test(
Enum::Unit,
&[Token::Enum { name: "Enum" }, Token::U32(0), Token::Unit],
);
}
#[test]
fn test_enum_unit_bytes() {
test(
Enum::Unit,
&[
Token::Enum { name: "Enum" },
Token::Bytes(b"Unit"),
Token::Unit,
],
);
}
#[test]
fn test_enum_other_unit() {
test(
EnumOther::Unit,
&[
Token::Enum { name: "EnumOther" },
Token::Str("Unit"),
Token::Unit,
],
);
test(
EnumOther::Unit,
&[Token::Enum { name: "EnumOther" }, Token::U8(0), Token::Unit],
);
test(
EnumOther::Unit,
&[
Token::Enum { name: "EnumOther" },
Token::U16(0),
Token::Unit,
],
);
test(
EnumOther::Unit,
&[
Token::Enum { name: "EnumOther" },
Token::U32(0),
Token::Unit,
],
);
test(
EnumOther::Unit,
&[
Token::Enum { name: "EnumOther" },
Token::U64(0),
Token::Unit,
],
);
}
#[test]
fn test_enum_other() {
test(
EnumOther::Other,
&[
Token::Enum { name: "EnumOther" },
Token::Str("Foo"),
Token::Unit,
],
);
test(
EnumOther::Other,
&[
Token::Enum { name: "EnumOther" },
Token::U8(42),
Token::Unit,
],
);
test(
EnumOther::Other,
&[
Token::Enum { name: "EnumOther" },
Token::U16(42),
Token::Unit,
],
);
test(
EnumOther::Other,
&[
Token::Enum { name: "EnumOther" },
Token::U32(42),
Token::Unit,
],
);
test(
EnumOther::Other,
&[
Token::Enum { name: "EnumOther" },
Token::U64(42),
Token::Unit,
],
);
}
#[test]
fn test_box() {
test(Box::new(0i32), &[Token::I32(0)]);
}
#[test]
fn test_boxed_slice() {
test(
Box::new([0, 1, 2]),
&[
Token::Seq { len: Some(3) },
Token::I32(0),
Token::I32(1),
Token::I32(2),
Token::SeqEnd,
],
);
}
#[test]
fn test_duration() {
test(
Duration::new(1, 2),
&[
Token::Struct {
name: "Duration",
len: 2,
},
Token::Str("secs"),
Token::U64(1),
Token::Str("nanos"),
Token::U32(2),
Token::StructEnd,
],
);
test(
Duration::new(1, 2),
&[
Token::Seq { len: Some(2) },
Token::I64(1),
Token::I64(2),
Token::SeqEnd,
],
);
}
#[test]
fn test_system_time() {
test(
UNIX_EPOCH + Duration::new(1, 2),
&[
Token::Struct {
name: "SystemTime",
len: 2,
},
Token::Str("secs_since_epoch"),
Token::U64(1),
Token::Str("nanos_since_epoch"),
Token::U32(2),
Token::StructEnd,
],
);
test(
UNIX_EPOCH + Duration::new(1, 2),
&[
Token::Seq { len: Some(2) },
Token::I64(1),
Token::I64(2),
Token::SeqEnd,
],
);
}
#[test]
fn test_range() {
test(
1u32..2u32,
&[
Token::Struct {
name: "Range",
len: 2,
},
Token::Str("start"),
Token::U32(1),
Token::Str("end"),
Token::U32(2),
Token::StructEnd,
],
);
test(
1u32..2u32,
&[
Token::Seq { len: Some(2) },
Token::U64(1),
Token::U64(2),
Token::SeqEnd,
],
);
}
#[test]
fn test_range_inclusive() {
test(
1u32..=2u32,
&[
Token::Struct {
name: "RangeInclusive",
len: 2,
},
Token::Str("start"),
Token::U32(1),
Token::Str("end"),
Token::U32(2),
Token::StructEnd,
],
);
test(
1u32..=2u32,
&[
Token::Seq { len: Some(2) },
Token::U64(1),
Token::U64(2),
Token::SeqEnd,
],
);
}
#[test]
fn test_range_from() {
test(
1u32..,
&[
Token::Struct {
name: "RangeFrom",
len: 1,
},
Token::Str("start"),
Token::U32(1),
Token::StructEnd,
],
);
test(
1u32..,
&[Token::Seq { len: Some(1) }, Token::U32(1), Token::SeqEnd],
);
}
#[test]
fn test_range_to() {
test(
..2u32,
&[
Token::Struct {
name: "RangeTo",
len: 1,
},
Token::Str("end"),
Token::U32(2),
Token::StructEnd,
],
);
test(
..2u32,
&[Token::Seq { len: Some(1) }, Token::U32(2), Token::SeqEnd],
);
}
#[test]
fn test_bound() {
test(
Bound::Unbounded::<()>,
&[
Token::Enum { name: "Bound" },
Token::Str("Unbounded"),
Token::Unit,
],
);
test(
Bound::Included(0),
&[
Token::Enum { name: "Bound" },
Token::Str("Included"),
Token::U8(0),
],
);
test(
Bound::Excluded(0),
&[
Token::Enum { name: "Bound" },
Token::Str("Excluded"),
Token::U8(0),
],
);
}
#[test]
fn test_path() {
test(
Path::new("/usr/local/lib"),
&[Token::BorrowedStr("/usr/local/lib")],
);
test(
Path::new("/usr/local/lib"),
&[Token::BorrowedBytes(b"/usr/local/lib")],
);
}
#[test]
fn test_path_buf() {
test(
PathBuf::from("/usr/local/lib"),
&[Token::Str("/usr/local/lib")],
);
test(
PathBuf::from("/usr/local/lib"),
&[Token::String("/usr/local/lib")],
);
test(
PathBuf::from("/usr/local/lib"),
&[Token::Bytes(b"/usr/local/lib")],
);
test(
PathBuf::from("/usr/local/lib"),
&[Token::ByteBuf(b"/usr/local/lib")],
);
}
#[test]
fn test_boxed_path() {
test(
PathBuf::from("/usr/local/lib").into_boxed_path(),
&[Token::Str("/usr/local/lib")],
);
test(
PathBuf::from("/usr/local/lib").into_boxed_path(),
&[Token::String("/usr/local/lib")],
);
test(
PathBuf::from("/usr/local/lib").into_boxed_path(),
&[Token::Bytes(b"/usr/local/lib")],
);
test(
PathBuf::from("/usr/local/lib").into_boxed_path(),
&[Token::ByteBuf(b"/usr/local/lib")],
);
}
#[test]
fn test_cstring() {
test(CString::new("abc").unwrap(), &[Token::Bytes(b"abc")]);
}
#[test]
fn test_rc() {
test(Rc::new(true), &[Token::Bool(true)]);
}
#[test]
fn test_rc_weak_some() {
test(
SkipPartialEq(RcWeak::<bool>::new()),
&[Token::Some, Token::Bool(true)],
);
}
#[test]
fn test_rc_weak_none() {
test(SkipPartialEq(RcWeak::<bool>::new()), &[Token::None]);
}
#[test]
fn test_arc() {
test(Arc::new(true), &[Token::Bool(true)]);
}
#[test]
fn test_arc_weak_some() {
test(
SkipPartialEq(ArcWeak::<bool>::new()),
&[Token::Some, Token::Bool(true)],
);
}
#[test]
fn test_arc_weak_none() {
test(SkipPartialEq(ArcWeak::<bool>::new()), &[Token::None]);
}
#[test]
fn test_wrapping() {
test(Wrapping(1usize), &[Token::U32(1)]);
test(Wrapping(1usize), &[Token::U64(1)]);
}
#[test]
fn test_saturating() {
test(Saturating(1usize), &[Token::U32(1)]);
test(Saturating(1usize), &[Token::U64(1)]);
test(Saturating(0u8), &[Token::I8(0)]);
test(Saturating(0u16), &[Token::I16(0)]);
// saturate input values at the minimum or maximum value
test(Saturating(u8::MAX), &[Token::U16(u16::MAX)]);
test(Saturating(u8::MAX), &[Token::U16(u8::MAX as u16 + 1)]);
test(Saturating(u16::MAX), &[Token::U32(u32::MAX)]);
test(Saturating(u32::MAX), &[Token::U64(u64::MAX)]);
test(Saturating(u8::MIN), &[Token::I8(i8::MIN)]);
test(Saturating(u16::MIN), &[Token::I16(i16::MIN)]);
test(Saturating(u32::MIN), &[Token::I32(i32::MIN)]);
test(Saturating(i8::MIN), &[Token::I16(i16::MIN)]);
test(Saturating(i16::MIN), &[Token::I32(i32::MIN)]);
test(Saturating(i32::MIN), &[Token::I64(i64::MIN)]);
test(Saturating(u8::MIN), &[Token::I8(-1)]);
test(Saturating(u16::MIN), &[Token::I16(-1)]);
#[cfg(target_pointer_width = "64")]
{
test(Saturating(usize::MIN), &[Token::U64(u64::MIN)]);
test(Saturating(usize::MAX), &[Token::U64(u64::MAX)]);
test(Saturating(isize::MIN), &[Token::I64(i64::MIN)]);
test(Saturating(isize::MAX), &[Token::I64(i64::MAX)]);
test(Saturating(0usize), &[Token::I64(i64::MIN)]);
test(
Saturating(9_223_372_036_854_775_807usize),
&[Token::I64(i64::MAX)],
);
}
}
#[test]
fn test_rc_dst() {
test(Rc::<str>::from("s"), &[Token::Str("s")]);
test(
Rc::<[bool]>::from(&[true][..]),
&[
Token::Seq { len: Some(1) },
Token::Bool(true),
Token::SeqEnd,
],
);
}
#[test]
fn test_arc_dst() {
test(Arc::<str>::from("s"), &[Token::Str("s")]);
test(
Arc::<[bool]>::from(&[true][..]),
&[
Token::Seq { len: Some(1) },
Token::Bool(true),
Token::SeqEnd,
],
);
}
#[test]
fn test_ignored_any() {
test(IgnoredAny, &[Token::Str("s")]);
test(
IgnoredAny,
&[
Token::Seq { len: Some(1) },
Token::Bool(true),
Token::SeqEnd,
],
);
test(
IgnoredAny,
&[Token::Enum { name: "E" }, Token::Str("Rust"), Token::Unit],
);
}
#[test]
fn test_net_ipv4addr_readable() {
test(
"1.2.3.4".parse::<net::Ipv4Addr>().unwrap().readable(),
&[Token::Str("1.2.3.4")],
);
}
#[test]
fn test_net_ipv6addr_readable() {
test(
"::1".parse::<net::Ipv6Addr>().unwrap().readable(),
&[Token::Str("::1")],
);
}
#[test]
fn test_net_ipaddr_readable() {
test(
"1.2.3.4".parse::<net::IpAddr>().unwrap().readable(),
&[Token::Str("1.2.3.4")],
);
}
#[test]
fn test_net_socketaddr_readable() {
test(
"1.2.3.4:1234"
.parse::<net::SocketAddr>()
.unwrap()
.readable(),
&[Token::Str("1.2.3.4:1234")],
);
test(
"1.2.3.4:1234"
.parse::<net::SocketAddrV4>()
.unwrap()
.readable(),
&[Token::Str("1.2.3.4:1234")],
);
test(
"[::1]:1234"
.parse::<net::SocketAddrV6>()
.unwrap()
.readable(),
&[Token::Str("[::1]:1234")],
);
}
#[test]
fn test_net_ipv4addr_compact() {
test(
net::Ipv4Addr::from(*b"1234").compact(),
&seq![
Token::Tuple { len: 4 },
b"1234".iter().copied().map(Token::U8),
Token::TupleEnd
],
);
}
#[test]
fn test_net_ipv6addr_compact() {
test(
net::Ipv6Addr::from(*b"1234567890123456").compact(),
&seq![
Token::Tuple { len: 4 },
b"1234567890123456".iter().copied().map(Token::U8),
Token::TupleEnd
],
);
}
#[test]
fn test_net_ipaddr_compact() {
test(
net::IpAddr::from(*b"1234").compact(),
&seq![
Token::NewtypeVariant {
name: "IpAddr",
variant: "V4"
},
Token::Tuple { len: 4 },
b"1234".iter().copied().map(Token::U8),
Token::TupleEnd
],
);
}
#[test]
fn test_net_socketaddr_compact() {
test(
net::SocketAddr::from((*b"1234567890123456", 1234)).compact(),
&seq![
Token::NewtypeVariant {
name: "SocketAddr",
variant: "V6"
},
Token::Tuple { len: 2 },
Token::Tuple { len: 16 },
b"1234567890123456".iter().copied().map(Token::U8),
Token::TupleEnd,
Token::U16(1234),
Token::TupleEnd
],
);
test(
net::SocketAddr::from((*b"1234", 1234)).compact(),
&seq![
Token::NewtypeVariant {
name: "SocketAddr",
variant: "V4"
},
Token::Tuple { len: 2 },
Token::Tuple { len: 4 },
b"1234".iter().copied().map(Token::U8),
Token::TupleEnd,
Token::U16(1234),
Token::TupleEnd
],
);
test(
net::SocketAddrV4::new(net::Ipv4Addr::from(*b"1234"), 1234).compact(),
&seq![
Token::Tuple { len: 2 },
Token::Tuple { len: 4 },
b"1234".iter().copied().map(Token::U8),
Token::TupleEnd,
Token::U16(1234),
Token::TupleEnd
],
);
test(
net::SocketAddrV6::new(net::Ipv6Addr::from(*b"1234567890123456"), 1234, 0, 0).compact(),
&seq![
Token::Tuple { len: 2 },
Token::Tuple { len: 16 },
b"1234567890123456".iter().copied().map(Token::U8),
Token::TupleEnd,
Token::U16(1234),
Token::TupleEnd
],
);
}
#[cfg(feature = "unstable")]
#[test]
fn test_never_result() {
test(
Ok::<u8, !>(0),
&[
Token::NewtypeVariant {
name: "Result",
variant: "Ok",
},
Token::U8(0),
],
);
}
#[cfg(unix)]
#[test]
fn test_osstring() {
use std::os::unix::ffi::OsStringExt;
let value = OsString::from_vec(vec![1, 2, 3]);
let tokens = [
Token::Enum { name: "OsString" },
Token::Str("Unix"),
Token::Seq { len: Some(2) },
Token::U8(1),
Token::U8(2),
Token::U8(3),
Token::SeqEnd,
];
assert_de_tokens(&value, &tokens);
assert_de_tokens_ignore(&tokens);
}
#[cfg(windows)]
#[test]
fn test_osstring() {
use std::os::windows::ffi::OsStringExt;
let value = OsString::from_wide(&[1, 2, 3]);
let tokens = [
Token::Enum { name: "OsString" },
Token::Str("Windows"),
Token::Seq { len: Some(2) },
Token::U16(1),
Token::U16(2),
Token::U16(3),
Token::SeqEnd,
];
assert_de_tokens(&value, &tokens);
assert_de_tokens_ignore(&tokens);
}
#[test]
fn test_cstr() {
assert_de_tokens::<Box<CStr>>(
&CString::new("abc").unwrap().into_boxed_c_str(),
&[Token::Bytes(b"abc")],
);
}
#[test]
fn test_atomics() {
fn test<L, A, T>(load: L, val: T)
where
L: Fn(&A, Ordering) -> T,
A: DeserializeOwned,
T: PartialEq + Debug + Copy + for<'de> IntoDeserializer<'de>,
{
match A::deserialize(val.into_deserializer()) {
Ok(v) => {
let loaded = load(&v, Ordering::Relaxed);
assert_eq!(val, loaded);
}
Err(e) => panic!("tokens failed to deserialize: {}", e),
}
}
test(AtomicBool::load, true);
test(AtomicI8::load, -127i8);
test(AtomicI16::load, -510i16);
test(AtomicI32::load, -131072i32);
test(AtomicIsize::load, -131072isize);
test(AtomicU8::load, 127u8);
test(AtomicU16::load, 510u16);
test(AtomicU32::load, 131072u32);
test(AtomicUsize::load, 131072usize);
#[cfg(target_arch = "x86_64")]
{
test(AtomicI64::load, -8589934592i64);
test(AtomicU64::load, 8589934592u64);
}
}