2015-03-03 22:33:17 -06:00
|
|
|
use std::vec;
|
|
|
|
use std::collections::BTreeMap;
|
|
|
|
|
2015-03-11 13:05:46 -05:00
|
|
|
use serde::ser::{Serialize, Serializer, SeqVisitor, MapVisitor};
|
2015-03-03 22:33:17 -06:00
|
|
|
|
|
|
|
#[derive(Clone, PartialEq, Debug)]
|
|
|
|
pub enum Token<'a> {
|
|
|
|
Bool(bool),
|
|
|
|
Isize(isize),
|
|
|
|
I8(i8),
|
|
|
|
I16(i16),
|
|
|
|
I32(i32),
|
|
|
|
I64(i64),
|
|
|
|
Usize(usize),
|
|
|
|
U8(u8),
|
|
|
|
U16(u16),
|
|
|
|
U32(u32),
|
|
|
|
U64(u64),
|
|
|
|
F32(f32),
|
|
|
|
F64(f64),
|
|
|
|
Char(char),
|
|
|
|
Str(&'a str),
|
|
|
|
|
|
|
|
Option(bool),
|
|
|
|
|
|
|
|
Unit,
|
2015-07-04 14:11:20 -05:00
|
|
|
UnitStruct(&'a str),
|
2015-03-03 22:33:17 -06:00
|
|
|
EnumUnit(&'a str, &'a str),
|
|
|
|
|
2015-07-17 08:19:11 -05:00
|
|
|
EnumSimple(&'a str, &'a str),
|
|
|
|
|
2015-03-12 21:40:46 -05:00
|
|
|
SeqStart(Option<usize>),
|
2015-07-04 14:11:20 -05:00
|
|
|
TupleStructStart(&'a str, Option<usize>),
|
2015-03-12 21:40:46 -05:00
|
|
|
EnumSeqStart(&'a str, &'a str, Option<usize>),
|
2015-03-17 00:30:02 -05:00
|
|
|
SeqSep,
|
2015-03-03 22:33:17 -06:00
|
|
|
SeqEnd,
|
|
|
|
|
2015-03-12 21:40:46 -05:00
|
|
|
MapStart(Option<usize>),
|
2015-07-04 14:11:20 -05:00
|
|
|
StructStart(&'a str, Option<usize>),
|
2015-03-12 21:40:46 -05:00
|
|
|
EnumMapStart(&'a str, &'a str, Option<usize>),
|
2015-03-17 00:30:02 -05:00
|
|
|
MapSep,
|
2015-03-03 22:33:17 -06:00
|
|
|
MapEnd,
|
|
|
|
}
|
|
|
|
|
|
|
|
struct AssertSerializer<'a> {
|
|
|
|
iter: vec::IntoIter<Token<'a>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> AssertSerializer<'a> {
|
|
|
|
fn new(values: Vec<Token<'a>>) -> AssertSerializer {
|
|
|
|
AssertSerializer {
|
|
|
|
iter: values.into_iter(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn visit_sequence<V>(&mut self, mut visitor: V) -> Result<(), ()>
|
|
|
|
where V: SeqVisitor
|
|
|
|
{
|
|
|
|
while let Some(()) = try!(visitor.visit(self)) { }
|
|
|
|
|
|
|
|
assert_eq!(self.iter.next(), Some(Token::SeqEnd));
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn visit_mapping<V>(&mut self, mut visitor: V) -> Result<(), ()>
|
|
|
|
where V: MapVisitor
|
|
|
|
{
|
|
|
|
while let Some(()) = try!(visitor.visit(self)) { }
|
|
|
|
|
|
|
|
assert_eq!(self.iter.next(), Some(Token::MapEnd));
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> Serializer for AssertSerializer<'a> {
|
|
|
|
type Error = ();
|
|
|
|
|
|
|
|
fn visit_unit(&mut self) -> Result<(), ()> {
|
|
|
|
assert_eq!(self.iter.next(), Some(Token::Unit));
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2015-07-17 08:19:11 -05:00
|
|
|
fn visit_enum_simple<T>(&mut self,
|
|
|
|
name: &str,
|
|
|
|
variant: &str,
|
|
|
|
value: T,
|
|
|
|
) -> Result<(), ()>
|
|
|
|
where T: Serialize,
|
|
|
|
{
|
|
|
|
assert_eq!(self.iter.next(), Some(Token::EnumSimple(name, variant)));
|
|
|
|
value.serialize(self)
|
|
|
|
}
|
|
|
|
|
2015-07-04 14:11:20 -05:00
|
|
|
fn visit_unit_struct(&mut self, name: &str) -> Result<(), ()> {
|
|
|
|
assert_eq!(self.iter.next().unwrap(), Token::UnitStruct(name));
|
2015-03-03 22:33:17 -06:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2015-07-29 14:25:16 -05:00
|
|
|
fn visit_unit_variant(&mut self,
|
|
|
|
name: &str,
|
|
|
|
_variant_index: usize,
|
|
|
|
variant: &str) -> Result<(), ()> {
|
2015-07-19 12:09:12 -05:00
|
|
|
assert_eq!(
|
|
|
|
self.iter.next().unwrap(),
|
|
|
|
Token::EnumUnit(name, variant)
|
|
|
|
);
|
|
|
|
|
2015-03-03 22:33:17 -06:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn visit_bool(&mut self, v: bool) -> Result<(), ()> {
|
|
|
|
assert_eq!(self.iter.next(), Some(Token::Bool(v)));
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn visit_isize(&mut self, v: isize) -> Result<(), ()> {
|
|
|
|
assert_eq!(self.iter.next(), Some(Token::Isize(v)));
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn visit_i8(&mut self, v: i8) -> Result<(), ()> {
|
|
|
|
assert_eq!(self.iter.next(), Some(Token::I8(v)));
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn visit_i16(&mut self, v: i16) -> Result<(), ()> {
|
|
|
|
assert_eq!(self.iter.next(), Some(Token::I16(v)));
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn visit_i32(&mut self, v: i32) -> Result<(), ()> {
|
|
|
|
assert_eq!(self.iter.next(), Some(Token::I32(v)));
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn visit_i64(&mut self, v: i64) -> Result<(), ()> {
|
|
|
|
assert_eq!(self.iter.next(), Some(Token::I64(v)));
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn visit_usize(&mut self, v: usize) -> Result<(), ()> {
|
|
|
|
assert_eq!(self.iter.next(), Some(Token::Usize(v)));
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn visit_u8(&mut self, v: u8) -> Result<(), ()> {
|
|
|
|
assert_eq!(self.iter.next(), Some(Token::U8(v)));
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn visit_u16(&mut self, v: u16) -> Result<(), ()> {
|
|
|
|
assert_eq!(self.iter.next(), Some(Token::U16(v)));
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn visit_u32(&mut self, v: u32) -> Result<(), ()> {
|
|
|
|
assert_eq!(self.iter.next(), Some(Token::U32(v)));
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn visit_u64(&mut self, v: u64) -> Result<(), ()> {
|
|
|
|
assert_eq!(self.iter.next(), Some(Token::U64(v)));
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn visit_f32(&mut self, v: f32) -> Result<(), ()> {
|
|
|
|
assert_eq!(self.iter.next(), Some(Token::F32(v)));
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn visit_f64(&mut self, v: f64) -> Result<(), ()> {
|
|
|
|
assert_eq!(self.iter.next(), Some(Token::F64(v)));
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn visit_char(&mut self, v: char) -> Result<(), ()> {
|
|
|
|
assert_eq!(self.iter.next(), Some(Token::Char(v)));
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn visit_str(&mut self, v: &str) -> Result<(), ()> {
|
|
|
|
assert_eq!(self.iter.next().unwrap(), Token::Str(v));
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn visit_none(&mut self) -> Result<(), ()> {
|
|
|
|
assert_eq!(self.iter.next(), Some(Token::Option(false)));
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn visit_some<V>(&mut self, value: V) -> Result<(), ()>
|
|
|
|
where V: Serialize,
|
|
|
|
{
|
|
|
|
assert_eq!(self.iter.next(), Some(Token::Option(true)));
|
2015-03-12 09:33:34 -05:00
|
|
|
value.serialize(self)
|
2015-03-03 22:33:17 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn visit_seq<V>(&mut self, visitor: V) -> Result<(), ()>
|
|
|
|
where V: SeqVisitor
|
|
|
|
{
|
2015-03-12 21:40:46 -05:00
|
|
|
let len = visitor.len();
|
2015-03-03 22:33:17 -06:00
|
|
|
|
|
|
|
assert_eq!(self.iter.next(), Some(Token::SeqStart(len)));
|
|
|
|
|
|
|
|
self.visit_sequence(visitor)
|
|
|
|
}
|
|
|
|
|
2015-07-04 14:11:20 -05:00
|
|
|
fn visit_tuple_struct<V>(&mut self, name: &str, visitor: V) -> Result<(), ()>
|
2015-03-03 22:33:17 -06:00
|
|
|
where V: SeqVisitor
|
|
|
|
{
|
2015-03-12 21:40:46 -05:00
|
|
|
let len = visitor.len();
|
2015-03-03 22:33:17 -06:00
|
|
|
|
2015-07-19 12:09:12 -05:00
|
|
|
assert_eq!(
|
|
|
|
self.iter.next().unwrap(),
|
|
|
|
Token::TupleStructStart(name, len)
|
|
|
|
);
|
2015-03-03 22:33:17 -06:00
|
|
|
|
|
|
|
self.visit_sequence(visitor)
|
|
|
|
}
|
|
|
|
|
2015-07-29 14:25:16 -05:00
|
|
|
fn visit_tuple_variant<V>(&mut self,
|
|
|
|
name: &str,
|
|
|
|
_variant_index: usize,
|
|
|
|
variant: &str,
|
|
|
|
visitor: V) -> Result<(), ()>
|
2015-03-03 22:33:17 -06:00
|
|
|
where V: SeqVisitor
|
|
|
|
{
|
2015-03-12 21:40:46 -05:00
|
|
|
let len = visitor.len();
|
2015-03-03 22:33:17 -06:00
|
|
|
|
2015-07-19 12:09:12 -05:00
|
|
|
assert_eq!(
|
|
|
|
self.iter.next().unwrap(),
|
|
|
|
Token::EnumSeqStart(name, variant, len)
|
|
|
|
);
|
2015-03-03 22:33:17 -06:00
|
|
|
|
|
|
|
self.visit_sequence(visitor)
|
|
|
|
}
|
|
|
|
|
2015-03-17 00:30:02 -05:00
|
|
|
fn visit_seq_elt<T>(&mut self, value: T) -> Result<(), ()>
|
2015-03-03 22:33:17 -06:00
|
|
|
where T: Serialize
|
|
|
|
{
|
2015-03-17 00:30:02 -05:00
|
|
|
assert_eq!(self.iter.next(), Some(Token::SeqSep));
|
2015-03-12 09:33:34 -05:00
|
|
|
value.serialize(self)
|
2015-03-03 22:33:17 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fn visit_map<V>(&mut self, visitor: V) -> Result<(), ()>
|
|
|
|
where V: MapVisitor
|
|
|
|
{
|
2015-03-12 21:40:46 -05:00
|
|
|
let len = visitor.len();
|
2015-03-03 22:33:17 -06:00
|
|
|
|
|
|
|
assert_eq!(self.iter.next(), Some(Token::MapStart(len)));
|
|
|
|
|
|
|
|
self.visit_mapping(visitor)
|
|
|
|
}
|
|
|
|
|
2015-07-04 14:11:20 -05:00
|
|
|
fn visit_struct<V>(&mut self, name: &str, visitor: V) -> Result<(), ()>
|
2015-03-03 22:33:17 -06:00
|
|
|
where V: MapVisitor
|
|
|
|
{
|
2015-03-12 21:40:46 -05:00
|
|
|
let len = visitor.len();
|
2015-03-03 22:33:17 -06:00
|
|
|
|
2015-07-19 12:09:12 -05:00
|
|
|
assert_eq!(
|
|
|
|
self.iter.next().unwrap(),
|
|
|
|
Token::StructStart(name, len)
|
|
|
|
);
|
2015-03-03 22:33:17 -06:00
|
|
|
|
|
|
|
self.visit_mapping(visitor)
|
|
|
|
}
|
|
|
|
|
2015-07-29 14:25:16 -05:00
|
|
|
fn visit_struct_variant<V>(&mut self,
|
|
|
|
name: &str,
|
|
|
|
_variant_index: usize,
|
|
|
|
variant: &str,
|
|
|
|
visitor: V) -> Result<(), ()>
|
2015-03-03 22:33:17 -06:00
|
|
|
where V: MapVisitor
|
|
|
|
{
|
2015-03-12 21:40:46 -05:00
|
|
|
let len = visitor.len();
|
2015-03-03 22:33:17 -06:00
|
|
|
|
2015-07-19 12:09:12 -05:00
|
|
|
assert_eq!(
|
|
|
|
self.iter.next().unwrap(),
|
|
|
|
Token::EnumMapStart(name, variant, len)
|
|
|
|
);
|
2015-03-03 22:33:17 -06:00
|
|
|
|
|
|
|
self.visit_mapping(visitor)
|
|
|
|
}
|
|
|
|
|
2015-03-17 00:30:02 -05:00
|
|
|
fn visit_map_elt<K, V>(&mut self, key: K, value: V) -> Result<(), ()>
|
2015-03-03 22:33:17 -06:00
|
|
|
where K: Serialize,
|
|
|
|
V: Serialize,
|
|
|
|
{
|
2015-03-17 00:30:02 -05:00
|
|
|
assert_eq!(self.iter.next(), Some(Token::MapSep));
|
2015-03-03 22:33:17 -06:00
|
|
|
|
2015-03-12 09:33:34 -05:00
|
|
|
try!(key.serialize(self));
|
|
|
|
value.serialize(self)
|
2015-03-03 22:33:17 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-03 23:42:33 -06:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-03-19 09:49:42 -05:00
|
|
|
#[derive(Serialize)]
|
2015-07-04 14:11:20 -05:00
|
|
|
struct UnitStruct;
|
2015-03-03 22:33:17 -06:00
|
|
|
|
2015-03-19 09:49:42 -05:00
|
|
|
#[derive(Serialize)]
|
2015-07-04 14:11:20 -05:00
|
|
|
struct TupleStruct(i32, i32, i32);
|
2015-03-03 22:33:17 -06:00
|
|
|
|
2015-03-19 09:49:42 -05:00
|
|
|
#[derive(Serialize)]
|
2015-07-04 14:11:20 -05:00
|
|
|
struct Struct {
|
2015-03-03 23:42:33 -06:00
|
|
|
a: i32,
|
|
|
|
b: i32,
|
|
|
|
c: i32,
|
|
|
|
}
|
|
|
|
|
2015-03-19 09:49:42 -05:00
|
|
|
#[derive(Serialize)]
|
2015-03-03 22:33:17 -06:00
|
|
|
enum Enum {
|
|
|
|
Unit,
|
2015-07-17 08:19:11 -05:00
|
|
|
One(i32),
|
2015-03-03 22:33:17 -06:00
|
|
|
Seq(i32, i32),
|
|
|
|
Map { a: i32, b: i32 },
|
|
|
|
}
|
|
|
|
|
2015-03-03 23:42:33 -06:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-03-03 22:33:17 -06:00
|
|
|
macro_rules! btreemap {
|
|
|
|
() => {
|
|
|
|
BTreeMap::new()
|
|
|
|
};
|
|
|
|
($($key:expr => $value:expr),+) => {
|
|
|
|
{
|
|
|
|
let mut map = BTreeMap::new();
|
|
|
|
$(map.insert($key, $value);)+
|
|
|
|
map
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! declare_test {
|
|
|
|
($name:ident { $($value:expr => $tokens:expr,)+ }) => {
|
|
|
|
#[test]
|
|
|
|
fn $name() {
|
|
|
|
$(
|
|
|
|
let mut ser = AssertSerializer::new($tokens);
|
2015-03-12 09:33:34 -05:00
|
|
|
assert_eq!($value.serialize(&mut ser), Ok(()));
|
2015-03-03 22:33:17 -06:00
|
|
|
)+
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! declare_tests {
|
|
|
|
($($name:ident { $($value:expr => $tokens:expr,)+ })+) => {
|
|
|
|
$(
|
|
|
|
declare_test!($name { $($value => $tokens,)+ });
|
|
|
|
)+
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
declare_tests! {
|
|
|
|
test_unit {
|
|
|
|
() => vec![Token::Unit],
|
|
|
|
}
|
|
|
|
test_bool {
|
|
|
|
true => vec![Token::Bool(true)],
|
|
|
|
false => vec![Token::Bool(false)],
|
|
|
|
}
|
|
|
|
test_isizes {
|
|
|
|
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_usizes {
|
|
|
|
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')],
|
|
|
|
}
|
|
|
|
test_str {
|
|
|
|
"abc" => vec![Token::Str("abc")],
|
|
|
|
"abc".to_string() => vec![Token::Str("abc")],
|
|
|
|
}
|
|
|
|
test_option {
|
|
|
|
None::<i32> => vec![Token::Option(false)],
|
|
|
|
Some(1) => vec![
|
|
|
|
Token::Option(true),
|
|
|
|
Token::I32(1),
|
|
|
|
],
|
|
|
|
}
|
2015-07-19 13:16:46 -05:00
|
|
|
test_result {
|
|
|
|
Ok::<i32, i32>(0) => vec![
|
2015-07-30 09:58:02 -05:00
|
|
|
Token::EnumSimple("Result", "Ok"),
|
2015-07-19 13:16:46 -05:00
|
|
|
Token::I32(0),
|
|
|
|
],
|
|
|
|
Err::<i32, i32>(1) => vec![
|
2015-07-30 09:58:02 -05:00
|
|
|
Token::EnumSimple("Result", "Err"),
|
2015-07-19 13:16:46 -05:00
|
|
|
Token::I32(1),
|
|
|
|
],
|
|
|
|
}
|
2015-03-03 22:33:17 -06:00
|
|
|
test_slice {
|
|
|
|
&[0][..0] => vec![
|
2015-03-12 21:40:46 -05:00
|
|
|
Token::SeqStart(Some(0)),
|
2015-03-03 22:33:17 -06:00
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
|
|
|
&[1, 2, 3][..] => vec![
|
2015-03-12 21:40:46 -05:00
|
|
|
Token::SeqStart(Some(3)),
|
2015-03-17 00:30:02 -05:00
|
|
|
Token::SeqSep,
|
2015-03-03 22:33:17 -06:00
|
|
|
Token::I32(1),
|
|
|
|
|
2015-03-17 00:30:02 -05:00
|
|
|
Token::SeqSep,
|
2015-03-03 22:33:17 -06:00
|
|
|
Token::I32(2),
|
2015-05-16 04:51:35 -05:00
|
|
|
|
|
|
|
Token::SeqSep,
|
|
|
|
Token::I32(3),
|
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
|
|
|
}
|
|
|
|
test_array {
|
|
|
|
[0; 0] => vec![
|
|
|
|
Token::SeqStart(Some(0)),
|
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
|
|
|
[1, 2, 3] => vec![
|
|
|
|
Token::SeqStart(Some(3)),
|
|
|
|
Token::SeqSep,
|
|
|
|
Token::I32(1),
|
|
|
|
|
|
|
|
Token::SeqSep,
|
|
|
|
Token::I32(2),
|
2015-03-03 22:33:17 -06:00
|
|
|
|
2015-03-17 00:30:02 -05:00
|
|
|
Token::SeqSep,
|
2015-03-03 22:33:17 -06:00
|
|
|
Token::I32(3),
|
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
|
|
|
}
|
|
|
|
test_vec {
|
|
|
|
Vec::<isize>::new() => vec![
|
2015-03-12 21:40:46 -05:00
|
|
|
Token::SeqStart(Some(0)),
|
2015-03-03 22:33:17 -06:00
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
|
|
|
vec![vec![], vec![1], vec![2, 3]] => vec![
|
2015-03-12 21:40:46 -05:00
|
|
|
Token::SeqStart(Some(3)),
|
2015-03-17 00:30:02 -05:00
|
|
|
Token::SeqSep,
|
2015-03-12 21:40:46 -05:00
|
|
|
Token::SeqStart(Some(0)),
|
2015-03-03 22:33:17 -06:00
|
|
|
Token::SeqEnd,
|
|
|
|
|
2015-03-17 00:30:02 -05:00
|
|
|
Token::SeqSep,
|
2015-03-12 21:40:46 -05:00
|
|
|
Token::SeqStart(Some(1)),
|
2015-03-17 00:30:02 -05:00
|
|
|
Token::SeqSep,
|
2015-03-03 22:33:17 -06:00
|
|
|
Token::I32(1),
|
|
|
|
Token::SeqEnd,
|
|
|
|
|
2015-03-17 00:30:02 -05:00
|
|
|
Token::SeqSep,
|
2015-03-12 21:40:46 -05:00
|
|
|
Token::SeqStart(Some(2)),
|
2015-03-17 00:30:02 -05:00
|
|
|
Token::SeqSep,
|
2015-03-03 22:33:17 -06:00
|
|
|
Token::I32(2),
|
|
|
|
|
2015-03-17 00:30:02 -05:00
|
|
|
Token::SeqSep,
|
2015-03-03 22:33:17 -06:00
|
|
|
Token::I32(3),
|
|
|
|
Token::SeqEnd,
|
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
|
|
|
}
|
|
|
|
test_tuple {
|
|
|
|
(1,) => vec![
|
2015-03-12 21:40:46 -05:00
|
|
|
Token::SeqStart(Some(1)),
|
2015-03-17 00:30:02 -05:00
|
|
|
Token::SeqSep,
|
2015-03-03 22:33:17 -06:00
|
|
|
Token::I32(1),
|
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
|
|
|
(1, 2, 3) => vec![
|
2015-03-12 21:40:46 -05:00
|
|
|
Token::SeqStart(Some(3)),
|
2015-03-17 00:30:02 -05:00
|
|
|
Token::SeqSep,
|
2015-03-03 22:33:17 -06:00
|
|
|
Token::I32(1),
|
|
|
|
|
2015-03-17 00:30:02 -05:00
|
|
|
Token::SeqSep,
|
2015-03-03 22:33:17 -06:00
|
|
|
Token::I32(2),
|
|
|
|
|
2015-03-17 00:30:02 -05:00
|
|
|
Token::SeqSep,
|
2015-03-03 22:33:17 -06:00
|
|
|
Token::I32(3),
|
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
|
|
|
}
|
|
|
|
test_btreemap {
|
|
|
|
btreemap![1 => 2] => vec![
|
2015-03-12 21:40:46 -05:00
|
|
|
Token::MapStart(Some(1)),
|
2015-03-17 00:30:02 -05:00
|
|
|
Token::MapSep,
|
2015-03-03 22:33:17 -06:00
|
|
|
Token::I32(1),
|
|
|
|
Token::I32(2),
|
|
|
|
Token::MapEnd,
|
|
|
|
],
|
|
|
|
btreemap![1 => 2, 3 => 4] => vec![
|
2015-03-12 21:40:46 -05:00
|
|
|
Token::MapStart(Some(2)),
|
2015-03-17 00:30:02 -05:00
|
|
|
Token::MapSep,
|
2015-03-03 22:33:17 -06:00
|
|
|
Token::I32(1),
|
|
|
|
Token::I32(2),
|
|
|
|
|
2015-03-17 00:30:02 -05:00
|
|
|
Token::MapSep,
|
2015-03-03 22:33:17 -06:00
|
|
|
Token::I32(3),
|
|
|
|
Token::I32(4),
|
|
|
|
Token::MapEnd,
|
|
|
|
],
|
|
|
|
btreemap![1 => btreemap![], 2 => btreemap![3 => 4, 5 => 6]] => vec![
|
2015-03-12 21:40:46 -05:00
|
|
|
Token::MapStart(Some(2)),
|
2015-03-17 00:30:02 -05:00
|
|
|
Token::MapSep,
|
2015-03-03 22:33:17 -06:00
|
|
|
Token::I32(1),
|
2015-03-12 21:40:46 -05:00
|
|
|
Token::MapStart(Some(0)),
|
2015-03-03 22:33:17 -06:00
|
|
|
Token::MapEnd,
|
|
|
|
|
2015-03-17 00:30:02 -05:00
|
|
|
Token::MapSep,
|
2015-03-03 22:33:17 -06:00
|
|
|
Token::I32(2),
|
2015-03-12 21:40:46 -05:00
|
|
|
Token::MapStart(Some(2)),
|
2015-03-17 00:30:02 -05:00
|
|
|
Token::MapSep,
|
2015-03-03 22:33:17 -06:00
|
|
|
Token::I32(3),
|
|
|
|
Token::I32(4),
|
|
|
|
|
2015-03-17 00:30:02 -05:00
|
|
|
Token::MapSep,
|
2015-03-03 22:33:17 -06:00
|
|
|
Token::I32(5),
|
|
|
|
Token::I32(6),
|
|
|
|
Token::MapEnd,
|
|
|
|
Token::MapEnd,
|
|
|
|
],
|
|
|
|
}
|
2015-07-04 14:11:20 -05:00
|
|
|
test_unit_struct {
|
|
|
|
UnitStruct => vec![Token::UnitStruct("UnitStruct")],
|
2015-03-03 22:33:17 -06:00
|
|
|
}
|
2015-07-04 14:11:20 -05:00
|
|
|
test_tuple_struct {
|
|
|
|
TupleStruct(1, 2, 3) => vec![
|
|
|
|
Token::TupleStructStart("TupleStruct", Some(3)),
|
2015-03-17 00:30:02 -05:00
|
|
|
Token::SeqSep,
|
2015-03-03 22:33:17 -06:00
|
|
|
Token::I32(1),
|
|
|
|
|
2015-03-17 00:30:02 -05:00
|
|
|
Token::SeqSep,
|
2015-03-03 22:33:17 -06:00
|
|
|
Token::I32(2),
|
|
|
|
|
2015-03-17 00:30:02 -05:00
|
|
|
Token::SeqSep,
|
2015-03-03 22:33:17 -06:00
|
|
|
Token::I32(3),
|
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
|
|
|
}
|
2015-07-04 14:11:20 -05:00
|
|
|
test_struct {
|
|
|
|
Struct { a: 1, b: 2, c: 3 } => vec![
|
|
|
|
Token::StructStart("Struct", Some(3)),
|
2015-03-17 00:30:02 -05:00
|
|
|
Token::MapSep,
|
2015-03-03 23:42:33 -06:00
|
|
|
Token::Str("a"),
|
|
|
|
Token::I32(1),
|
|
|
|
|
2015-03-17 00:30:02 -05:00
|
|
|
Token::MapSep,
|
2015-03-03 23:42:33 -06:00
|
|
|
Token::Str("b"),
|
|
|
|
Token::I32(2),
|
|
|
|
|
2015-03-17 00:30:02 -05:00
|
|
|
Token::MapSep,
|
2015-03-03 23:42:33 -06:00
|
|
|
Token::Str("c"),
|
|
|
|
Token::I32(3),
|
|
|
|
Token::MapEnd,
|
|
|
|
],
|
|
|
|
}
|
2015-03-03 22:33:17 -06:00
|
|
|
test_enum {
|
|
|
|
Enum::Unit => vec![Token::EnumUnit("Enum", "Unit")],
|
2015-07-17 08:19:11 -05:00
|
|
|
Enum::One(42) => vec![Token::EnumSimple("Enum", "One"), Token::I32(42)],
|
2015-03-03 22:33:17 -06:00
|
|
|
Enum::Seq(1, 2) => vec![
|
2015-03-12 21:40:46 -05:00
|
|
|
Token::EnumSeqStart("Enum", "Seq", Some(2)),
|
2015-03-17 00:30:02 -05:00
|
|
|
Token::SeqSep,
|
2015-03-03 22:33:17 -06:00
|
|
|
Token::I32(1),
|
|
|
|
|
2015-03-17 00:30:02 -05:00
|
|
|
Token::SeqSep,
|
2015-03-03 22:33:17 -06:00
|
|
|
Token::I32(2),
|
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
|
|
|
Enum::Map { a: 1, b: 2 } => vec![
|
2015-03-12 21:40:46 -05:00
|
|
|
Token::EnumMapStart("Enum", "Map", Some(2)),
|
2015-03-17 00:30:02 -05:00
|
|
|
Token::MapSep,
|
2015-03-03 22:33:17 -06:00
|
|
|
Token::Str("a"),
|
|
|
|
Token::I32(1),
|
|
|
|
|
2015-03-17 00:30:02 -05:00
|
|
|
Token::MapSep,
|
2015-03-03 22:33:17 -06:00
|
|
|
Token::Str("b"),
|
|
|
|
Token::I32(2),
|
|
|
|
Token::MapEnd,
|
|
|
|
],
|
|
|
|
}
|
|
|
|
}
|