2015-03-20 22:35:01 -05:00
|
|
|
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
|
2016-02-21 19:02:25 -06:00
|
|
|
use std::net;
|
2016-01-28 11:45:38 -06:00
|
|
|
use std::path::PathBuf;
|
2016-08-03 19:15:14 -05:00
|
|
|
use std::time::Duration;
|
2015-03-20 10:32:33 -05:00
|
|
|
|
2016-07-21 03:11:04 -05:00
|
|
|
use serde::Deserialize;
|
2016-06-28 23:47:54 -05:00
|
|
|
|
2016-06-11 02:43:02 -05:00
|
|
|
extern crate fnv;
|
|
|
|
use self::fnv::FnvHasher;
|
|
|
|
|
2016-06-28 23:47:54 -05:00
|
|
|
extern crate serde_test;
|
|
|
|
use self::serde_test::{
|
2016-02-21 18:26:52 -06:00
|
|
|
Error,
|
|
|
|
Token,
|
|
|
|
assert_de_tokens,
|
|
|
|
assert_de_tokens_error,
|
|
|
|
};
|
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,
|
2016-03-07 01:27:12 -06:00
|
|
|
#[serde(skip_deserializing)]
|
2015-03-03 23:19:55 -06:00
|
|
|
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() {
|
|
|
|
$(
|
2016-01-10 21:34:48 -06:00
|
|
|
// Test ser/de roundtripping
|
2015-08-27 22:01:09 -05:00
|
|
|
assert_de_tokens(&$value, $tokens);
|
2016-01-10 21:34:48 -06:00
|
|
|
|
|
|
|
// Test that the tokens are ignorable
|
|
|
|
assert_de_tokens_ignore($tokens);
|
2015-03-03 23:19:55 -06:00
|
|
|
)+
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! declare_tests {
|
|
|
|
($($name:ident { $($value:expr => $tokens:expr,)+ })+) => {
|
|
|
|
$(
|
|
|
|
declare_test!($name { $($value => $tokens,)+ });
|
|
|
|
)+
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-07 01:27:12 -06:00
|
|
|
macro_rules! declare_error_tests {
|
|
|
|
($($name:ident<$target:ident> { $tokens:expr, $expected:expr, })+) => {
|
|
|
|
$(
|
|
|
|
#[test]
|
|
|
|
fn $name() {
|
|
|
|
assert_de_tokens_error::<$target>($tokens, $expected);
|
|
|
|
}
|
|
|
|
)+
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-29 01:50:19 -05:00
|
|
|
fn assert_de_tokens_ignore(ignorable_tokens: &[Token<'static>]) {
|
2016-06-28 23:47:54 -05:00
|
|
|
#[derive(PartialEq, Debug, Deserialize)]
|
|
|
|
struct IgnoreBase {
|
|
|
|
a: i32,
|
|
|
|
}
|
2016-07-12 08:44:19 -05:00
|
|
|
|
2016-06-28 23:47:54 -05:00
|
|
|
let expected = IgnoreBase{a: 1};
|
2016-07-12 08:44:19 -05:00
|
|
|
|
2016-06-28 23:47:54 -05:00
|
|
|
// Embed the tokens to be ignored in the normal token
|
|
|
|
// stream for an IgnoreBase type
|
|
|
|
let concated_tokens : Vec<Token<'static>> = vec![
|
|
|
|
Token::MapStart(Some(2)),
|
|
|
|
Token::MapSep,
|
|
|
|
Token::Str("a"),
|
|
|
|
Token::I32(1),
|
2016-07-12 08:44:19 -05:00
|
|
|
|
2016-06-28 23:47:54 -05:00
|
|
|
Token::MapSep,
|
|
|
|
Token::Str("ignored")
|
|
|
|
]
|
|
|
|
.into_iter()
|
2016-06-29 01:50:19 -05:00
|
|
|
.chain(ignorable_tokens.to_vec().into_iter())
|
2016-06-28 23:47:54 -05:00
|
|
|
.chain(vec![
|
|
|
|
Token::MapEnd,
|
|
|
|
].into_iter())
|
|
|
|
.collect();
|
2016-07-12 08:44:19 -05:00
|
|
|
|
2016-06-28 23:47:54 -05:00
|
|
|
let mut de = serde_test::Deserializer::new(concated_tokens.into_iter());
|
|
|
|
let v: Result<IgnoreBase, Error> = Deserialize::deserialize(&mut de);
|
2016-07-12 08:44:19 -05:00
|
|
|
|
2016-06-28 23:47:54 -05:00
|
|
|
// We run this test on every token stream for convenience, but
|
|
|
|
// some token streams don't make sense embedded as a map value,
|
|
|
|
// so we ignore those. SyntaxError is the real sign of trouble.
|
|
|
|
if let Err(Error::UnexpectedToken(_)) = v {
|
|
|
|
return;
|
|
|
|
}
|
2016-07-12 08:44:19 -05:00
|
|
|
|
2016-06-28 23:47:54 -05:00
|
|
|
assert_eq!(v.as_ref(), Ok(&expected));
|
|
|
|
assert_eq!(de.next_token(), None);
|
|
|
|
}
|
|
|
|
|
2015-03-03 23:19:55 -06:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
declare_tests! {
|
|
|
|
test_bool {
|
2016-06-29 01:50:19 -05:00
|
|
|
true => &[Token::Bool(true)],
|
|
|
|
false => &[Token::Bool(false)],
|
2015-03-03 23:19:55 -06:00
|
|
|
}
|
|
|
|
test_isize {
|
2016-06-29 01:50:19 -05:00
|
|
|
0isize => &[Token::Isize(0)],
|
|
|
|
0isize => &[Token::I8(0)],
|
|
|
|
0isize => &[Token::I16(0)],
|
|
|
|
0isize => &[Token::I32(0)],
|
|
|
|
0isize => &[Token::I64(0)],
|
|
|
|
0isize => &[Token::Usize(0)],
|
|
|
|
0isize => &[Token::U8(0)],
|
|
|
|
0isize => &[Token::U16(0)],
|
|
|
|
0isize => &[Token::U32(0)],
|
|
|
|
0isize => &[Token::U64(0)],
|
|
|
|
0isize => &[Token::F32(0.)],
|
|
|
|
0isize => &[Token::F64(0.)],
|
2015-03-03 23:19:55 -06:00
|
|
|
}
|
|
|
|
test_ints {
|
2016-06-29 01:50:19 -05:00
|
|
|
0isize => &[Token::Isize(0)],
|
|
|
|
0i8 => &[Token::I8(0)],
|
|
|
|
0i16 => &[Token::I16(0)],
|
|
|
|
0i32 => &[Token::I32(0)],
|
|
|
|
0i64 => &[Token::I64(0)],
|
2015-03-03 23:19:55 -06:00
|
|
|
}
|
|
|
|
test_uints {
|
2016-06-29 01:50:19 -05:00
|
|
|
0usize => &[Token::Usize(0)],
|
|
|
|
0u8 => &[Token::U8(0)],
|
|
|
|
0u16 => &[Token::U16(0)],
|
|
|
|
0u32 => &[Token::U32(0)],
|
|
|
|
0u64 => &[Token::U64(0)],
|
2015-03-03 23:19:55 -06:00
|
|
|
}
|
|
|
|
test_floats {
|
2016-06-29 01:50:19 -05:00
|
|
|
0f32 => &[Token::F32(0.)],
|
|
|
|
0f64 => &[Token::F64(0.)],
|
2015-03-03 23:19:55 -06:00
|
|
|
}
|
|
|
|
test_char {
|
2016-06-29 01:50:19 -05:00
|
|
|
'a' => &[Token::Char('a')],
|
|
|
|
'a' => &[Token::Str("a")],
|
|
|
|
'a' => &[Token::String("a".to_owned())],
|
2015-03-03 23:19:55 -06:00
|
|
|
}
|
|
|
|
test_string {
|
2016-06-29 01:50:19 -05:00
|
|
|
"abc".to_owned() => &[Token::Str("abc")],
|
|
|
|
"abc".to_owned() => &[Token::String("abc".to_owned())],
|
|
|
|
"a".to_owned() => &[Token::Char('a')],
|
2015-03-03 23:19:55 -06:00
|
|
|
}
|
|
|
|
test_option {
|
2016-06-29 01:50:19 -05:00
|
|
|
None::<i32> => &[Token::Unit],
|
|
|
|
None::<i32> => &[Token::Option(false)],
|
|
|
|
Some(1) => &[Token::I32(1)],
|
|
|
|
Some(1) => &[
|
2015-03-03 23:19:55 -06:00
|
|
|
Token::Option(true),
|
|
|
|
Token::I32(1),
|
|
|
|
],
|
|
|
|
}
|
2015-07-19 13:16:46 -05:00
|
|
|
test_result {
|
2016-06-29 01:50:19 -05:00
|
|
|
Ok::<i32, i32>(0) => &[
|
2015-07-19 13:16:46 -05:00
|
|
|
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
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
Err::<i32, i32>(1) => &[
|
2015-07-19 13:16:46 -05:00
|
|
|
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 {
|
2016-06-29 01:50:19 -05:00
|
|
|
() => &[Token::Unit],
|
|
|
|
() => &[
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::SeqStart(Some(0)),
|
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
() => &[
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::SeqStart(None),
|
2015-03-03 23:19:55 -06:00
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
() => &[
|
2016-07-12 08:44:19 -05:00
|
|
|
Token::TupleStructStart("Anything", 0),
|
2015-03-03 23:19:55 -06:00
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
|
|
|
}
|
2015-07-04 14:11:20 -05:00
|
|
|
test_unit_struct {
|
2016-06-29 01:50:19 -05:00
|
|
|
UnitStruct => &[Token::Unit],
|
|
|
|
UnitStruct => &[
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::UnitStruct("UnitStruct"),
|
2015-03-20 10:32:33 -05:00
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
UnitStruct => &[
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::SeqStart(Some(0)),
|
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
UnitStruct => &[
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::SeqStart(None),
|
2015-03-03 23:19:55 -06:00
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
|
|
|
}
|
2016-12-01 06:46:24 -06:00
|
|
|
test_unit_string {
|
|
|
|
String::new() => &[Token::Unit],
|
|
|
|
}
|
2015-07-04 14:11:20 -05:00
|
|
|
test_tuple_struct {
|
2016-06-29 01:50:19 -05:00
|
|
|
TupleStruct(1, 2, 3) => &[
|
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,
|
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
TupleStruct(1, 2, 3) => &[
|
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,
|
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
TupleStruct(1, 2, 3) => &[
|
2016-07-12 08:44:19 -05:00
|
|
|
Token::TupleStructStart("TupleStruct", 3),
|
2016-02-23 07:15:44 -06:00
|
|
|
Token::TupleStructSep,
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::I32(1),
|
|
|
|
|
2016-02-23 07:15:44 -06:00
|
|
|
Token::TupleStructSep,
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::I32(2),
|
|
|
|
|
2016-02-23 07:15:44 -06:00
|
|
|
Token::TupleStructSep,
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::I32(3),
|
2016-02-23 07:15:44 -06:00
|
|
|
Token::TupleStructEnd,
|
2015-08-27 22:01:09 -05:00
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
TupleStruct(1, 2, 3) => &[
|
2016-07-12 08:44:19 -05:00
|
|
|
Token::TupleStructStart("TupleStruct", 3),
|
2016-02-23 07:15:44 -06:00
|
|
|
Token::TupleStructSep,
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::I32(1),
|
|
|
|
|
2016-02-23 07:15:44 -06:00
|
|
|
Token::TupleStructSep,
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::I32(2),
|
|
|
|
|
2016-02-23 07:15:44 -06:00
|
|
|
Token::TupleStructSep,
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::I32(3),
|
2016-02-23 07:15:44 -06:00
|
|
|
Token::TupleStructEnd,
|
2015-03-20 22:35:01 -05:00
|
|
|
],
|
|
|
|
}
|
|
|
|
test_btreeset {
|
2016-06-29 01:50:19 -05:00
|
|
|
BTreeSet::<isize>::new() => &[
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::Unit,
|
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
BTreeSet::<isize>::new() => &[
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::SeqStart(Some(0)),
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
btreeset![btreeset![], btreeset![1], btreeset![2, 3]] => &[
|
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,
|
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
BTreeSet::<isize>::new() => &[
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::UnitStruct("Anything"),
|
2015-03-20 22:35:01 -05:00
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
BTreeSet::<isize>::new() => &[
|
2016-07-12 08:44:19 -05:00
|
|
|
Token::TupleStructStart("Anything", 0),
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
|
|
|
}
|
|
|
|
test_hashset {
|
2016-06-29 01:50:19 -05:00
|
|
|
HashSet::<isize>::new() => &[
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::Unit,
|
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
HashSet::<isize>::new() => &[
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::SeqStart(Some(0)),
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
hashset![1, 2, 3] => &[
|
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,
|
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
HashSet::<isize>::new() => &[
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::UnitStruct("Anything"),
|
2015-03-20 22:35:01 -05:00
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
HashSet::<isize>::new() => &[
|
2016-07-12 08:44:19 -05:00
|
|
|
Token::TupleStructStart("Anything", 0),
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::SeqEnd,
|
2016-06-11 11:59:29 -05:00
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
hashset![FnvHasher @ 1, 2, 3] => &[
|
2016-06-11 11:59:29 -05:00
|
|
|
Token::SeqStart(Some(3)),
|
|
|
|
Token::SeqSep,
|
|
|
|
Token::I32(1),
|
|
|
|
|
|
|
|
Token::SeqSep,
|
|
|
|
Token::I32(2),
|
|
|
|
|
|
|
|
Token::SeqSep,
|
|
|
|
Token::I32(3),
|
|
|
|
Token::SeqEnd,
|
2015-03-20 22:35:01 -05:00
|
|
|
],
|
2015-03-03 23:19:55 -06:00
|
|
|
}
|
|
|
|
test_vec {
|
2016-06-29 01:50:19 -05:00
|
|
|
Vec::<isize>::new() => &[
|
2015-03-20 10:47:33 -05:00
|
|
|
Token::Unit,
|
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
Vec::<isize>::new() => &[
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::SeqStart(Some(0)),
|
2015-03-03 23:19:55 -06:00
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
vec![vec![], vec![1], vec![2, 3]] => &[
|
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,
|
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
Vec::<isize>::new() => &[
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::UnitStruct("Anything"),
|
2015-03-20 10:47:33 -05:00
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
Vec::<isize>::new() => &[
|
2016-07-12 08:44:19 -05:00
|
|
|
Token::TupleStructStart("Anything", 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 {
|
2016-06-29 01:50:19 -05:00
|
|
|
[0; 0] => &[
|
2015-05-16 06:32:58 -05:00
|
|
|
Token::Unit,
|
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
[0; 0] => &[
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::SeqStart(Some(0)),
|
2015-05-16 06:32:58 -05:00
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
[0; 0] => &[
|
2016-02-23 07:15:44 -06:00
|
|
|
Token::SeqArrayStart(0),
|
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
([0; 0], [1], [2, 3]) => &[
|
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,
|
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
([0; 0], [1], [2, 3]) => &[
|
2016-02-23 07:15:44 -06:00
|
|
|
Token::SeqArrayStart(3),
|
|
|
|
Token::SeqSep,
|
|
|
|
Token::SeqArrayStart(0),
|
|
|
|
Token::SeqEnd,
|
|
|
|
|
|
|
|
Token::SeqSep,
|
|
|
|
Token::SeqArrayStart(1),
|
|
|
|
Token::SeqSep,
|
|
|
|
Token::I32(1),
|
|
|
|
Token::SeqEnd,
|
|
|
|
|
|
|
|
Token::SeqSep,
|
|
|
|
Token::SeqArrayStart(2),
|
|
|
|
Token::SeqSep,
|
|
|
|
Token::I32(2),
|
|
|
|
|
|
|
|
Token::SeqSep,
|
|
|
|
Token::I32(3),
|
|
|
|
Token::SeqEnd,
|
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
[0; 0] => &[
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::UnitStruct("Anything"),
|
2015-05-16 06:32:58 -05:00
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
[0; 0] => &[
|
2016-07-12 08:44:19 -05:00
|
|
|
Token::TupleStructStart("Anything", 0),
|
2015-05-16 06:32:58 -05:00
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
|
|
|
}
|
2015-03-03 23:19:55 -06:00
|
|
|
test_tuple {
|
2016-06-29 01:50:19 -05:00
|
|
|
(1,) => &[
|
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,
|
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
(1, 2, 3) => &[
|
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,
|
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
(1,) => &[
|
2016-02-23 07:15:44 -06:00
|
|
|
Token::TupleStart(1),
|
|
|
|
Token::TupleSep,
|
|
|
|
Token::I32(1),
|
|
|
|
Token::TupleEnd,
|
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
(1, 2, 3) => &[
|
2016-02-23 07:15:44 -06:00
|
|
|
Token::TupleStart(3),
|
|
|
|
Token::TupleSep,
|
|
|
|
Token::I32(1),
|
|
|
|
|
|
|
|
Token::TupleSep,
|
|
|
|
Token::I32(2),
|
|
|
|
|
|
|
|
Token::TupleSep,
|
|
|
|
Token::I32(3),
|
|
|
|
Token::TupleEnd,
|
|
|
|
],
|
2015-03-03 23:19:55 -06:00
|
|
|
}
|
|
|
|
test_btreemap {
|
2016-06-29 01:50:19 -05:00
|
|
|
BTreeMap::<isize, isize>::new() => &[
|
2015-03-20 10:47:33 -05:00
|
|
|
Token::Unit,
|
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
BTreeMap::<isize, isize>::new() => &[
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::MapStart(Some(0)),
|
2015-03-20 10:47:33 -05:00
|
|
|
Token::MapEnd,
|
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
btreemap![1 => 2] => &[
|
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,
|
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
btreemap![1 => 2, 3 => 4] => &[
|
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,
|
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
btreemap![1 => btreemap![], 2 => btreemap![3 => 4, 5 => 6]] => &[
|
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,
|
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
BTreeMap::<isize, isize>::new() => &[
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::UnitStruct("Anything"),
|
2015-03-20 10:47:33 -05:00
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
BTreeMap::<isize, isize>::new() => &[
|
2016-07-12 08:44:19 -05:00
|
|
|
Token::StructStart("Anything", 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 {
|
2016-06-29 01:50:19 -05:00
|
|
|
HashMap::<isize, isize>::new() => &[
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::Unit,
|
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
HashMap::<isize, isize>::new() => &[
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::MapStart(Some(0)),
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::MapEnd,
|
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
hashmap![1 => 2] => &[
|
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,
|
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
hashmap![1 => 2, 3 => 4] => &[
|
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,
|
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
hashmap![1 => hashmap![], 2 => hashmap![3 => 4, 5 => 6]] => &[
|
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,
|
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
HashMap::<isize, isize>::new() => &[
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::UnitStruct("Anything"),
|
2015-03-20 22:35:01 -05:00
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
HashMap::<isize, isize>::new() => &[
|
2016-07-12 08:44:19 -05:00
|
|
|
Token::StructStart("Anything", 0),
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::MapEnd,
|
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
hashmap![FnvHasher @ 1 => 2, 3 => 4] => &[
|
2016-06-11 02:43:02 -05:00
|
|
|
Token::MapStart(Some(2)),
|
|
|
|
Token::MapSep,
|
|
|
|
Token::I32(1),
|
|
|
|
Token::I32(2),
|
|
|
|
|
|
|
|
Token::MapSep,
|
|
|
|
Token::I32(3),
|
|
|
|
Token::I32(4),
|
|
|
|
Token::MapEnd,
|
|
|
|
],
|
2015-03-20 22:35:01 -05:00
|
|
|
}
|
2015-07-04 14:11:20 -05:00
|
|
|
test_struct {
|
2016-06-29 01:50:19 -05:00
|
|
|
Struct { a: 1, b: 2, c: 0 } => &[
|
2016-03-07 01:27:12 -06:00
|
|
|
Token::MapStart(Some(3)),
|
|
|
|
Token::MapSep,
|
|
|
|
Token::Str("a"),
|
|
|
|
Token::I32(1),
|
|
|
|
|
|
|
|
Token::MapSep,
|
|
|
|
Token::Str("b"),
|
|
|
|
Token::I32(2),
|
|
|
|
Token::MapEnd,
|
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
Struct { a: 1, b: 2, c: 0 } => &[
|
2016-07-12 08:44:19 -05:00
|
|
|
Token::StructStart("Struct", 3),
|
2016-03-07 01:27:12 -06:00
|
|
|
Token::StructSep,
|
|
|
|
Token::Str("a"),
|
|
|
|
Token::I32(1),
|
|
|
|
|
|
|
|
Token::StructSep,
|
|
|
|
Token::Str("b"),
|
|
|
|
Token::I32(2),
|
|
|
|
Token::StructEnd,
|
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
Struct { a: 1, b: 2, c: 0 } => &[
|
2016-03-07 01:27:12 -06:00
|
|
|
Token::SeqStart(Some(3)),
|
|
|
|
Token::SeqSep,
|
|
|
|
Token::I32(1),
|
|
|
|
|
|
|
|
Token::SeqSep,
|
|
|
|
Token::I32(2),
|
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
|
|
|
}
|
|
|
|
test_struct_with_skip {
|
2016-06-29 01:50:19 -05:00
|
|
|
Struct { a: 1, b: 2, c: 0 } => &[
|
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),
|
2016-03-07 01:27:12 -06:00
|
|
|
|
|
|
|
Token::MapSep,
|
|
|
|
Token::Str("d"),
|
|
|
|
Token::I32(4),
|
2015-03-03 23:19:55 -06:00
|
|
|
Token::MapEnd,
|
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
Struct { a: 1, b: 2, c: 0 } => &[
|
2016-07-12 08:44:19 -05:00
|
|
|
Token::StructStart("Struct", 3),
|
2016-02-13 00:05:02 -06:00
|
|
|
Token::StructSep,
|
2015-03-03 23:19:55 -06:00
|
|
|
Token::Str("a"),
|
|
|
|
Token::I32(1),
|
|
|
|
|
2016-02-13 00:05:02 -06:00
|
|
|
Token::StructSep,
|
2015-03-03 23:19:55 -06:00
|
|
|
Token::Str("b"),
|
|
|
|
Token::I32(2),
|
|
|
|
|
2016-02-13 00:05:02 -06:00
|
|
|
Token::StructSep,
|
2015-03-03 23:19:55 -06:00
|
|
|
Token::Str("c"),
|
|
|
|
Token::I32(3),
|
2016-03-07 01:27:12 -06:00
|
|
|
|
|
|
|
Token::StructSep,
|
|
|
|
Token::Str("d"),
|
|
|
|
Token::I32(4),
|
2016-02-13 00:05:02 -06:00
|
|
|
Token::StructEnd,
|
2015-03-03 23:19:55 -06:00
|
|
|
],
|
|
|
|
}
|
2015-03-16 00:04:17 -05:00
|
|
|
test_enum_unit {
|
2016-06-29 01:50:19 -05:00
|
|
|
Enum::Unit => &[
|
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 {
|
2016-06-29 01:50:19 -05:00
|
|
|
Enum::Simple(1) => &[
|
2016-02-13 00:05:02 -06:00
|
|
|
Token::EnumNewType("Enum", "Simple"),
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::I32(1),
|
2015-07-30 09:54:55 -05:00
|
|
|
],
|
|
|
|
}
|
2015-03-03 23:19:55 -06:00
|
|
|
test_enum_seq {
|
2016-06-29 01:50:19 -05:00
|
|
|
Enum::Seq(1, 2, 3) => &[
|
2016-07-12 08:44:19 -05:00
|
|
|
Token::EnumSeqStart("Enum", "Seq", 3),
|
2016-02-13 00:05:02 -06:00
|
|
|
Token::EnumSeqSep,
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::I32(1),
|
2015-03-03 23:19:55 -06:00
|
|
|
|
2016-02-13 00:05:02 -06:00
|
|
|
Token::EnumSeqSep,
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::I32(2),
|
2015-03-03 23:19:55 -06:00
|
|
|
|
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::EnumSeqEnd,
|
2015-03-03 23:19:55 -06:00
|
|
|
],
|
|
|
|
}
|
|
|
|
test_enum_map {
|
2016-06-29 01:50:19 -05:00
|
|
|
Enum::Map { a: 1, b: 2, c: 3 } => &[
|
2016-07-12 08:44:19 -05:00
|
|
|
Token::EnumMapStart("Enum", "Map", 3),
|
2016-02-13 00:05:02 -06:00
|
|
|
Token::EnumMapSep,
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::Str("a"),
|
|
|
|
Token::I32(1),
|
2015-03-03 23:19:55 -06:00
|
|
|
|
2016-02-13 00:05:02 -06:00
|
|
|
Token::EnumMapSep,
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::Str("b"),
|
|
|
|
Token::I32(2),
|
2015-03-03 23:19:55 -06:00
|
|
|
|
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::EnumMapEnd,
|
2015-03-03 23:19:55 -06:00
|
|
|
],
|
|
|
|
}
|
2015-07-30 10:05:41 -05:00
|
|
|
test_enum_unit_usize {
|
2016-06-29 01:50:19 -05:00
|
|
|
Enum::Unit => &[
|
2015-07-30 10:05:41 -05:00
|
|
|
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 {
|
2016-06-29 01:50:19 -05:00
|
|
|
Enum::Unit => &[
|
2015-07-30 10:05:41 -05:00
|
|
|
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
|
|
|
],
|
|
|
|
}
|
2016-04-17 22:59:26 -05:00
|
|
|
test_box {
|
2016-06-29 01:50:19 -05:00
|
|
|
Box::new(0i32) => &[Token::I32(0)],
|
2016-04-17 22:59:26 -05:00
|
|
|
}
|
|
|
|
test_boxed_slice {
|
2016-06-29 01:50:19 -05:00
|
|
|
Box::new([0, 1, 2]) => &[
|
2016-04-17 22:59:26 -05:00
|
|
|
Token::SeqStart(Some(3)),
|
|
|
|
Token::SeqSep,
|
|
|
|
Token::I32(0),
|
|
|
|
Token::SeqSep,
|
|
|
|
Token::I32(1),
|
|
|
|
Token::SeqSep,
|
|
|
|
Token::I32(2),
|
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
|
|
|
}
|
2016-08-03 19:15:14 -05:00
|
|
|
test_duration {
|
|
|
|
Duration::new(1, 2) => &[
|
|
|
|
Token::StructStart("Duration", 2),
|
|
|
|
Token::StructSep,
|
|
|
|
Token::Str("secs"),
|
|
|
|
Token::U64(1),
|
|
|
|
|
|
|
|
Token::StructSep,
|
|
|
|
Token::Str("nanos"),
|
|
|
|
Token::U32(2),
|
|
|
|
Token::StructEnd,
|
|
|
|
],
|
|
|
|
Duration::new(1, 2) => &[
|
|
|
|
Token::SeqStart(Some(2)),
|
|
|
|
Token::SeqSep,
|
|
|
|
Token::I64(1),
|
|
|
|
|
|
|
|
Token::SeqSep,
|
|
|
|
Token::I64(2),
|
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
|
|
|
}
|
2016-02-21 19:02:25 -06:00
|
|
|
test_net_ipv4addr {
|
2016-06-29 01:50:19 -05:00
|
|
|
"1.2.3.4".parse::<net::Ipv4Addr>().unwrap() => &[Token::Str("1.2.3.4")],
|
2016-02-21 19:02:25 -06:00
|
|
|
}
|
|
|
|
test_net_ipv6addr {
|
2016-06-29 01:50:19 -05:00
|
|
|
"::1".parse::<net::Ipv6Addr>().unwrap() => &[Token::Str("::1")],
|
2016-02-21 19:02:25 -06:00
|
|
|
}
|
2016-02-21 21:07:13 -06:00
|
|
|
test_net_socketaddr {
|
2016-06-29 01:50:19 -05:00
|
|
|
"1.2.3.4:1234".parse::<net::SocketAddr>().unwrap() => &[Token::Str("1.2.3.4:1234")],
|
|
|
|
"1.2.3.4:1234".parse::<net::SocketAddrV4>().unwrap() => &[Token::Str("1.2.3.4:1234")],
|
|
|
|
"[::1]:1234".parse::<net::SocketAddrV6>().unwrap() => &[Token::Str("[::1]:1234")],
|
2016-02-21 21:07:13 -06:00
|
|
|
}
|
2016-01-28 11:45:38 -06:00
|
|
|
test_path_buf {
|
2016-06-29 01:50:19 -05:00
|
|
|
PathBuf::from("/usr/local/lib") => &[
|
2016-01-28 11:45:38 -06:00
|
|
|
Token::String("/usr/local/lib".to_owned()),
|
|
|
|
],
|
|
|
|
}
|
2015-03-03 23:19:55 -06:00
|
|
|
}
|
2016-02-21 18:26:52 -06:00
|
|
|
|
2016-07-17 15:17:23 -05:00
|
|
|
#[cfg(feature = "unstable")]
|
2016-02-21 19:02:25 -06:00
|
|
|
#[test]
|
|
|
|
fn test_net_ipaddr() {
|
|
|
|
assert_de_tokens(
|
|
|
|
"1.2.3.4".parse::<net::IpAddr>().unwrap(),
|
2016-06-29 01:50:19 -05:00
|
|
|
&[Token::Str("1.2.3.4")],
|
2016-02-21 19:02:25 -06:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-03-07 01:27:12 -06:00
|
|
|
declare_error_tests! {
|
|
|
|
test_unknown_variant<Enum> {
|
2016-06-29 01:50:19 -05:00
|
|
|
&[
|
2016-02-21 18:26:52 -06:00
|
|
|
Token::EnumUnit("Enum", "Foo"),
|
|
|
|
],
|
2016-06-29 00:49:13 -05:00
|
|
|
Error::UnknownVariant("Foo".to_owned()),
|
2016-03-07 01:27:12 -06:00
|
|
|
}
|
|
|
|
test_struct_seq_too_long<Struct> {
|
2016-06-29 01:50:19 -05:00
|
|
|
&[
|
2016-03-07 01:27:12 -06:00
|
|
|
Token::SeqStart(Some(4)),
|
|
|
|
Token::SeqSep, Token::I32(1),
|
|
|
|
Token::SeqSep, Token::I32(2),
|
|
|
|
Token::SeqSep, Token::I32(3),
|
|
|
|
],
|
|
|
|
Error::UnexpectedToken(Token::SeqSep),
|
|
|
|
}
|
2016-05-10 11:52:51 -05:00
|
|
|
test_duplicate_field_struct<Struct> {
|
2016-06-29 01:50:19 -05:00
|
|
|
&[
|
2016-05-10 11:52:51 -05:00
|
|
|
Token::MapStart(Some(3)),
|
|
|
|
Token::MapSep,
|
|
|
|
Token::Str("a"),
|
|
|
|
Token::I32(1),
|
|
|
|
|
|
|
|
Token::MapSep,
|
|
|
|
Token::Str("a"),
|
|
|
|
],
|
2016-06-29 00:49:13 -05:00
|
|
|
Error::DuplicateField("a"),
|
2016-05-10 11:52:51 -05:00
|
|
|
}
|
|
|
|
test_duplicate_field_enum<Enum> {
|
2016-06-29 01:50:19 -05:00
|
|
|
&[
|
2016-07-12 08:44:19 -05:00
|
|
|
Token::EnumMapStart("Enum", "Map", 3),
|
2016-05-10 11:52:51 -05:00
|
|
|
Token::EnumMapSep,
|
|
|
|
Token::Str("a"),
|
|
|
|
Token::I32(1),
|
|
|
|
|
|
|
|
Token::EnumMapSep,
|
|
|
|
Token::Str("a"),
|
|
|
|
],
|
2016-06-29 00:49:13 -05:00
|
|
|
Error::DuplicateField("a"),
|
2016-05-10 11:52:51 -05:00
|
|
|
}
|
2016-02-21 18:26:52 -06:00
|
|
|
}
|