2016-06-28 23:47:54 -05:00
|
|
|
extern crate serde_test;
|
|
|
|
use self::serde_test::{
|
|
|
|
Token,
|
|
|
|
assert_tokens,
|
|
|
|
assert_ser_tokens,
|
|
|
|
assert_de_tokens,
|
|
|
|
};
|
2015-03-06 21:11:47 -06:00
|
|
|
|
2016-06-28 23:47:54 -05:00
|
|
|
use std::marker::PhantomData;
|
2015-02-20 10:21:15 -06:00
|
|
|
|
2016-03-30 08:33:02 -05:00
|
|
|
// That tests that the derived Serialize implementation doesn't trigger
|
|
|
|
// any warning about `serializer` not being used, in case of empty enums.
|
|
|
|
#[derive(Serialize)]
|
|
|
|
#[allow(dead_code)]
|
|
|
|
#[deny(unused_variables)]
|
|
|
|
enum Void {}
|
|
|
|
|
2015-03-19 09:49:42 -05:00
|
|
|
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
2015-03-03 22:29:59 -06:00
|
|
|
struct NamedUnit;
|
|
|
|
|
2015-03-19 09:49:42 -05:00
|
|
|
#[derive(Debug, PartialEq, Serialize)]
|
2015-03-15 19:47:25 -05:00
|
|
|
struct SerNamedTuple<'a, 'b, A: 'a, B: 'b, C>(&'a A, &'b mut B, C);
|
|
|
|
|
2015-03-19 09:49:42 -05:00
|
|
|
#[derive(Debug, PartialEq, Deserialize)]
|
2015-03-15 19:47:25 -05:00
|
|
|
struct DeNamedTuple<A, B, C>(A, B, C);
|
|
|
|
|
2015-03-19 09:49:42 -05:00
|
|
|
#[derive(Debug, PartialEq, Serialize)]
|
2015-03-15 19:47:25 -05:00
|
|
|
struct SerNamedMap<'a, 'b, A: 'a, B: 'b, C> {
|
|
|
|
a: &'a A,
|
|
|
|
b: &'b mut B,
|
|
|
|
c: C,
|
|
|
|
}
|
|
|
|
|
2015-03-19 09:49:42 -05:00
|
|
|
#[derive(Debug, PartialEq, Deserialize)]
|
2015-03-15 19:47:25 -05:00
|
|
|
struct DeNamedMap<A, B, C> {
|
|
|
|
a: A,
|
|
|
|
b: B,
|
|
|
|
c: C,
|
|
|
|
}
|
|
|
|
|
2015-03-19 09:49:42 -05:00
|
|
|
#[derive(Debug, PartialEq, Serialize)]
|
2015-03-08 21:07:23 -05:00
|
|
|
enum SerEnum<'a, B: 'a, C: /* Trait + */ 'a, D> where D: /* Trait + */ 'a {
|
2015-02-20 10:21:15 -06:00
|
|
|
Unit,
|
|
|
|
Seq(
|
|
|
|
i8,
|
2015-03-06 21:11:47 -06:00
|
|
|
B,
|
2015-02-20 10:21:15 -06:00
|
|
|
&'a C,
|
2015-03-08 21:07:23 -05:00
|
|
|
//C::Type,
|
2015-03-06 21:11:47 -06:00
|
|
|
&'a mut D,
|
|
|
|
//<D as Trait>::Type,
|
2015-02-20 10:21:15 -06:00
|
|
|
),
|
|
|
|
Map {
|
|
|
|
a: i8,
|
2015-03-06 21:11:47 -06:00
|
|
|
b: B,
|
|
|
|
c: &'a C,
|
|
|
|
//d: C::Type,
|
|
|
|
e: &'a mut D,
|
|
|
|
//f: <D as Trait>::Type,
|
2015-02-20 10:21:15 -06:00
|
|
|
},
|
2015-03-14 01:44:18 -05:00
|
|
|
|
|
|
|
// Make sure we can support more than one variant.
|
|
|
|
_Unit2,
|
|
|
|
_Seq2(
|
|
|
|
i8,
|
|
|
|
B,
|
|
|
|
&'a C,
|
|
|
|
//C::Type,
|
|
|
|
&'a mut D,
|
|
|
|
//<D as Trait>::Type,
|
|
|
|
),
|
|
|
|
_Map2 {
|
|
|
|
a: i8,
|
|
|
|
b: B,
|
|
|
|
c: &'a C,
|
|
|
|
//d: C::Type,
|
|
|
|
e: &'a mut D,
|
|
|
|
//f: <D as Trait>::Type,
|
|
|
|
},
|
2015-02-20 10:21:15 -06:00
|
|
|
}
|
|
|
|
|
2015-08-27 22:01:09 -05:00
|
|
|
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
2015-03-08 21:07:23 -05:00
|
|
|
enum DeEnum<B, C: /* Trait */, D> /* where D: Trait */ {
|
|
|
|
Unit,
|
|
|
|
Seq(
|
|
|
|
i8,
|
|
|
|
B,
|
|
|
|
C,
|
|
|
|
//C::Type,
|
|
|
|
D,
|
|
|
|
//<D as Trait>::Type,
|
|
|
|
),
|
|
|
|
Map {
|
|
|
|
a: i8,
|
|
|
|
b: B,
|
|
|
|
c: C,
|
|
|
|
//d: C::Type,
|
|
|
|
e: D,
|
|
|
|
//f: <D as Trait>::Type,
|
|
|
|
},
|
2015-03-14 01:44:18 -05:00
|
|
|
|
|
|
|
// Make sure we can support more than one variant.
|
|
|
|
_Unit2,
|
|
|
|
_Seq2(
|
|
|
|
i8,
|
|
|
|
B,
|
|
|
|
C,
|
|
|
|
//C::Type,
|
|
|
|
D,
|
|
|
|
//<D as Trait>::Type,
|
|
|
|
),
|
|
|
|
_Map2 {
|
|
|
|
a: i8,
|
|
|
|
b: B,
|
|
|
|
c: C,
|
|
|
|
//d: C::Type,
|
|
|
|
e: D,
|
|
|
|
//f: <D as Trait>::Type,
|
|
|
|
},
|
2015-03-08 21:07:23 -05:00
|
|
|
}
|
|
|
|
|
2015-06-18 10:45:03 -05:00
|
|
|
#[derive(Serialize)]
|
|
|
|
enum Lifetimes<'a> {
|
|
|
|
LifetimeSeq(&'a i32),
|
|
|
|
NoLifetimeSeq(i32),
|
|
|
|
LifetimeMap { a: &'a i32 },
|
|
|
|
NoLifetimeMap { a: i32 },
|
|
|
|
}
|
|
|
|
|
2015-07-23 09:25:27 -05:00
|
|
|
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
|
|
|
pub struct GenericStruct<T> {
|
|
|
|
x: T,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
2016-02-13 00:05:02 -06:00
|
|
|
pub struct GenericNewTypeStruct<T>(T);
|
2015-07-23 09:25:27 -05:00
|
|
|
|
|
|
|
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
2015-07-30 11:38:09 -05:00
|
|
|
pub struct GenericTupleStruct<T, U>(T, U);
|
2015-07-23 09:25:27 -05:00
|
|
|
|
|
|
|
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
2015-07-30 11:38:09 -05:00
|
|
|
pub enum GenericEnum<T, U> {
|
|
|
|
Unit,
|
2016-02-13 00:05:02 -06:00
|
|
|
NewType(T),
|
2015-07-30 11:38:09 -05:00
|
|
|
Seq(T, U),
|
|
|
|
Map { x: T, y: U },
|
2015-07-23 09:25:27 -05:00
|
|
|
}
|
|
|
|
|
2016-04-14 01:51:04 -05:00
|
|
|
trait AssociatedType {
|
|
|
|
type X;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl AssociatedType for i32 {
|
|
|
|
type X = i32;
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
|
|
|
struct DefaultTyParam<T: AssociatedType<X=i32> = i32> {
|
|
|
|
phantom: PhantomData<T>
|
|
|
|
}
|
|
|
|
|
2015-03-03 11:50:57 -06:00
|
|
|
#[test]
|
2015-03-06 21:11:47 -06:00
|
|
|
fn test_named_unit() {
|
2015-08-27 22:01:09 -05:00
|
|
|
assert_tokens(
|
|
|
|
&NamedUnit,
|
2016-06-29 01:50:19 -05:00
|
|
|
&[Token::UnitStruct("NamedUnit")]
|
2015-03-06 21:11:47 -06:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2015-03-08 13:39:20 -05:00
|
|
|
fn test_ser_named_tuple() {
|
2015-03-06 21:11:47 -06:00
|
|
|
let a = 5;
|
|
|
|
let mut b = 6;
|
|
|
|
let c = 7;
|
2015-08-27 22:01:09 -05:00
|
|
|
assert_ser_tokens(
|
|
|
|
&SerNamedTuple(&a, &mut b, c),
|
|
|
|
&[
|
2016-07-12 08:44:19 -05:00
|
|
|
Token::TupleStructStart("SerNamedTuple", 3),
|
2016-02-23 07:15:44 -06:00
|
|
|
Token::TupleStructSep,
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::I32(5),
|
2015-03-06 21:11:47 -06:00
|
|
|
|
2016-02-23 07:15:44 -06:00
|
|
|
Token::TupleStructSep,
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::I32(6),
|
|
|
|
|
2016-02-23 07:15:44 -06:00
|
|
|
Token::TupleStructSep,
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::I32(7),
|
2015-03-06 21:11:47 -06:00
|
|
|
|
2016-02-23 07:15:44 -06:00
|
|
|
Token::TupleStructEnd,
|
2015-08-27 22:01:09 -05:00
|
|
|
],
|
2015-03-06 21:11:47 -06:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-03-08 13:39:20 -05:00
|
|
|
#[test]
|
|
|
|
fn test_de_named_tuple() {
|
2015-08-27 22:01:09 -05:00
|
|
|
assert_de_tokens(
|
|
|
|
&DeNamedTuple(5, 6, 7),
|
2016-06-29 01:50:19 -05:00
|
|
|
&[
|
2016-02-13 00:05:02 -06:00
|
|
|
Token::SeqStart(Some(3)),
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::SeqSep,
|
|
|
|
Token::I32(5),
|
|
|
|
|
|
|
|
Token::SeqSep,
|
|
|
|
Token::I32(6),
|
|
|
|
|
|
|
|
Token::SeqSep,
|
|
|
|
Token::I32(7),
|
2015-03-08 13:39:20 -05:00
|
|
|
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::SeqEnd,
|
|
|
|
]
|
2015-03-08 13:39:20 -05:00
|
|
|
);
|
2016-02-13 00:05:02 -06:00
|
|
|
|
|
|
|
assert_de_tokens(
|
|
|
|
&DeNamedTuple(5, 6, 7),
|
2016-06-29 01:50:19 -05:00
|
|
|
&[
|
2016-07-12 08:44:19 -05:00
|
|
|
Token::TupleStructStart("DeNamedTuple", 3),
|
2016-02-23 07:15:44 -06:00
|
|
|
Token::TupleStructSep,
|
2016-02-13 00:05:02 -06:00
|
|
|
Token::I32(5),
|
|
|
|
|
2016-02-23 07:15:44 -06:00
|
|
|
Token::TupleStructSep,
|
2016-02-13 00:05:02 -06:00
|
|
|
Token::I32(6),
|
|
|
|
|
2016-02-23 07:15:44 -06:00
|
|
|
Token::TupleStructSep,
|
2016-02-13 00:05:02 -06:00
|
|
|
Token::I32(7),
|
|
|
|
|
2016-02-23 07:15:44 -06:00
|
|
|
Token::TupleStructEnd,
|
2016-02-13 00:05:02 -06:00
|
|
|
]
|
|
|
|
);
|
2015-03-08 13:39:20 -05:00
|
|
|
}
|
|
|
|
|
2015-03-07 00:14:13 -06:00
|
|
|
#[test]
|
2015-03-08 20:46:41 -05:00
|
|
|
fn test_ser_named_map() {
|
2015-03-07 00:14:13 -06:00
|
|
|
let a = 5;
|
|
|
|
let mut b = 6;
|
|
|
|
let c = 7;
|
|
|
|
|
2015-08-27 22:01:09 -05:00
|
|
|
assert_ser_tokens(
|
|
|
|
&SerNamedMap {
|
|
|
|
a: &a,
|
|
|
|
b: &mut b,
|
|
|
|
c: c,
|
|
|
|
},
|
|
|
|
&[
|
2016-07-12 08:44:19 -05:00
|
|
|
Token::StructStart("SerNamedMap", 3),
|
2015-08-27 22:01:09 -05:00
|
|
|
|
2016-02-13 00:05:02 -06:00
|
|
|
Token::StructSep,
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::Str("a"),
|
|
|
|
Token::I32(5),
|
|
|
|
|
2016-02-13 00:05:02 -06:00
|
|
|
Token::StructSep,
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::Str("b"),
|
|
|
|
Token::I32(6),
|
|
|
|
|
2016-02-13 00:05:02 -06:00
|
|
|
Token::StructSep,
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::Str("c"),
|
|
|
|
Token::I32(7),
|
|
|
|
|
2016-02-13 00:05:02 -06:00
|
|
|
Token::StructEnd,
|
2015-08-27 22:01:09 -05:00
|
|
|
]
|
2015-03-07 00:14:13 -06:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-03-08 20:46:41 -05:00
|
|
|
#[test]
|
|
|
|
fn test_de_named_map() {
|
2015-08-27 22:01:09 -05:00
|
|
|
assert_de_tokens(
|
|
|
|
&DeNamedMap {
|
|
|
|
a: 5,
|
|
|
|
b: 6,
|
|
|
|
c: 7,
|
|
|
|
},
|
2016-06-29 01:50:19 -05:00
|
|
|
&[
|
2016-07-12 08:44:19 -05:00
|
|
|
Token::StructStart("DeNamedMap", 3),
|
2015-08-27 22:01:09 -05:00
|
|
|
|
2016-02-13 00:05:02 -06:00
|
|
|
Token::StructSep,
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::Str("a"),
|
|
|
|
Token::I32(5),
|
|
|
|
|
2016-02-13 00:05:02 -06:00
|
|
|
Token::StructSep,
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::Str("b"),
|
|
|
|
Token::I32(6),
|
|
|
|
|
2016-02-13 00:05:02 -06:00
|
|
|
Token::StructSep,
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::Str("c"),
|
|
|
|
Token::I32(7),
|
|
|
|
|
2016-02-13 00:05:02 -06:00
|
|
|
Token::StructEnd,
|
2015-08-27 22:01:09 -05:00
|
|
|
]
|
|
|
|
);
|
2015-03-08 20:46:41 -05:00
|
|
|
}
|
|
|
|
|
2015-03-06 21:11:47 -06:00
|
|
|
#[test]
|
2015-03-08 21:07:23 -05:00
|
|
|
fn test_ser_enum_unit() {
|
2015-08-27 22:01:09 -05:00
|
|
|
assert_ser_tokens(
|
|
|
|
&SerEnum::Unit::<u32, u32, u32>,
|
|
|
|
&[
|
|
|
|
Token::EnumUnit("SerEnum", "Unit"),
|
|
|
|
]
|
2015-03-06 21:11:47 -06:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2015-03-08 21:07:23 -05:00
|
|
|
fn test_ser_enum_seq() {
|
2015-03-06 21:11:47 -06:00
|
|
|
let a = 1;
|
|
|
|
let b = 2;
|
|
|
|
let c = 3;
|
|
|
|
//let d = 4;
|
|
|
|
let mut e = 5;
|
|
|
|
//let f = 6;
|
|
|
|
|
2015-08-27 22:01:09 -05:00
|
|
|
assert_ser_tokens(
|
|
|
|
&SerEnum::Seq(
|
2015-03-06 21:11:47 -06:00
|
|
|
a,
|
|
|
|
b,
|
|
|
|
&c,
|
|
|
|
//d,
|
|
|
|
&mut e,
|
|
|
|
//f,
|
2015-08-27 22:01:09 -05:00
|
|
|
),
|
|
|
|
&[
|
2016-07-12 08:44:19 -05:00
|
|
|
Token::EnumSeqStart("SerEnum", "Seq", 4),
|
2015-03-06 21:11:47 -06:00
|
|
|
|
2016-02-13 00:05:02 -06:00
|
|
|
Token::EnumSeqSep,
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::I8(1),
|
|
|
|
|
2016-02-13 00:05:02 -06:00
|
|
|
Token::EnumSeqSep,
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::I32(2),
|
|
|
|
|
2016-02-13 00:05:02 -06:00
|
|
|
Token::EnumSeqSep,
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::I32(3),
|
|
|
|
|
2016-02-13 00:05:02 -06:00
|
|
|
Token::EnumSeqSep,
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::I32(5),
|
|
|
|
|
2016-02-13 00:05:02 -06:00
|
|
|
Token::EnumSeqEnd,
|
2015-08-27 22:01:09 -05:00
|
|
|
],
|
2015-03-06 21:11:47 -06:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2015-03-08 21:07:23 -05:00
|
|
|
fn test_ser_enum_map() {
|
2015-03-06 21:11:47 -06:00
|
|
|
let a = 1;
|
|
|
|
let b = 2;
|
|
|
|
let c = 3;
|
|
|
|
//let d = 4;
|
|
|
|
let mut e = 5;
|
|
|
|
//let f = 6;
|
|
|
|
|
2015-08-27 22:01:09 -05:00
|
|
|
assert_ser_tokens(
|
|
|
|
&SerEnum::Map {
|
2015-03-06 21:11:47 -06:00
|
|
|
a: a,
|
|
|
|
b: b,
|
|
|
|
c: &c,
|
|
|
|
//d: d,
|
|
|
|
e: &mut e,
|
|
|
|
//f: f,
|
2015-08-27 22:01:09 -05:00
|
|
|
},
|
|
|
|
&[
|
2016-07-12 08:44:19 -05:00
|
|
|
Token::EnumMapStart("SerEnum", "Map", 4),
|
2015-03-06 21:11:47 -06:00
|
|
|
|
2016-02-13 00:05:02 -06:00
|
|
|
Token::EnumMapSep,
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::Str("a"),
|
|
|
|
Token::I8(1),
|
|
|
|
|
2016-02-13 00:05:02 -06:00
|
|
|
Token::EnumMapSep,
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::Str("b"),
|
|
|
|
Token::I32(2),
|
|
|
|
|
2016-02-13 00:05:02 -06:00
|
|
|
Token::EnumMapSep,
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::Str("c"),
|
|
|
|
Token::I32(3),
|
|
|
|
|
2016-02-13 00:05:02 -06:00
|
|
|
Token::EnumMapSep,
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::Str("e"),
|
|
|
|
Token::I32(5),
|
|
|
|
|
2016-02-13 00:05:02 -06:00
|
|
|
Token::EnumMapEnd,
|
2015-08-27 22:01:09 -05:00
|
|
|
],
|
2015-03-06 21:11:47 -06:00
|
|
|
);
|
2015-03-03 11:50:57 -06:00
|
|
|
}
|
2015-03-08 21:07:23 -05:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_de_enum_unit() {
|
2015-08-27 22:01:09 -05:00
|
|
|
assert_tokens(
|
|
|
|
&DeEnum::Unit::<u32, u32, u32>,
|
2016-06-29 01:50:19 -05:00
|
|
|
&[
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::EnumUnit("DeEnum", "Unit"),
|
|
|
|
],
|
2015-03-08 21:07:23 -05:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_de_enum_seq() {
|
|
|
|
let a = 1;
|
|
|
|
let b = 2;
|
|
|
|
let c = 3;
|
|
|
|
//let d = 4;
|
|
|
|
let e = 5;
|
|
|
|
//let f = 6;
|
|
|
|
|
2015-08-27 22:01:09 -05:00
|
|
|
assert_tokens(
|
|
|
|
&DeEnum::Seq(
|
2015-03-08 21:07:23 -05:00
|
|
|
a,
|
|
|
|
b,
|
|
|
|
c,
|
|
|
|
//d,
|
|
|
|
e,
|
|
|
|
//f,
|
2015-08-27 22:01:09 -05:00
|
|
|
),
|
2016-06-29 01:50:19 -05:00
|
|
|
&[
|
2016-07-12 08:44:19 -05:00
|
|
|
Token::EnumSeqStart("DeEnum", "Seq", 4),
|
2015-03-08 21:07:23 -05:00
|
|
|
|
2016-02-13 00:05:02 -06:00
|
|
|
Token::EnumSeqSep,
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::I8(1),
|
|
|
|
|
2016-02-13 00:05:02 -06:00
|
|
|
Token::EnumSeqSep,
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::I32(2),
|
|
|
|
|
2016-02-13 00:05:02 -06:00
|
|
|
Token::EnumSeqSep,
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::I32(3),
|
|
|
|
|
2016-02-13 00:05:02 -06:00
|
|
|
Token::EnumSeqSep,
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::I32(5),
|
|
|
|
|
2016-02-13 00:05:02 -06:00
|
|
|
Token::EnumSeqEnd,
|
2015-08-27 22:01:09 -05:00
|
|
|
],
|
2015-03-08 21:07:23 -05:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_de_enum_map() {
|
|
|
|
let a = 1;
|
|
|
|
let b = 2;
|
|
|
|
let c = 3;
|
|
|
|
//let d = 4;
|
|
|
|
let e = 5;
|
|
|
|
//let f = 6;
|
|
|
|
|
2015-08-27 22:01:09 -05:00
|
|
|
assert_tokens(
|
|
|
|
&DeEnum::Map {
|
2015-03-08 21:07:23 -05:00
|
|
|
a: a,
|
|
|
|
b: b,
|
|
|
|
c: c,
|
|
|
|
//d: d,
|
|
|
|
e: e,
|
|
|
|
//f: f,
|
2015-08-27 22:01:09 -05:00
|
|
|
},
|
2016-06-29 01:50:19 -05:00
|
|
|
&[
|
2016-07-12 08:44:19 -05:00
|
|
|
Token::EnumMapStart("DeEnum", "Map", 4),
|
2015-03-08 21:07:23 -05:00
|
|
|
|
2016-02-13 00:05:02 -06:00
|
|
|
Token::EnumMapSep,
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::Str("a"),
|
|
|
|
Token::I8(1),
|
|
|
|
|
2016-02-13 00:05:02 -06:00
|
|
|
Token::EnumMapSep,
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::Str("b"),
|
|
|
|
Token::I32(2),
|
|
|
|
|
2016-02-13 00:05:02 -06:00
|
|
|
Token::EnumMapSep,
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::Str("c"),
|
|
|
|
Token::I32(3),
|
|
|
|
|
2016-02-13 00:05:02 -06:00
|
|
|
Token::EnumMapSep,
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::Str("e"),
|
|
|
|
Token::I32(5),
|
|
|
|
|
2016-02-13 00:05:02 -06:00
|
|
|
Token::EnumMapEnd,
|
2015-08-27 22:01:09 -05:00
|
|
|
],
|
2015-03-08 21:07:23 -05:00
|
|
|
);
|
|
|
|
}
|
2015-06-18 10:45:03 -05:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_lifetimes() {
|
|
|
|
let value = 5;
|
2015-08-27 22:01:09 -05:00
|
|
|
|
|
|
|
assert_ser_tokens(
|
|
|
|
&Lifetimes::LifetimeSeq(&value),
|
|
|
|
&[
|
2016-02-13 00:05:02 -06:00
|
|
|
Token::EnumNewType("Lifetimes", "LifetimeSeq"),
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::I32(5),
|
|
|
|
]
|
2015-06-18 10:45:03 -05:00
|
|
|
);
|
|
|
|
|
2015-08-27 22:01:09 -05:00
|
|
|
assert_ser_tokens(
|
|
|
|
&Lifetimes::NoLifetimeSeq(5),
|
|
|
|
&[
|
2016-02-13 00:05:02 -06:00
|
|
|
Token::EnumNewType("Lifetimes", "NoLifetimeSeq"),
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::I32(5),
|
|
|
|
]
|
2015-06-18 10:45:03 -05:00
|
|
|
);
|
|
|
|
|
2015-08-27 22:01:09 -05:00
|
|
|
assert_ser_tokens(
|
|
|
|
&Lifetimes::LifetimeMap { a: &value },
|
|
|
|
&[
|
2016-07-12 08:44:19 -05:00
|
|
|
Token::EnumMapStart("Lifetimes", "LifetimeMap", 1),
|
2015-08-27 22:01:09 -05:00
|
|
|
|
2016-02-13 00:05:02 -06:00
|
|
|
Token::EnumMapSep,
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::Str("a"),
|
|
|
|
Token::I32(5),
|
|
|
|
|
2016-02-13 00:05:02 -06:00
|
|
|
Token::EnumMapEnd,
|
2015-08-27 22:01:09 -05:00
|
|
|
]
|
2015-06-18 10:45:03 -05:00
|
|
|
);
|
|
|
|
|
2015-08-27 22:01:09 -05:00
|
|
|
assert_ser_tokens(
|
|
|
|
&Lifetimes::NoLifetimeMap { a: 5 },
|
|
|
|
&[
|
2016-07-12 08:44:19 -05:00
|
|
|
Token::EnumMapStart("Lifetimes", "NoLifetimeMap", 1),
|
2015-08-27 22:01:09 -05:00
|
|
|
|
2016-02-13 00:05:02 -06:00
|
|
|
Token::EnumMapSep,
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::Str("a"),
|
|
|
|
Token::I32(5),
|
|
|
|
|
2016-02-13 00:05:02 -06:00
|
|
|
Token::EnumMapEnd,
|
2015-08-27 22:01:09 -05:00
|
|
|
]
|
2015-06-18 10:45:03 -05:00
|
|
|
);
|
|
|
|
}
|
2015-07-23 09:25:27 -05:00
|
|
|
|
2015-08-27 22:01:09 -05:00
|
|
|
#[test]
|
|
|
|
fn test_generic_struct() {
|
|
|
|
assert_tokens(
|
|
|
|
&GenericStruct { x: 5u32 },
|
2016-06-29 01:50:19 -05:00
|
|
|
&[
|
2016-07-12 08:44:19 -05:00
|
|
|
Token::StructStart("GenericStruct", 1),
|
2015-08-27 22:01:09 -05:00
|
|
|
|
2016-02-13 00:05:02 -06:00
|
|
|
Token::StructSep,
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::Str("x"),
|
|
|
|
Token::U32(5),
|
|
|
|
|
2016-02-13 00:05:02 -06:00
|
|
|
Token::StructEnd,
|
2015-08-27 22:01:09 -05:00
|
|
|
]
|
|
|
|
);
|
2015-07-30 11:38:09 -05:00
|
|
|
}
|
2015-07-23 09:25:27 -05:00
|
|
|
|
2015-08-27 22:01:09 -05:00
|
|
|
#[test]
|
|
|
|
fn test_generic_newtype_struct() {
|
|
|
|
assert_tokens(
|
2016-02-13 00:05:02 -06:00
|
|
|
&GenericNewTypeStruct(5u32),
|
2016-06-29 01:50:19 -05:00
|
|
|
&[
|
2016-02-13 00:05:02 -06:00
|
|
|
Token::StructNewType("GenericNewTypeStruct"),
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::U32(5),
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_generic_tuple_struct() {
|
|
|
|
assert_tokens(
|
|
|
|
&GenericTupleStruct(5u32, 6u32),
|
2016-06-29 01:50:19 -05:00
|
|
|
&[
|
2016-07-12 08:44:19 -05:00
|
|
|
Token::TupleStructStart("GenericTupleStruct", 2),
|
2015-08-27 22:01:09 -05:00
|
|
|
|
2016-02-23 07:15:44 -06:00
|
|
|
Token::TupleStructSep,
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::U32(5),
|
|
|
|
|
2016-02-23 07:15:44 -06:00
|
|
|
Token::TupleStructSep,
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::U32(6),
|
|
|
|
|
2016-02-23 07:15:44 -06:00
|
|
|
Token::TupleStructEnd,
|
2015-08-27 22:01:09 -05:00
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_generic_enum_unit() {
|
|
|
|
assert_tokens(
|
|
|
|
&GenericEnum::Unit::<u32, u32>,
|
2016-06-29 01:50:19 -05:00
|
|
|
&[
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::EnumUnit("GenericEnum", "Unit"),
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_generic_enum_newtype() {
|
|
|
|
assert_tokens(
|
2016-02-13 00:05:02 -06:00
|
|
|
&GenericEnum::NewType::<u32, u32>(5),
|
2016-06-29 01:50:19 -05:00
|
|
|
&[
|
2016-02-13 00:05:02 -06:00
|
|
|
Token::EnumNewType("GenericEnum", "NewType"),
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::U32(5),
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_generic_enum_seq() {
|
|
|
|
assert_tokens(
|
|
|
|
&GenericEnum::Seq::<u32, u32>(5, 6),
|
2016-06-29 01:50:19 -05:00
|
|
|
&[
|
2016-07-12 08:44:19 -05:00
|
|
|
Token::EnumSeqStart("GenericEnum", "Seq", 2),
|
2015-08-27 22:01:09 -05:00
|
|
|
|
2016-02-13 00:05:02 -06:00
|
|
|
Token::EnumSeqSep,
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::U32(5),
|
|
|
|
|
2016-02-13 00:05:02 -06:00
|
|
|
Token::EnumSeqSep,
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::U32(6),
|
|
|
|
|
2016-02-13 00:05:02 -06:00
|
|
|
Token::EnumSeqEnd,
|
2015-08-27 22:01:09 -05:00
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_generic_enum_map() {
|
|
|
|
assert_tokens(
|
|
|
|
&GenericEnum::Map::<u32, u32> { x: 5, y: 6 },
|
2016-06-29 01:50:19 -05:00
|
|
|
&[
|
2016-07-12 08:44:19 -05:00
|
|
|
Token::EnumMapStart("GenericEnum", "Map", 2),
|
2015-08-27 22:01:09 -05:00
|
|
|
|
2016-02-13 00:05:02 -06:00
|
|
|
Token::EnumMapSep,
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::Str("x"),
|
|
|
|
Token::U32(5),
|
|
|
|
|
2016-02-13 00:05:02 -06:00
|
|
|
Token::EnumMapSep,
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::Str("y"),
|
|
|
|
Token::U32(6),
|
|
|
|
|
2016-02-13 00:05:02 -06:00
|
|
|
Token::EnumMapEnd,
|
2015-08-27 22:01:09 -05:00
|
|
|
]
|
|
|
|
);
|
2015-07-23 09:25:27 -05:00
|
|
|
}
|
2016-04-14 01:51:04 -05:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_default_ty_param() {
|
|
|
|
assert_tokens(
|
|
|
|
&DefaultTyParam::<i32> { phantom: PhantomData },
|
2016-06-29 01:50:19 -05:00
|
|
|
&[
|
2016-07-12 08:44:19 -05:00
|
|
|
Token::StructStart("DefaultTyParam", 1),
|
2016-04-14 01:51:04 -05:00
|
|
|
|
|
|
|
Token::StructSep,
|
|
|
|
Token::Str("phantom"),
|
|
|
|
Token::UnitStruct("PhantomData"),
|
|
|
|
|
|
|
|
Token::StructEnd,
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|