2015-03-20 22:35:01 -05:00
|
|
|
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
|
2015-03-20 10:32:33 -05:00
|
|
|
|
2015-12-01 11:03:08 -06:00
|
|
|
use num::FromPrimitive;
|
|
|
|
use num::bigint::{BigInt, BigUint};
|
|
|
|
use num::complex::Complex;
|
|
|
|
use num::rational::Ratio;
|
|
|
|
|
2015-08-27 22:01:09 -05:00
|
|
|
use serde::de::{Deserializer, Visitor};
|
2015-03-03 23:19:55 -06:00
|
|
|
|
2015-08-27 22:01:09 -05:00
|
|
|
use token::{Token, assert_de_tokens};
|
2015-03-03 23:19:55 -06:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-04-05 12:20:33 -05:00
|
|
|
#[derive(Copy, Clone, PartialEq, Debug, Deserialize)]
|
2015-07-04 14:11:20 -05:00
|
|
|
struct UnitStruct;
|
2015-03-03 23:19:55 -06:00
|
|
|
|
2015-03-19 09:49:42 -05:00
|
|
|
#[derive(PartialEq, Debug, Deserialize)]
|
2015-07-04 14:11:20 -05:00
|
|
|
struct TupleStruct(i32, i32, i32);
|
2015-03-03 23:19:55 -06:00
|
|
|
|
2015-03-19 09:49:42 -05:00
|
|
|
#[derive(PartialEq, Debug, Deserialize)]
|
2015-07-04 14:11:20 -05:00
|
|
|
struct Struct {
|
2015-03-03 23:19:55 -06:00
|
|
|
a: i32,
|
|
|
|
b: i32,
|
|
|
|
c: i32,
|
|
|
|
}
|
|
|
|
|
2015-03-19 09:49:42 -05:00
|
|
|
#[derive(PartialEq, Debug, Deserialize)]
|
2015-03-03 23:19:55 -06:00
|
|
|
enum Enum {
|
|
|
|
Unit,
|
2015-07-30 09:54:55 -05:00
|
|
|
Simple(i32),
|
2015-03-03 23:19:55 -06:00
|
|
|
Seq(i32, i32, i32),
|
|
|
|
Map { a: i32, b: i32, c: i32 }
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
macro_rules! declare_test {
|
|
|
|
($name:ident { $($value:expr => $tokens:expr,)+ }) => {
|
|
|
|
#[test]
|
|
|
|
fn $name() {
|
|
|
|
$(
|
2015-08-27 22:01:09 -05:00
|
|
|
assert_de_tokens(&$value, $tokens);
|
2015-03-03 23:19:55 -06:00
|
|
|
)+
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! declare_tests {
|
|
|
|
($($name:ident { $($value:expr => $tokens:expr,)+ })+) => {
|
|
|
|
$(
|
|
|
|
declare_test!($name { $($value => $tokens,)+ });
|
|
|
|
)+
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
declare_tests! {
|
|
|
|
test_bool {
|
|
|
|
true => vec![Token::Bool(true)],
|
|
|
|
false => vec![Token::Bool(false)],
|
|
|
|
}
|
|
|
|
test_isize {
|
|
|
|
0isize => vec![Token::Isize(0)],
|
|
|
|
0isize => vec![Token::I8(0)],
|
|
|
|
0isize => vec![Token::I16(0)],
|
|
|
|
0isize => vec![Token::I32(0)],
|
|
|
|
0isize => vec![Token::I64(0)],
|
|
|
|
0isize => vec![Token::Usize(0)],
|
|
|
|
0isize => vec![Token::U8(0)],
|
|
|
|
0isize => vec![Token::U16(0)],
|
|
|
|
0isize => vec![Token::U32(0)],
|
|
|
|
0isize => vec![Token::U64(0)],
|
|
|
|
0isize => vec![Token::F32(0.)],
|
|
|
|
0isize => vec![Token::F64(0.)],
|
|
|
|
}
|
|
|
|
test_ints {
|
|
|
|
0isize => vec![Token::Isize(0)],
|
|
|
|
0i8 => vec![Token::I8(0)],
|
|
|
|
0i16 => vec![Token::I16(0)],
|
|
|
|
0i32 => vec![Token::I32(0)],
|
|
|
|
0i64 => vec![Token::I64(0)],
|
|
|
|
}
|
|
|
|
test_uints {
|
|
|
|
0usize => vec![Token::Usize(0)],
|
|
|
|
0u8 => vec![Token::U8(0)],
|
|
|
|
0u16 => vec![Token::U16(0)],
|
|
|
|
0u32 => vec![Token::U32(0)],
|
|
|
|
0u64 => vec![Token::U64(0)],
|
|
|
|
}
|
|
|
|
test_floats {
|
|
|
|
0f32 => vec![Token::F32(0.)],
|
|
|
|
0f64 => vec![Token::F64(0.)],
|
|
|
|
}
|
|
|
|
test_char {
|
|
|
|
'a' => vec![Token::Char('a')],
|
|
|
|
'a' => vec![Token::Str("a")],
|
|
|
|
'a' => vec![Token::String("a".to_string())],
|
|
|
|
}
|
|
|
|
test_string {
|
|
|
|
"abc".to_string() => vec![Token::Str("abc")],
|
|
|
|
"abc".to_string() => vec![Token::String("abc".to_string())],
|
|
|
|
"a".to_string() => vec![Token::Char('a')],
|
|
|
|
}
|
|
|
|
test_option {
|
|
|
|
None::<i32> => vec![Token::Unit],
|
|
|
|
None::<i32> => vec![Token::Option(false)],
|
|
|
|
Some(1) => vec![Token::I32(1)],
|
|
|
|
Some(1) => vec![
|
|
|
|
Token::Option(true),
|
|
|
|
Token::I32(1),
|
|
|
|
],
|
|
|
|
}
|
2015-07-19 13:16:46 -05:00
|
|
|
test_result {
|
|
|
|
Ok::<i32, i32>(0) => vec![
|
|
|
|
Token::EnumStart("Result"),
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::Str("Ok"),
|
|
|
|
Token::I32(0),
|
2015-07-19 13:16:46 -05:00
|
|
|
],
|
|
|
|
Err::<i32, i32>(1) => vec![
|
|
|
|
Token::EnumStart("Result"),
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::Str("Err"),
|
|
|
|
Token::I32(1),
|
2015-07-19 13:16:46 -05:00
|
|
|
],
|
|
|
|
}
|
2015-03-03 23:19:55 -06:00
|
|
|
test_unit {
|
|
|
|
() => vec![Token::Unit],
|
|
|
|
() => vec![
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::SeqStart(Some(0)),
|
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
|
|
|
() => vec![
|
|
|
|
Token::SeqStart(None),
|
2015-03-03 23:19:55 -06:00
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
|
|
|
() => vec![
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::TupleStructStart("Anything", Some(0)),
|
2015-03-03 23:19:55 -06:00
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
|
|
|
}
|
2015-07-04 14:11:20 -05:00
|
|
|
test_unit_struct {
|
|
|
|
UnitStruct => vec![Token::Unit],
|
|
|
|
UnitStruct => vec![
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::UnitStruct("UnitStruct"),
|
2015-03-20 10:32:33 -05:00
|
|
|
],
|
2015-07-04 14:11:20 -05:00
|
|
|
UnitStruct => vec![
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::SeqStart(Some(0)),
|
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
|
|
|
UnitStruct => vec![
|
|
|
|
Token::SeqStart(None),
|
2015-03-03 23:19:55 -06:00
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
|
|
|
}
|
2015-07-04 14:11:20 -05:00
|
|
|
test_tuple_struct {
|
|
|
|
TupleStruct(1, 2, 3) => vec![
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::SeqStart(Some(3)),
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::SeqSep,
|
2015-03-03 23:19:55 -06:00
|
|
|
Token::I32(1),
|
|
|
|
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::SeqSep,
|
2015-03-03 23:19:55 -06:00
|
|
|
Token::I32(2),
|
|
|
|
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::SeqSep,
|
2015-03-03 23:19:55 -06:00
|
|
|
Token::I32(3),
|
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
2015-07-04 14:11:20 -05:00
|
|
|
TupleStruct(1, 2, 3) => vec![
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::SeqStart(None),
|
|
|
|
Token::SeqSep,
|
|
|
|
Token::I32(1),
|
|
|
|
|
|
|
|
Token::SeqSep,
|
|
|
|
Token::I32(2),
|
|
|
|
|
|
|
|
Token::SeqSep,
|
|
|
|
Token::I32(3),
|
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
|
|
|
TupleStruct(1, 2, 3) => vec![
|
|
|
|
Token::TupleStructStart("TupleStruct", Some(3)),
|
|
|
|
Token::SeqSep,
|
|
|
|
Token::I32(1),
|
|
|
|
|
|
|
|
Token::SeqSep,
|
|
|
|
Token::I32(2),
|
|
|
|
|
|
|
|
Token::SeqSep,
|
|
|
|
Token::I32(3),
|
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
|
|
|
TupleStruct(1, 2, 3) => vec![
|
|
|
|
Token::TupleStructStart("TupleStruct", None),
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::SeqSep,
|
|
|
|
Token::I32(1),
|
|
|
|
|
|
|
|
Token::SeqSep,
|
|
|
|
Token::I32(2),
|
|
|
|
|
|
|
|
Token::SeqSep,
|
|
|
|
Token::I32(3),
|
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
|
|
|
}
|
|
|
|
test_btreeset {
|
|
|
|
BTreeSet::<isize>::new() => vec![
|
|
|
|
Token::Unit,
|
|
|
|
],
|
|
|
|
BTreeSet::<isize>::new() => vec![
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::SeqStart(Some(0)),
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
|
|
|
btreeset![btreeset![], btreeset![1], btreeset![2, 3]] => vec![
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::SeqStart(Some(3)),
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::SeqSep,
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::SeqStart(Some(0)),
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::SeqEnd,
|
|
|
|
|
|
|
|
Token::SeqSep,
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::SeqStart(Some(1)),
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::SeqSep,
|
|
|
|
Token::I32(1),
|
|
|
|
Token::SeqEnd,
|
|
|
|
|
|
|
|
Token::SeqSep,
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::SeqStart(Some(2)),
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::SeqSep,
|
|
|
|
Token::I32(2),
|
|
|
|
|
|
|
|
Token::SeqSep,
|
|
|
|
Token::I32(3),
|
|
|
|
Token::SeqEnd,
|
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
|
|
|
BTreeSet::<isize>::new() => vec![
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::UnitStruct("Anything"),
|
2015-03-20 22:35:01 -05:00
|
|
|
],
|
|
|
|
BTreeSet::<isize>::new() => vec![
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::TupleStructStart("Anything", Some(0)),
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
|
|
|
}
|
|
|
|
test_hashset {
|
|
|
|
HashSet::<isize>::new() => vec![
|
|
|
|
Token::Unit,
|
|
|
|
],
|
|
|
|
HashSet::<isize>::new() => vec![
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::SeqStart(Some(0)),
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
|
|
|
hashset![1, 2, 3] => vec![
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::SeqStart(Some(3)),
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::SeqSep,
|
2015-03-03 23:19:55 -06:00
|
|
|
Token::I32(1),
|
|
|
|
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::SeqSep,
|
2015-03-03 23:19:55 -06:00
|
|
|
Token::I32(2),
|
|
|
|
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::SeqSep,
|
2015-03-03 23:19:55 -06:00
|
|
|
Token::I32(3),
|
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
2015-03-20 22:35:01 -05:00
|
|
|
HashSet::<isize>::new() => vec![
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::UnitStruct("Anything"),
|
2015-03-20 22:35:01 -05:00
|
|
|
],
|
|
|
|
HashSet::<isize>::new() => vec![
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::TupleStructStart("Anything", Some(0)),
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
2015-03-03 23:19:55 -06:00
|
|
|
}
|
|
|
|
test_vec {
|
2015-03-20 10:47:33 -05:00
|
|
|
Vec::<isize>::new() => vec![
|
|
|
|
Token::Unit,
|
|
|
|
],
|
2015-03-03 23:19:55 -06:00
|
|
|
Vec::<isize>::new() => vec![
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::SeqStart(Some(0)),
|
2015-03-03 23:19:55 -06:00
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
|
|
|
vec![vec![], vec![1], vec![2, 3]] => vec![
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::SeqStart(Some(3)),
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::SeqSep,
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::SeqStart(Some(0)),
|
2015-03-03 23:19:55 -06:00
|
|
|
Token::SeqEnd,
|
|
|
|
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::SeqSep,
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::SeqStart(Some(1)),
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::SeqSep,
|
2015-03-03 23:19:55 -06:00
|
|
|
Token::I32(1),
|
|
|
|
Token::SeqEnd,
|
|
|
|
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::SeqSep,
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::SeqStart(Some(2)),
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::SeqSep,
|
2015-03-03 23:19:55 -06:00
|
|
|
Token::I32(2),
|
|
|
|
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::SeqSep,
|
2015-03-03 23:19:55 -06:00
|
|
|
Token::I32(3),
|
|
|
|
Token::SeqEnd,
|
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
2015-03-20 10:47:33 -05:00
|
|
|
Vec::<isize>::new() => vec![
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::UnitStruct("Anything"),
|
2015-03-20 10:47:33 -05:00
|
|
|
],
|
|
|
|
Vec::<isize>::new() => vec![
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::TupleStructStart("Anything", Some(0)),
|
2015-03-20 10:47:33 -05:00
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
2015-03-03 23:19:55 -06:00
|
|
|
}
|
2015-05-16 06:32:58 -05:00
|
|
|
test_array {
|
|
|
|
[0; 0] => vec![
|
|
|
|
Token::Unit,
|
|
|
|
],
|
|
|
|
[0; 0] => vec![
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::SeqStart(Some(0)),
|
2015-05-16 06:32:58 -05:00
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
|
|
|
([0; 0], [1], [2, 3]) => vec![
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::SeqStart(Some(3)),
|
2015-05-16 06:32:58 -05:00
|
|
|
Token::SeqSep,
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::SeqStart(Some(0)),
|
2015-05-16 06:32:58 -05:00
|
|
|
Token::SeqEnd,
|
|
|
|
|
|
|
|
Token::SeqSep,
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::SeqStart(Some(1)),
|
2015-05-16 06:32:58 -05:00
|
|
|
Token::SeqSep,
|
|
|
|
Token::I32(1),
|
|
|
|
Token::SeqEnd,
|
|
|
|
|
|
|
|
Token::SeqSep,
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::SeqStart(Some(2)),
|
2015-05-16 06:32:58 -05:00
|
|
|
Token::SeqSep,
|
|
|
|
Token::I32(2),
|
|
|
|
|
|
|
|
Token::SeqSep,
|
|
|
|
Token::I32(3),
|
|
|
|
Token::SeqEnd,
|
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
|
|
|
[0; 0] => vec![
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::UnitStruct("Anything"),
|
2015-05-16 06:32:58 -05:00
|
|
|
],
|
|
|
|
[0; 0] => vec![
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::TupleStructStart("Anything", Some(0)),
|
2015-05-16 06:32:58 -05:00
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
|
|
|
}
|
2015-03-03 23:19:55 -06:00
|
|
|
test_tuple {
|
|
|
|
(1,) => vec![
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::SeqStart(Some(1)),
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::SeqSep,
|
2015-03-03 23:19:55 -06:00
|
|
|
Token::I32(1),
|
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
|
|
|
(1, 2, 3) => vec![
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::SeqStart(Some(3)),
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::SeqSep,
|
2015-03-03 23:19:55 -06:00
|
|
|
Token::I32(1),
|
|
|
|
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::SeqSep,
|
2015-03-03 23:19:55 -06:00
|
|
|
Token::I32(2),
|
|
|
|
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::SeqSep,
|
2015-03-03 23:19:55 -06:00
|
|
|
Token::I32(3),
|
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
|
|
|
}
|
|
|
|
test_btreemap {
|
2015-03-20 10:47:33 -05:00
|
|
|
BTreeMap::<isize, isize>::new() => vec![
|
|
|
|
Token::Unit,
|
|
|
|
],
|
|
|
|
BTreeMap::<isize, isize>::new() => vec![
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::MapStart(Some(0)),
|
2015-03-20 10:47:33 -05:00
|
|
|
Token::MapEnd,
|
|
|
|
],
|
2015-03-03 23:19:55 -06:00
|
|
|
btreemap![1 => 2] => vec![
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::MapStart(Some(1)),
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::MapSep,
|
2015-03-03 23:19:55 -06:00
|
|
|
Token::I32(1),
|
|
|
|
Token::I32(2),
|
|
|
|
Token::MapEnd,
|
|
|
|
],
|
|
|
|
btreemap![1 => 2, 3 => 4] => vec![
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::MapStart(Some(2)),
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::MapSep,
|
2015-03-03 23:19:55 -06:00
|
|
|
Token::I32(1),
|
|
|
|
Token::I32(2),
|
|
|
|
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::MapSep,
|
2015-03-03 23:19:55 -06:00
|
|
|
Token::I32(3),
|
|
|
|
Token::I32(4),
|
|
|
|
Token::MapEnd,
|
|
|
|
],
|
|
|
|
btreemap![1 => btreemap![], 2 => btreemap![3 => 4, 5 => 6]] => vec![
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::MapStart(Some(2)),
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::MapSep,
|
2015-03-03 23:19:55 -06:00
|
|
|
Token::I32(1),
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::MapStart(Some(0)),
|
2015-03-03 23:19:55 -06:00
|
|
|
Token::MapEnd,
|
|
|
|
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::MapSep,
|
2015-03-03 23:19:55 -06:00
|
|
|
Token::I32(2),
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::MapStart(Some(2)),
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::MapSep,
|
2015-03-03 23:19:55 -06:00
|
|
|
Token::I32(3),
|
|
|
|
Token::I32(4),
|
|
|
|
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::MapSep,
|
2015-03-03 23:19:55 -06:00
|
|
|
Token::I32(5),
|
|
|
|
Token::I32(6),
|
|
|
|
Token::MapEnd,
|
|
|
|
Token::MapEnd,
|
|
|
|
],
|
2015-03-20 10:47:33 -05:00
|
|
|
BTreeMap::<isize, isize>::new() => vec![
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::UnitStruct("Anything"),
|
2015-03-20 10:47:33 -05:00
|
|
|
],
|
|
|
|
BTreeMap::<isize, isize>::new() => vec![
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::StructStart("Anything", Some(0)),
|
2015-03-20 10:47:33 -05:00
|
|
|
Token::MapEnd,
|
|
|
|
],
|
2015-03-03 23:19:55 -06:00
|
|
|
}
|
2015-03-20 22:35:01 -05:00
|
|
|
test_hashmap {
|
|
|
|
HashMap::<isize, isize>::new() => vec![
|
|
|
|
Token::Unit,
|
|
|
|
],
|
|
|
|
HashMap::<isize, isize>::new() => vec![
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::MapStart(Some(0)),
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::MapEnd,
|
|
|
|
],
|
|
|
|
hashmap![1 => 2] => vec![
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::MapStart(Some(1)),
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::MapSep,
|
|
|
|
Token::I32(1),
|
|
|
|
Token::I32(2),
|
|
|
|
Token::MapEnd,
|
|
|
|
],
|
|
|
|
hashmap![1 => 2, 3 => 4] => vec![
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::MapStart(Some(2)),
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::MapSep,
|
|
|
|
Token::I32(1),
|
|
|
|
Token::I32(2),
|
|
|
|
|
|
|
|
Token::MapSep,
|
|
|
|
Token::I32(3),
|
|
|
|
Token::I32(4),
|
|
|
|
Token::MapEnd,
|
|
|
|
],
|
|
|
|
hashmap![1 => hashmap![], 2 => hashmap![3 => 4, 5 => 6]] => vec![
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::MapStart(Some(2)),
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::MapSep,
|
|
|
|
Token::I32(1),
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::MapStart(Some(0)),
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::MapEnd,
|
|
|
|
|
|
|
|
Token::MapSep,
|
|
|
|
Token::I32(2),
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::MapStart(Some(2)),
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::MapSep,
|
|
|
|
Token::I32(3),
|
|
|
|
Token::I32(4),
|
|
|
|
|
|
|
|
Token::MapSep,
|
|
|
|
Token::I32(5),
|
|
|
|
Token::I32(6),
|
|
|
|
Token::MapEnd,
|
|
|
|
Token::MapEnd,
|
|
|
|
],
|
|
|
|
HashMap::<isize, isize>::new() => vec![
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::UnitStruct("Anything"),
|
2015-03-20 22:35:01 -05:00
|
|
|
],
|
|
|
|
HashMap::<isize, isize>::new() => vec![
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::StructStart("Anything", Some(0)),
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::MapEnd,
|
|
|
|
],
|
|
|
|
}
|
2015-07-04 14:11:20 -05:00
|
|
|
test_struct {
|
|
|
|
Struct { a: 1, b: 2, c: 3 } => vec![
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::MapStart(Some(3)),
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::MapSep,
|
2015-03-03 23:19:55 -06:00
|
|
|
Token::Str("a"),
|
|
|
|
Token::I32(1),
|
|
|
|
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::MapSep,
|
2015-03-03 23:19:55 -06:00
|
|
|
Token::Str("b"),
|
|
|
|
Token::I32(2),
|
|
|
|
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::MapSep,
|
2015-03-03 23:19:55 -06:00
|
|
|
Token::Str("c"),
|
|
|
|
Token::I32(3),
|
|
|
|
Token::MapEnd,
|
|
|
|
],
|
2015-07-04 14:11:20 -05:00
|
|
|
Struct { a: 1, b: 2, c: 3 } => vec![
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::StructStart("Struct", Some(3)),
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::MapSep,
|
2015-03-03 23:19:55 -06:00
|
|
|
Token::Str("a"),
|
|
|
|
Token::I32(1),
|
|
|
|
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::MapSep,
|
2015-03-03 23:19:55 -06:00
|
|
|
Token::Str("b"),
|
|
|
|
Token::I32(2),
|
|
|
|
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::MapSep,
|
2015-03-03 23:19:55 -06:00
|
|
|
Token::Str("c"),
|
|
|
|
Token::I32(3),
|
|
|
|
Token::MapEnd,
|
|
|
|
],
|
|
|
|
}
|
2015-03-16 00:04:17 -05:00
|
|
|
test_enum_unit {
|
2015-03-03 23:19:55 -06:00
|
|
|
Enum::Unit => vec![
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::EnumUnit("Enum", "Unit"),
|
2015-03-03 23:19:55 -06:00
|
|
|
],
|
|
|
|
}
|
2015-07-30 09:54:55 -05:00
|
|
|
test_enum_simple {
|
|
|
|
Enum::Simple(1) => vec![
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::EnumNewtype("Enum", "Simple"),
|
|
|
|
Token::I32(1),
|
2015-07-30 09:54:55 -05:00
|
|
|
],
|
|
|
|
}
|
2015-03-03 23:19:55 -06:00
|
|
|
test_enum_seq {
|
|
|
|
Enum::Seq(1, 2, 3) => vec![
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::EnumSeqStart("Enum", "Seq", Some(3)),
|
|
|
|
Token::SeqSep,
|
|
|
|
Token::I32(1),
|
2015-03-03 23:19:55 -06:00
|
|
|
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::SeqSep,
|
|
|
|
Token::I32(2),
|
2015-03-03 23:19:55 -06:00
|
|
|
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::SeqSep,
|
|
|
|
Token::I32(3),
|
|
|
|
Token::SeqEnd,
|
2015-03-03 23:19:55 -06:00
|
|
|
],
|
|
|
|
}
|
|
|
|
test_enum_map {
|
|
|
|
Enum::Map { a: 1, b: 2, c: 3 } => vec![
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::EnumMapStart("Enum", "Map", Some(3)),
|
|
|
|
Token::MapSep,
|
|
|
|
Token::Str("a"),
|
|
|
|
Token::I32(1),
|
2015-03-03 23:19:55 -06:00
|
|
|
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::MapSep,
|
|
|
|
Token::Str("b"),
|
|
|
|
Token::I32(2),
|
2015-03-03 23:19:55 -06:00
|
|
|
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::MapSep,
|
|
|
|
Token::Str("c"),
|
|
|
|
Token::I32(3),
|
|
|
|
Token::MapEnd,
|
2015-03-03 23:19:55 -06:00
|
|
|
],
|
|
|
|
}
|
2015-07-30 10:05:41 -05:00
|
|
|
test_enum_unit_usize {
|
|
|
|
Enum::Unit => vec![
|
|
|
|
Token::EnumStart("Enum"),
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::Usize(0),
|
|
|
|
Token::Unit,
|
2015-07-30 10:05:41 -05:00
|
|
|
],
|
|
|
|
}
|
|
|
|
test_enum_unit_bytes {
|
|
|
|
Enum::Unit => vec![
|
|
|
|
Token::EnumStart("Enum"),
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::Bytes(b"Unit"),
|
|
|
|
Token::Unit,
|
2015-07-30 10:05:41 -05:00
|
|
|
],
|
|
|
|
}
|
2015-12-01 11:03:08 -06:00
|
|
|
test_num_bigint {
|
|
|
|
BigInt::from_i64(123).unwrap() => vec![Token::Str("123")],
|
|
|
|
BigInt::from_i64(-123).unwrap() => vec![Token::Str("-123")],
|
|
|
|
}
|
|
|
|
test_num_biguint {
|
|
|
|
BigUint::from_i64(123).unwrap() => vec![Token::Str("123")],
|
|
|
|
}
|
|
|
|
test_num_complex {
|
|
|
|
Complex::new(1, 2) => vec![
|
|
|
|
Token::SeqStart(Some(2)),
|
|
|
|
Token::SeqSep,
|
|
|
|
Token::I32(1),
|
|
|
|
|
|
|
|
Token::SeqSep,
|
|
|
|
Token::I32(2),
|
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
|
|
|
}
|
|
|
|
test_num_ratio {
|
|
|
|
Ratio::new(1, 2) => vec![
|
|
|
|
Token::SeqStart(Some(2)),
|
|
|
|
Token::SeqSep,
|
|
|
|
Token::I32(1),
|
|
|
|
|
|
|
|
Token::SeqSep,
|
|
|
|
Token::I32(2),
|
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
|
|
|
}
|
2015-03-03 23:19:55 -06:00
|
|
|
}
|