2017-04-13 19:34:42 -05:00
|
|
|
// Copyright 2017 Serde Developers
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2018-07-08 21:02:44 -05:00
|
|
|
#![cfg_attr(
|
|
|
|
feature = "cargo-clippy",
|
|
|
|
allow(decimal_literal_representation)
|
|
|
|
)]
|
2018-06-03 02:15:05 -05:00
|
|
|
#![cfg_attr(feature = "unstable", feature(never_type))]
|
2018-01-13 16:28:12 -06:00
|
|
|
|
2017-02-24 17:32:13 -06:00
|
|
|
#[macro_use]
|
|
|
|
extern crate serde_derive;
|
|
|
|
|
2015-03-20 22:35:01 -05:00
|
|
|
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
|
2017-02-20 15:34:52 -06:00
|
|
|
use std::default::Default;
|
2018-06-03 02:27:26 -05:00
|
|
|
use std::ffi::{CStr, CString, OsString};
|
2018-04-30 03:41:22 -05:00
|
|
|
use std::net;
|
|
|
|
use std::num::Wrapping;
|
|
|
|
use std::path::{Path, PathBuf};
|
2018-05-07 13:16:40 -05:00
|
|
|
use std::rc::{Rc, Weak as RcWeak};
|
|
|
|
use std::sync::{Arc, Weak as ArcWeak};
|
2018-04-30 03:41:22 -05:00
|
|
|
use std::time::{Duration, UNIX_EPOCH};
|
2015-03-20 10:32:33 -05:00
|
|
|
|
2017-02-24 17:32:13 -06:00
|
|
|
extern crate serde;
|
2018-05-07 13:16:40 -05:00
|
|
|
use serde::{Deserialize, Deserializer};
|
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;
|
2017-11-03 10:12:43 -05:00
|
|
|
use self::serde_test::{assert_de_tokens, assert_de_tokens_error, Configure, Token};
|
2015-03-03 23:19:55 -06:00
|
|
|
|
2017-02-24 17:32:13 -06:00
|
|
|
#[macro_use]
|
|
|
|
mod macros;
|
|
|
|
|
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
|
|
|
|
2017-04-05 11:19:22 -05:00
|
|
|
#[derive(PartialEq, Debug, Deserialize)]
|
|
|
|
struct NewtypeStruct(i32);
|
|
|
|
|
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,
|
2017-12-23 22:24:57 -06:00
|
|
|
#[serde(skip_deserializing)]
|
|
|
|
c: i32,
|
2015-03-03 23:19:55 -06:00
|
|
|
}
|
|
|
|
|
2017-01-13 01:17:45 -06:00
|
|
|
#[derive(PartialEq, Debug, Deserialize)]
|
|
|
|
#[serde(deny_unknown_fields)]
|
|
|
|
struct StructDenyUnknown {
|
|
|
|
a: i32,
|
2017-12-23 22:24:57 -06:00
|
|
|
#[serde(skip_deserializing)]
|
|
|
|
b: i32,
|
2017-01-13 01:17:45 -06:00
|
|
|
}
|
|
|
|
|
2017-02-20 15:34:52 -06:00
|
|
|
#[derive(PartialEq, Debug, Deserialize)]
|
|
|
|
#[serde(default)]
|
2017-02-20 19:03:38 -06:00
|
|
|
struct StructDefault<T> {
|
2017-02-20 15:34:52 -06:00
|
|
|
a: i32,
|
2017-02-20 19:03:38 -06:00
|
|
|
b: T,
|
2017-02-20 15:34:52 -06:00
|
|
|
}
|
|
|
|
|
2017-02-20 19:03:38 -06:00
|
|
|
impl Default for StructDefault<String> {
|
|
|
|
fn default() -> Self {
|
|
|
|
StructDefault {
|
2017-02-20 15:34:52 -06:00
|
|
|
a: 100,
|
|
|
|
b: "default".to_string(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-13 03:12:31 -06:00
|
|
|
#[derive(PartialEq, Debug, Deserialize)]
|
|
|
|
struct StructSkipAll {
|
2017-12-23 22:24:57 -06:00
|
|
|
#[serde(skip_deserializing)]
|
|
|
|
a: i32,
|
2017-01-13 03:12:31 -06:00
|
|
|
}
|
|
|
|
|
2017-12-06 14:07:16 -06:00
|
|
|
#[derive(PartialEq, Debug, Deserialize)]
|
|
|
|
#[serde(default)]
|
|
|
|
struct StructSkipDefault {
|
2017-12-23 22:24:57 -06:00
|
|
|
#[serde(skip_deserializing)]
|
|
|
|
a: i32,
|
2017-12-06 14:07:16 -06:00
|
|
|
}
|
|
|
|
|
2017-12-11 22:59:54 -06:00
|
|
|
#[derive(PartialEq, Debug, Deserialize)]
|
|
|
|
#[serde(default)]
|
|
|
|
struct StructSkipDefaultGeneric<T> {
|
2017-12-23 22:24:57 -06:00
|
|
|
#[serde(skip_deserializing)]
|
|
|
|
t: T,
|
2017-12-11 22:59:54 -06:00
|
|
|
}
|
|
|
|
|
2017-12-06 14:07:16 -06:00
|
|
|
impl Default for StructSkipDefault {
|
|
|
|
fn default() -> Self {
|
2017-12-23 22:13:08 -06:00
|
|
|
StructSkipDefault { a: 16 }
|
2017-12-06 14:07:16 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-13 03:12:31 -06:00
|
|
|
#[derive(PartialEq, Debug, Deserialize)]
|
|
|
|
#[serde(deny_unknown_fields)]
|
|
|
|
struct StructSkipAllDenyUnknown {
|
2017-12-23 22:24:57 -06:00
|
|
|
#[serde(skip_deserializing)]
|
|
|
|
a: i32,
|
2017-01-13 03:12:31 -06:00
|
|
|
}
|
|
|
|
|
2015-03-19 09:49:42 -05:00
|
|
|
#[derive(PartialEq, Debug, Deserialize)]
|
2015-03-03 23:19:55 -06:00
|
|
|
enum Enum {
|
2017-01-13 01:35:39 -06:00
|
|
|
#[allow(dead_code)]
|
|
|
|
#[serde(skip_deserializing)]
|
|
|
|
Skipped,
|
2015-03-03 23:19:55 -06:00
|
|
|
Unit,
|
2015-07-30 09:54:55 -05:00
|
|
|
Simple(i32),
|
2015-03-03 23:19:55 -06:00
|
|
|
Seq(i32, i32, i32),
|
2017-12-23 22:13:08 -06:00
|
|
|
Map {
|
|
|
|
a: i32,
|
|
|
|
b: i32,
|
|
|
|
c: i32,
|
|
|
|
},
|
2015-03-03 23:19:55 -06:00
|
|
|
}
|
|
|
|
|
2017-01-13 03:14:03 -06:00
|
|
|
#[derive(PartialEq, Debug, Deserialize)]
|
|
|
|
enum EnumSkipAll {
|
|
|
|
#[allow(dead_code)]
|
|
|
|
#[serde(skip_deserializing)]
|
|
|
|
Skipped,
|
|
|
|
}
|
|
|
|
|
2015-03-03 23:19:55 -06:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
macro_rules! declare_tests {
|
2017-10-18 01:15:35 -05:00
|
|
|
(
|
2017-11-03 10:12:43 -05:00
|
|
|
$readable:tt
|
2017-10-18 01:15:35 -05:00
|
|
|
$($name:ident { $($value:expr => $tokens:expr,)+ })+
|
|
|
|
) => {
|
|
|
|
$(
|
|
|
|
#[test]
|
|
|
|
fn $name() {
|
|
|
|
$(
|
|
|
|
// Test ser/de roundtripping
|
2017-11-03 10:12:43 -05:00
|
|
|
assert_de_tokens(&$value.$readable(), $tokens);
|
2017-10-18 01:15:35 -05:00
|
|
|
|
|
|
|
// Test that the tokens are ignorable
|
|
|
|
assert_de_tokens_ignore($tokens);
|
|
|
|
)+
|
|
|
|
}
|
|
|
|
)+
|
|
|
|
};
|
|
|
|
|
2015-03-03 23:19:55 -06:00
|
|
|
($($name:ident { $($value:expr => $tokens:expr,)+ })+) => {
|
|
|
|
$(
|
2017-10-18 01:15:35 -05:00
|
|
|
#[test]
|
|
|
|
fn $name() {
|
|
|
|
$(
|
|
|
|
// Test ser/de roundtripping
|
|
|
|
assert_de_tokens(&$value, $tokens);
|
|
|
|
|
|
|
|
// Test that the tokens are ignorable
|
|
|
|
assert_de_tokens_ignore($tokens);
|
|
|
|
)+
|
|
|
|
}
|
2015-03-03 23:19:55 -06:00
|
|
|
)+
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-07 01:27:12 -06:00
|
|
|
macro_rules! declare_error_tests {
|
2017-01-28 17:00:54 -06:00
|
|
|
($($name:ident<$target:ty> { $tokens:expr, $expected:expr, })+) => {
|
2016-03-07 01:27:12 -06:00
|
|
|
$(
|
|
|
|
#[test]
|
|
|
|
fn $name() {
|
|
|
|
assert_de_tokens_error::<$target>($tokens, $expected);
|
|
|
|
}
|
|
|
|
)+
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-07 13:16:40 -05:00
|
|
|
#[derive(Debug)]
|
|
|
|
struct SkipPartialEq<T>(T);
|
|
|
|
|
|
|
|
impl<'de, T> Deserialize<'de> for SkipPartialEq<T>
|
|
|
|
where
|
|
|
|
T: Deserialize<'de>,
|
|
|
|
{
|
|
|
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
|
|
|
where
|
|
|
|
D: Deserializer<'de>,
|
|
|
|
{
|
|
|
|
T::deserialize(deserializer).map(SkipPartialEq)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> PartialEq for SkipPartialEq<T> {
|
|
|
|
fn eq(&self, _other: &Self) -> bool {
|
|
|
|
true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-18 01:09:50 -05:00
|
|
|
fn assert_de_tokens_ignore(ignorable_tokens: &[Token]) {
|
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
|
|
|
// Embed the tokens to be ignored in the normal token
|
|
|
|
// stream for an IgnoreBase type
|
2017-04-13 14:28:23 -05:00
|
|
|
let concated_tokens: Vec<Token> = vec![
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Map { len: Some(2) },
|
2017-04-13 14:28:23 -05:00
|
|
|
Token::Str("a"),
|
|
|
|
Token::I32(1),
|
|
|
|
Token::Str("ignored"),
|
2017-11-03 10:12:43 -05:00
|
|
|
].into_iter()
|
|
|
|
.chain(ignorable_tokens.to_vec().into_iter())
|
|
|
|
.chain(vec![Token::MapEnd].into_iter())
|
|
|
|
.collect();
|
2016-07-12 08:44:19 -05:00
|
|
|
|
2017-10-18 01:09:50 -05:00
|
|
|
let mut de = serde_test::Deserializer::new(&concated_tokens);
|
2017-04-19 13:38:57 -05:00
|
|
|
let base = IgnoreBase::deserialize(&mut de).unwrap();
|
|
|
|
assert_eq!(base, IgnoreBase { a: 1 });
|
2016-06-28 23:47:54 -05:00
|
|
|
}
|
|
|
|
|
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::I8(0)],
|
|
|
|
0isize => &[Token::I16(0)],
|
|
|
|
0isize => &[Token::I32(0)],
|
|
|
|
0isize => &[Token::I64(0)],
|
|
|
|
0isize => &[Token::U8(0)],
|
|
|
|
0isize => &[Token::U16(0)],
|
|
|
|
0isize => &[Token::U32(0)],
|
|
|
|
0isize => &[Token::U64(0)],
|
2015-03-03 23:19:55 -06:00
|
|
|
}
|
|
|
|
test_ints {
|
2016-06-29 01:50:19 -05:00
|
|
|
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
|
|
|
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
|
|
|
}
|
2018-05-19 18:31:44 -05:00
|
|
|
test_small_int_to_128 {
|
|
|
|
1i128 => &[Token::I8(1)],
|
|
|
|
1i128 => &[Token::I16(1)],
|
|
|
|
1i128 => &[Token::I32(1)],
|
|
|
|
1i128 => &[Token::I64(1)],
|
|
|
|
|
|
|
|
1i128 => &[Token::U8(1)],
|
|
|
|
1i128 => &[Token::U16(1)],
|
|
|
|
1i128 => &[Token::U32(1)],
|
|
|
|
1i128 => &[Token::U64(1)],
|
|
|
|
|
|
|
|
1u128 => &[Token::I8(1)],
|
|
|
|
1u128 => &[Token::I16(1)],
|
|
|
|
1u128 => &[Token::I32(1)],
|
|
|
|
1u128 => &[Token::I64(1)],
|
|
|
|
|
|
|
|
1u128 => &[Token::U8(1)],
|
|
|
|
1u128 => &[Token::U16(1)],
|
|
|
|
1u128 => &[Token::U32(1)],
|
|
|
|
1u128 => &[Token::U64(1)],
|
|
|
|
}
|
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")],
|
2017-04-05 02:17:50 -05:00
|
|
|
'a' => &[Token::String("a")],
|
2015-03-03 23:19:55 -06:00
|
|
|
}
|
|
|
|
test_string {
|
2016-06-29 01:50:19 -05:00
|
|
|
"abc".to_owned() => &[Token::Str("abc")],
|
2017-04-05 02:17:50 -05:00
|
|
|
"abc".to_owned() => &[Token::String("abc")],
|
2016-06-29 01:50:19 -05:00
|
|
|
"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],
|
2017-04-05 12:40:14 -05:00
|
|
|
None::<i32> => &[Token::None],
|
2016-06-29 01:50:19 -05:00
|
|
|
Some(1) => &[
|
2017-04-05 12:40:14 -05:00
|
|
|
Token::Some,
|
2015-03-03 23:19:55 -06:00
|
|
|
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) => &[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Enum { name: "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) => &[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Enum { name: "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-03-03 23:19:55 -06:00
|
|
|
}
|
2015-07-04 14:11:20 -05:00
|
|
|
test_unit_struct {
|
2016-06-29 01:50:19 -05:00
|
|
|
UnitStruct => &[Token::Unit],
|
|
|
|
UnitStruct => &[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::UnitStruct { name: "UnitStruct" },
|
2015-03-20 10:32:33 -05:00
|
|
|
],
|
2015-03-03 23:19:55 -06:00
|
|
|
}
|
2017-04-05 11:19:22 -05:00
|
|
|
test_newtype_struct {
|
|
|
|
NewtypeStruct(1) => &[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::NewtypeStruct { name: "NewtypeStruct" },
|
2017-04-05 11:19:22 -05:00
|
|
|
Token::I32(1),
|
|
|
|
],
|
|
|
|
}
|
2015-07-04 14:11:20 -05:00
|
|
|
test_tuple_struct {
|
2016-06-29 01:50:19 -05:00
|
|
|
TupleStruct(1, 2, 3) => &[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Seq { len: Some(3) },
|
2015-03-03 23:19:55 -06:00
|
|
|
Token::I32(1),
|
|
|
|
Token::I32(2),
|
|
|
|
Token::I32(3),
|
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
TupleStruct(1, 2, 3) => &[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Seq { len: None },
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::I32(1),
|
|
|
|
Token::I32(2),
|
|
|
|
Token::I32(3),
|
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
TupleStruct(1, 2, 3) => &[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::TupleStruct { name: "TupleStruct", len: 3 },
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::I32(1),
|
|
|
|
Token::I32(2),
|
|
|
|
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) => &[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::TupleStruct { name: "TupleStruct", len: 3 },
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::I32(1),
|
|
|
|
Token::I32(2),
|
|
|
|
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() => &[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Seq { len: 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]] => &[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Seq { len: Some(3) },
|
|
|
|
Token::Seq { len: Some(0) },
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::SeqEnd,
|
|
|
|
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Seq { len: Some(1) },
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::I32(1),
|
|
|
|
Token::SeqEnd,
|
|
|
|
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Seq { len: Some(2) },
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::I32(2),
|
|
|
|
Token::I32(3),
|
|
|
|
Token::SeqEnd,
|
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
BTreeSet::<isize>::new() => &[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::TupleStruct { name: "Anything", len: 0 },
|
2017-02-02 14:10:07 -06:00
|
|
|
Token::TupleStructEnd,
|
2015-03-20 22:35:01 -05:00
|
|
|
],
|
|
|
|
}
|
|
|
|
test_hashset {
|
2016-06-29 01:50:19 -05:00
|
|
|
HashSet::<isize>::new() => &[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Seq { len: Some(0) },
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
hashset![1, 2, 3] => &[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Seq { len: Some(3) },
|
2015-03-03 23:19:55 -06:00
|
|
|
Token::I32(1),
|
|
|
|
Token::I32(2),
|
|
|
|
Token::I32(3),
|
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
HashSet::<isize>::new() => &[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::TupleStruct { name: "Anything", len: 0 },
|
2017-02-02 14:10:07 -06:00
|
|
|
Token::TupleStructEnd,
|
2016-06-11 11:59:29 -05:00
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
hashset![FnvHasher @ 1, 2, 3] => &[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Seq { len: Some(3) },
|
2016-06-11 11:59:29 -05:00
|
|
|
Token::I32(1),
|
|
|
|
Token::I32(2),
|
|
|
|
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() => &[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Seq { len: 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]] => &[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Seq { len: Some(3) },
|
|
|
|
Token::Seq { len: Some(0) },
|
2015-03-03 23:19:55 -06:00
|
|
|
Token::SeqEnd,
|
|
|
|
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Seq { len: Some(1) },
|
2015-03-03 23:19:55 -06:00
|
|
|
Token::I32(1),
|
|
|
|
Token::SeqEnd,
|
|
|
|
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Seq { len: Some(2) },
|
2015-03-03 23:19:55 -06:00
|
|
|
Token::I32(2),
|
|
|
|
Token::I32(3),
|
|
|
|
Token::SeqEnd,
|
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
Vec::<isize>::new() => &[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::TupleStruct { name: "Anything", len: 0 },
|
2017-02-02 14:10:07 -06:00
|
|
|
Token::TupleStructEnd,
|
2015-03-20 10:47:33 -05:00
|
|
|
],
|
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] => &[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Seq { len: Some(0) },
|
2015-05-16 06:32:58 -05:00
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
[0; 0] => &[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Tuple { len: 0 },
|
2017-04-17 14:07:49 -05:00
|
|
|
Token::TupleEnd,
|
2016-02-23 07:15:44 -06:00
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
([0; 0], [1], [2, 3]) => &[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Seq { len: Some(3) },
|
|
|
|
Token::Seq { len: Some(0) },
|
2015-05-16 06:32:58 -05:00
|
|
|
Token::SeqEnd,
|
|
|
|
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Seq { len: Some(1) },
|
2015-05-16 06:32:58 -05:00
|
|
|
Token::I32(1),
|
|
|
|
Token::SeqEnd,
|
|
|
|
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Seq { len: Some(2) },
|
2015-05-16 06:32:58 -05:00
|
|
|
Token::I32(2),
|
|
|
|
Token::I32(3),
|
|
|
|
Token::SeqEnd,
|
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
([0; 0], [1], [2, 3]) => &[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Tuple { len: 3 },
|
|
|
|
Token::Tuple { len: 0 },
|
2017-04-17 14:07:49 -05:00
|
|
|
Token::TupleEnd,
|
2016-02-23 07:15:44 -06:00
|
|
|
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Tuple { len: 1 },
|
2016-02-23 07:15:44 -06:00
|
|
|
Token::I32(1),
|
2017-04-17 14:07:49 -05:00
|
|
|
Token::TupleEnd,
|
2016-02-23 07:15:44 -06:00
|
|
|
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Tuple { len: 2 },
|
2016-02-23 07:15:44 -06:00
|
|
|
Token::I32(2),
|
|
|
|
Token::I32(3),
|
2017-04-17 14:07:49 -05:00
|
|
|
Token::TupleEnd,
|
|
|
|
Token::TupleEnd,
|
2016-02-23 07:15:44 -06:00
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
[0; 0] => &[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::TupleStruct { name: "Anything", len: 0 },
|
2017-02-02 14:10:07 -06:00
|
|
|
Token::TupleStructEnd,
|
2015-05-16 06:32:58 -05:00
|
|
|
],
|
|
|
|
}
|
2015-03-03 23:19:55 -06:00
|
|
|
test_tuple {
|
2016-06-29 01:50:19 -05:00
|
|
|
(1,) => &[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Seq { len: Some(1) },
|
2015-03-03 23:19:55 -06:00
|
|
|
Token::I32(1),
|
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
(1, 2, 3) => &[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Seq { len: Some(3) },
|
2015-03-03 23:19:55 -06:00
|
|
|
Token::I32(1),
|
|
|
|
Token::I32(2),
|
|
|
|
Token::I32(3),
|
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
(1,) => &[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Tuple { len: 1 },
|
2016-02-23 07:15:44 -06:00
|
|
|
Token::I32(1),
|
|
|
|
Token::TupleEnd,
|
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
(1, 2, 3) => &[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Tuple { len: 3 },
|
2016-02-23 07:15:44 -06:00
|
|
|
Token::I32(1),
|
|
|
|
Token::I32(2),
|
|
|
|
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() => &[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Map { len: Some(0) },
|
2015-03-20 10:47:33 -05:00
|
|
|
Token::MapEnd,
|
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
btreemap![1 => 2] => &[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Map { len: Some(1) },
|
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] => &[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Map { len: Some(2) },
|
2015-03-03 23:19:55 -06:00
|
|
|
Token::I32(1),
|
|
|
|
Token::I32(2),
|
|
|
|
|
|
|
|
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]] => &[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Map { len: Some(2) },
|
2015-03-03 23:19:55 -06:00
|
|
|
Token::I32(1),
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Map { len: Some(0) },
|
2015-03-03 23:19:55 -06:00
|
|
|
Token::MapEnd,
|
|
|
|
|
|
|
|
Token::I32(2),
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Map { len: Some(2) },
|
2015-03-03 23:19:55 -06:00
|
|
|
Token::I32(3),
|
|
|
|
Token::I32(4),
|
|
|
|
|
|
|
|
Token::I32(5),
|
|
|
|
Token::I32(6),
|
|
|
|
Token::MapEnd,
|
|
|
|
Token::MapEnd,
|
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
BTreeMap::<isize, isize>::new() => &[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Struct { name: "Anything", len: 0 },
|
2017-02-02 14:10:07 -06:00
|
|
|
Token::StructEnd,
|
2015-03-20 10:47:33 -05:00
|
|
|
],
|
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() => &[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Map { len: Some(0) },
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::MapEnd,
|
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
hashmap![1 => 2] => &[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Map { len: Some(1) },
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::I32(1),
|
|
|
|
Token::I32(2),
|
|
|
|
Token::MapEnd,
|
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
hashmap![1 => 2, 3 => 4] => &[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Map { len: Some(2) },
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::I32(1),
|
|
|
|
Token::I32(2),
|
|
|
|
|
|
|
|
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]] => &[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Map { len: Some(2) },
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::I32(1),
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Map { len: Some(0) },
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::MapEnd,
|
|
|
|
|
|
|
|
Token::I32(2),
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Map { len: Some(2) },
|
2015-03-20 22:35:01 -05:00
|
|
|
Token::I32(3),
|
|
|
|
Token::I32(4),
|
|
|
|
|
|
|
|
Token::I32(5),
|
|
|
|
Token::I32(6),
|
|
|
|
Token::MapEnd,
|
|
|
|
Token::MapEnd,
|
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
HashMap::<isize, isize>::new() => &[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Struct { name: "Anything", len: 0 },
|
2017-02-02 14:10:07 -06:00
|
|
|
Token::StructEnd,
|
2015-03-20 22:35:01 -05:00
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
hashmap![FnvHasher @ 1 => 2, 3 => 4] => &[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Map { len: Some(2) },
|
2016-06-11 02:43:02 -05:00
|
|
|
Token::I32(1),
|
|
|
|
Token::I32(2),
|
|
|
|
|
|
|
|
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 } => &[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Map { len: Some(3) },
|
2016-03-07 01:27:12 -06:00
|
|
|
Token::Str("a"),
|
|
|
|
Token::I32(1),
|
|
|
|
|
|
|
|
Token::Str("b"),
|
|
|
|
Token::I32(2),
|
|
|
|
Token::MapEnd,
|
|
|
|
],
|
2017-09-05 23:55:06 -05:00
|
|
|
Struct { a: 1, b: 2, c: 0 } => &[
|
|
|
|
Token::Map { len: Some(3) },
|
|
|
|
Token::U32(0),
|
|
|
|
Token::I32(1),
|
|
|
|
|
|
|
|
Token::U32(1),
|
|
|
|
Token::I32(2),
|
|
|
|
Token::MapEnd,
|
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
Struct { a: 1, b: 2, c: 0 } => &[
|
2017-11-12 11:52:39 -06:00
|
|
|
Token::Struct { name: "Struct", len: 2 },
|
2016-03-07 01:27:12 -06:00
|
|
|
Token::Str("a"),
|
|
|
|
Token::I32(1),
|
|
|
|
|
|
|
|
Token::Str("b"),
|
|
|
|
Token::I32(2),
|
|
|
|
Token::StructEnd,
|
|
|
|
],
|
2016-06-29 01:50:19 -05:00
|
|
|
Struct { a: 1, b: 2, c: 0 } => &[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Seq { len: Some(3) },
|
2016-03-07 01:27:12 -06:00
|
|
|
Token::I32(1),
|
|
|
|
Token::I32(2),
|
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
|
|
|
}
|
|
|
|
test_struct_with_skip {
|
2016-06-29 01:50:19 -05:00
|
|
|
Struct { a: 1, b: 2, c: 0 } => &[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Map { len: Some(3) },
|
2015-03-03 23:19:55 -06:00
|
|
|
Token::Str("a"),
|
|
|
|
Token::I32(1),
|
|
|
|
|
|
|
|
Token::Str("b"),
|
|
|
|
Token::I32(2),
|
|
|
|
|
|
|
|
Token::Str("c"),
|
|
|
|
Token::I32(3),
|
2016-03-07 01:27:12 -06:00
|
|
|
|
|
|
|
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 } => &[
|
2017-11-12 11:52:39 -06:00
|
|
|
Token::Struct { name: "Struct", len: 2 },
|
2015-03-03 23:19:55 -06:00
|
|
|
Token::Str("a"),
|
|
|
|
Token::I32(1),
|
|
|
|
|
|
|
|
Token::Str("b"),
|
|
|
|
Token::I32(2),
|
|
|
|
|
|
|
|
Token::Str("c"),
|
|
|
|
Token::I32(3),
|
2016-03-07 01:27:12 -06:00
|
|
|
|
|
|
|
Token::Str("d"),
|
|
|
|
Token::I32(4),
|
2016-02-13 00:05:02 -06:00
|
|
|
Token::StructEnd,
|
2015-03-03 23:19:55 -06:00
|
|
|
],
|
|
|
|
}
|
2017-01-13 03:12:31 -06:00
|
|
|
test_struct_skip_all {
|
|
|
|
StructSkipAll { a: 0 } => &[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Struct { name: "StructSkipAll", len: 0 },
|
2017-01-13 03:12:31 -06:00
|
|
|
Token::StructEnd,
|
|
|
|
],
|
|
|
|
StructSkipAll { a: 0 } => &[
|
2017-11-12 11:52:39 -06:00
|
|
|
Token::Struct { name: "StructSkipAll", len: 0 },
|
2017-01-13 03:12:31 -06:00
|
|
|
Token::Str("a"),
|
|
|
|
Token::I32(1),
|
|
|
|
|
|
|
|
Token::Str("b"),
|
|
|
|
Token::I32(2),
|
|
|
|
Token::StructEnd,
|
|
|
|
],
|
|
|
|
}
|
2017-12-06 14:07:16 -06:00
|
|
|
test_struct_skip_default {
|
|
|
|
StructSkipDefault { a: 16 } => &[
|
|
|
|
Token::Struct { name: "StructSkipDefault", len: 0 },
|
|
|
|
Token::StructEnd,
|
|
|
|
],
|
|
|
|
}
|
2017-01-13 03:12:31 -06:00
|
|
|
test_struct_skip_all_deny_unknown {
|
|
|
|
StructSkipAllDenyUnknown { a: 0 } => &[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Struct { name: "StructSkipAllDenyUnknown", len: 0 },
|
2017-01-13 03:12:31 -06:00
|
|
|
Token::StructEnd,
|
|
|
|
],
|
|
|
|
}
|
2017-02-20 15:34:52 -06:00
|
|
|
test_struct_default {
|
2017-02-20 19:03:38 -06:00
|
|
|
StructDefault { a: 50, b: "overwritten".to_string() } => &[
|
2017-11-12 11:52:39 -06:00
|
|
|
Token::Struct { name: "StructDefault", len: 2 },
|
2017-02-20 15:34:52 -06:00
|
|
|
Token::Str("a"),
|
|
|
|
Token::I32(50),
|
|
|
|
|
|
|
|
Token::Str("b"),
|
2017-04-05 02:17:50 -05:00
|
|
|
Token::String("overwritten"),
|
2017-02-20 15:34:52 -06:00
|
|
|
Token::StructEnd,
|
|
|
|
],
|
2017-02-20 19:03:38 -06:00
|
|
|
StructDefault { a: 100, b: "default".to_string() } => &[
|
2017-11-12 11:52:39 -06:00
|
|
|
Token::Struct { name: "StructDefault", len: 2 },
|
2017-02-20 15:34:52 -06:00
|
|
|
Token::StructEnd,
|
|
|
|
],
|
|
|
|
}
|
2015-03-16 00:04:17 -05:00
|
|
|
test_enum_unit {
|
2016-06-29 01:50:19 -05:00
|
|
|
Enum::Unit => &[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::UnitVariant { name: "Enum", variant: "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) => &[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::NewtypeVariant { name: "Enum", variant: "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) => &[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::TupleVariant { name: "Enum", variant: "Seq", len: 3 },
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::I32(1),
|
|
|
|
Token::I32(2),
|
|
|
|
Token::I32(3),
|
2017-04-05 12:40:14 -05:00
|
|
|
Token::TupleVariantEnd,
|
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 } => &[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::StructVariant { name: "Enum", variant: "Map", len: 3 },
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::Str("a"),
|
|
|
|
Token::I32(1),
|
2015-03-03 23:19:55 -06:00
|
|
|
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::Str("b"),
|
|
|
|
Token::I32(2),
|
2015-03-03 23:19:55 -06:00
|
|
|
|
2015-08-27 22:01:09 -05:00
|
|
|
Token::Str("c"),
|
|
|
|
Token::I32(3),
|
2017-04-05 12:40:14 -05:00
|
|
|
Token::StructVariantEnd,
|
2015-03-03 23:19:55 -06:00
|
|
|
],
|
2015-07-30 10:05:41 -05:00
|
|
|
}
|
2017-01-18 01:52:06 -06:00
|
|
|
test_enum_unit_usize {
|
|
|
|
Enum::Unit => &[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Enum { name: "Enum" },
|
2017-01-25 10:59:34 -06:00
|
|
|
Token::U32(0),
|
2017-01-18 01:52:06 -06:00
|
|
|
Token::Unit,
|
|
|
|
],
|
|
|
|
}
|
2017-01-18 23:11:51 -06:00
|
|
|
test_enum_unit_bytes {
|
|
|
|
Enum::Unit => &[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Enum { name: "Enum" },
|
2017-01-18 23:11:51 -06:00
|
|
|
Token::Bytes(b"Unit"),
|
|
|
|
Token::Unit,
|
|
|
|
],
|
|
|
|
}
|
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]) => &[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Seq { len: Some(3) },
|
2016-04-17 22:59:26 -05:00
|
|
|
Token::I32(0),
|
|
|
|
Token::I32(1),
|
|
|
|
Token::I32(2),
|
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
|
|
|
}
|
2016-08-03 19:15:14 -05:00
|
|
|
test_duration {
|
|
|
|
Duration::new(1, 2) => &[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Struct { name: "Duration", len: 2 },
|
2016-08-03 19:15:14 -05:00
|
|
|
Token::Str("secs"),
|
|
|
|
Token::U64(1),
|
|
|
|
|
|
|
|
Token::Str("nanos"),
|
|
|
|
Token::U32(2),
|
|
|
|
Token::StructEnd,
|
|
|
|
],
|
|
|
|
Duration::new(1, 2) => &[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Seq { len: Some(2) },
|
2016-08-03 19:15:14 -05:00
|
|
|
Token::I64(1),
|
|
|
|
Token::I64(2),
|
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
|
|
|
}
|
2017-07-11 23:01:40 -05:00
|
|
|
test_system_time {
|
|
|
|
UNIX_EPOCH + Duration::new(1, 2) => &[
|
|
|
|
Token::Struct { name: "SystemTime", len: 2 },
|
|
|
|
Token::Str("secs_since_epoch"),
|
|
|
|
Token::U64(1),
|
|
|
|
|
|
|
|
Token::Str("nanos_since_epoch"),
|
|
|
|
Token::U32(2),
|
|
|
|
Token::StructEnd,
|
|
|
|
],
|
|
|
|
UNIX_EPOCH + Duration::new(1, 2) => &[
|
|
|
|
Token::Seq { len: Some(2) },
|
|
|
|
Token::I64(1),
|
|
|
|
Token::I64(2),
|
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
|
|
|
}
|
2017-03-09 13:39:27 -06:00
|
|
|
test_range {
|
|
|
|
1u32..2u32 => &[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Struct { name: "Range", len: 2 },
|
2017-03-09 13:39:27 -06:00
|
|
|
Token::Str("start"),
|
|
|
|
Token::U32(1),
|
|
|
|
|
|
|
|
Token::Str("end"),
|
|
|
|
Token::U32(2),
|
|
|
|
Token::StructEnd,
|
|
|
|
],
|
|
|
|
1u32..2u32 => &[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Seq { len: Some(2) },
|
2017-03-09 13:39:27 -06:00
|
|
|
Token::U64(1),
|
|
|
|
Token::U64(2),
|
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
|
|
|
}
|
2018-08-05 08:45:50 -05:00
|
|
|
test_range_inclusive {
|
|
|
|
1u32..=2u32 => &[
|
|
|
|
Token::Struct { name: "RangeInclusive", len: 2 },
|
|
|
|
Token::Str("start"),
|
|
|
|
Token::U32(1),
|
|
|
|
|
|
|
|
Token::Str("end"),
|
|
|
|
Token::U32(2),
|
|
|
|
Token::StructEnd,
|
|
|
|
],
|
|
|
|
1u32..=2u32 => &[
|
|
|
|
Token::Seq { len: Some(2) },
|
|
|
|
Token::U64(1),
|
|
|
|
Token::U64(2),
|
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
|
|
|
}
|
2017-05-10 11:28:41 -05:00
|
|
|
test_path {
|
|
|
|
Path::new("/usr/local/lib") => &[
|
|
|
|
Token::BorrowedStr("/usr/local/lib"),
|
|
|
|
],
|
|
|
|
}
|
2016-01-28 11:45:38 -06:00
|
|
|
test_path_buf {
|
2016-06-29 01:50:19 -05:00
|
|
|
PathBuf::from("/usr/local/lib") => &[
|
2017-04-05 02:17:50 -05:00
|
|
|
Token::String("/usr/local/lib"),
|
2016-01-28 11:45:38 -06:00
|
|
|
],
|
|
|
|
}
|
2017-03-03 17:06:04 -06:00
|
|
|
test_cstring {
|
|
|
|
CString::new("abc").unwrap() => &[
|
|
|
|
Token::Bytes(b"abc"),
|
|
|
|
],
|
|
|
|
}
|
2017-09-04 12:56:40 -05:00
|
|
|
test_rc {
|
|
|
|
Rc::new(true) => &[
|
|
|
|
Token::Bool(true),
|
|
|
|
],
|
|
|
|
}
|
2018-05-07 13:16:40 -05:00
|
|
|
test_rc_weak_some {
|
|
|
|
SkipPartialEq(RcWeak::<bool>::new()) => &[
|
|
|
|
Token::Some,
|
|
|
|
Token::Bool(true),
|
|
|
|
],
|
|
|
|
}
|
|
|
|
test_rc_weak_none {
|
|
|
|
SkipPartialEq(RcWeak::<bool>::new()) => &[
|
|
|
|
Token::None,
|
|
|
|
],
|
|
|
|
}
|
2017-09-04 12:56:40 -05:00
|
|
|
test_arc {
|
|
|
|
Arc::new(true) => &[
|
|
|
|
Token::Bool(true),
|
|
|
|
],
|
|
|
|
}
|
2018-05-07 13:16:40 -05:00
|
|
|
test_arc_weak_some {
|
|
|
|
SkipPartialEq(ArcWeak::<bool>::new()) => &[
|
|
|
|
Token::Some,
|
|
|
|
Token::Bool(true),
|
|
|
|
],
|
|
|
|
}
|
|
|
|
test_arc_weak_none {
|
|
|
|
SkipPartialEq(ArcWeak::<bool>::new()) => &[
|
|
|
|
Token::None,
|
|
|
|
],
|
|
|
|
}
|
2017-10-31 11:32:58 -05:00
|
|
|
test_wrapping {
|
|
|
|
Wrapping(1usize) => &[
|
|
|
|
Token::U32(1),
|
|
|
|
],
|
|
|
|
Wrapping(1usize) => &[
|
|
|
|
Token::U64(1),
|
|
|
|
],
|
|
|
|
}
|
2018-06-03 02:27:26 -05:00
|
|
|
test_rc_dst {
|
|
|
|
Rc::<str>::from("s") => &[
|
|
|
|
Token::Str("s"),
|
|
|
|
],
|
|
|
|
Rc::<[bool]>::from(&[true][..]) => &[
|
|
|
|
Token::Seq { len: Some(1) },
|
|
|
|
Token::Bool(true),
|
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
|
|
|
}
|
|
|
|
test_arc_dst {
|
|
|
|
Arc::<str>::from("s") => &[
|
|
|
|
Token::Str("s"),
|
|
|
|
],
|
|
|
|
Arc::<[bool]>::from(&[true][..]) => &[
|
|
|
|
Token::Seq { len: Some(1) },
|
|
|
|
Token::Bool(true),
|
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
|
|
|
}
|
2017-09-04 12:56:40 -05:00
|
|
|
}
|
|
|
|
|
2017-10-18 01:15:35 -05:00
|
|
|
declare_tests! {
|
2017-11-03 10:12:43 -05:00
|
|
|
readable
|
|
|
|
|
2017-10-18 01:15:35 -05:00
|
|
|
test_net_ipv4addr_readable {
|
|
|
|
"1.2.3.4".parse::<net::Ipv4Addr>().unwrap() => &[Token::Str("1.2.3.4")],
|
|
|
|
}
|
|
|
|
test_net_ipv6addr_readable {
|
|
|
|
"::1".parse::<net::Ipv6Addr>().unwrap() => &[Token::Str("::1")],
|
|
|
|
}
|
|
|
|
test_net_ipaddr_readable {
|
|
|
|
"1.2.3.4".parse::<net::IpAddr>().unwrap() => &[Token::Str("1.2.3.4")],
|
|
|
|
}
|
|
|
|
test_net_socketaddr_readable {
|
|
|
|
"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")],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
declare_tests! {
|
2017-11-03 10:12:43 -05:00
|
|
|
compact
|
|
|
|
|
2017-10-18 01:15:35 -05:00
|
|
|
test_net_ipv4addr_compact {
|
2017-09-11 08:54:49 -05:00
|
|
|
net::Ipv4Addr::from(*b"1234") => &seq![
|
|
|
|
Token::Tuple { len: 4 },
|
|
|
|
seq b"1234".iter().map(|&b| Token::U8(b)),
|
|
|
|
Token::TupleEnd
|
|
|
|
],
|
|
|
|
}
|
2017-10-18 01:15:35 -05:00
|
|
|
test_net_ipv6addr_compact {
|
2017-09-11 08:54:49 -05:00
|
|
|
net::Ipv6Addr::from(*b"1234567890123456") => &seq![
|
|
|
|
Token::Tuple { len: 4 },
|
|
|
|
seq b"1234567890123456".iter().map(|&b| Token::U8(b)),
|
|
|
|
Token::TupleEnd
|
|
|
|
],
|
2017-10-18 01:15:35 -05:00
|
|
|
}
|
|
|
|
test_net_ipaddr_compact {
|
|
|
|
net::IpAddr::from(*b"1234") => &seq![
|
|
|
|
Token::NewtypeVariant { name: "IpAddr", variant: "V4" },
|
2017-09-11 08:54:49 -05:00
|
|
|
|
2017-10-18 01:15:35 -05:00
|
|
|
Token::Tuple { len: 4 },
|
|
|
|
seq b"1234".iter().map(|&b| Token::U8(b)),
|
|
|
|
Token::TupleEnd
|
|
|
|
],
|
2017-09-11 08:54:49 -05:00
|
|
|
}
|
2017-10-18 01:15:35 -05:00
|
|
|
test_net_socketaddr_compact {
|
2017-09-11 08:54:49 -05:00
|
|
|
net::SocketAddr::from((*b"1234567890123456", 1234)) => &seq![
|
2017-09-14 09:54:47 -05:00
|
|
|
Token::NewtypeVariant { name: "SocketAddr", variant: "V6" },
|
|
|
|
|
2017-09-11 08:54:49 -05:00
|
|
|
Token::Tuple { len: 2 },
|
|
|
|
|
|
|
|
Token::Tuple { len: 16 },
|
|
|
|
seq b"1234567890123456".iter().map(|&b| Token::U8(b)),
|
|
|
|
Token::TupleEnd,
|
|
|
|
|
|
|
|
Token::U16(1234),
|
|
|
|
Token::TupleEnd
|
|
|
|
],
|
|
|
|
net::SocketAddr::from((*b"1234", 1234)) => &seq![
|
2017-09-14 09:54:47 -05:00
|
|
|
Token::NewtypeVariant { name: "SocketAddr", variant: "V4" },
|
|
|
|
|
2017-09-11 08:54:49 -05:00
|
|
|
Token::Tuple { len: 2 },
|
|
|
|
|
|
|
|
Token::Tuple { len: 4 },
|
|
|
|
seq b"1234".iter().map(|&b| Token::U8(b)),
|
|
|
|
Token::TupleEnd,
|
|
|
|
|
|
|
|
Token::U16(1234),
|
|
|
|
Token::TupleEnd
|
|
|
|
],
|
|
|
|
net::SocketAddrV4::new(net::Ipv4Addr::from(*b"1234"), 1234) => &seq![
|
|
|
|
Token::Tuple { len: 2 },
|
|
|
|
|
|
|
|
Token::Tuple { len: 4 },
|
|
|
|
seq b"1234".iter().map(|&b| Token::U8(b)),
|
|
|
|
Token::TupleEnd,
|
|
|
|
|
|
|
|
Token::U16(1234),
|
|
|
|
Token::TupleEnd
|
|
|
|
],
|
|
|
|
net::SocketAddrV6::new(net::Ipv6Addr::from(*b"1234567890123456"), 1234, 0, 0) => &seq![
|
|
|
|
Token::Tuple { len: 2 },
|
|
|
|
|
|
|
|
Token::Tuple { len: 16 },
|
|
|
|
seq b"1234567890123456".iter().map(|&b| Token::U8(b)),
|
|
|
|
Token::TupleEnd,
|
|
|
|
|
|
|
|
Token::U16(1234),
|
|
|
|
Token::TupleEnd
|
|
|
|
],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-03 02:15:05 -05:00
|
|
|
#[cfg(feature = "unstable")]
|
|
|
|
declare_tests! {
|
|
|
|
test_never_result {
|
|
|
|
Ok::<u8, !>(0) => &[
|
|
|
|
Token::NewtypeVariant { name: "Result", variant: "Ok" },
|
|
|
|
Token::U8(0),
|
|
|
|
],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-27 11:15:22 -05:00
|
|
|
#[cfg(unix)]
|
|
|
|
#[test]
|
|
|
|
fn test_osstring() {
|
|
|
|
use std::os::unix::ffi::OsStringExt;
|
|
|
|
|
|
|
|
let value = OsString::from_vec(vec![1, 2, 3]);
|
|
|
|
let tokens = [
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Enum { name: "OsString" },
|
2017-03-27 11:15:22 -05:00
|
|
|
Token::Str("Unix"),
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Seq { len: Some(2) },
|
2017-04-13 14:28:23 -05:00
|
|
|
Token::U8(1),
|
|
|
|
Token::U8(2),
|
|
|
|
Token::U8(3),
|
2017-03-27 11:15:22 -05:00
|
|
|
Token::SeqEnd,
|
|
|
|
];
|
|
|
|
|
|
|
|
assert_de_tokens(&value, &tokens);
|
2017-10-18 01:09:50 -05:00
|
|
|
assert_de_tokens_ignore(&tokens);
|
2017-03-27 11:15:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(windows)]
|
|
|
|
#[test]
|
|
|
|
fn test_osstring() {
|
|
|
|
use std::os::windows::ffi::OsStringExt;
|
|
|
|
|
|
|
|
let value = OsString::from_wide(&[1, 2, 3]);
|
|
|
|
let tokens = [
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Enum { name: "OsString" },
|
2017-03-27 11:15:22 -05:00
|
|
|
Token::Str("Windows"),
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Seq { len: Some(2) },
|
2017-04-13 14:28:23 -05:00
|
|
|
Token::U16(1),
|
|
|
|
Token::U16(2),
|
|
|
|
Token::U16(3),
|
2017-03-27 11:15:22 -05:00
|
|
|
Token::SeqEnd,
|
|
|
|
];
|
|
|
|
|
|
|
|
assert_de_tokens(&value, &tokens);
|
2017-10-18 01:09:50 -05:00
|
|
|
assert_de_tokens_ignore(&tokens);
|
2017-03-27 11:15:22 -05:00
|
|
|
}
|
|
|
|
|
2017-03-08 22:13:28 -06:00
|
|
|
#[test]
|
|
|
|
fn test_cstr() {
|
2017-04-13 14:28:23 -05:00
|
|
|
assert_de_tokens::<Box<CStr>>(
|
|
|
|
&CString::new("abc").unwrap().into_boxed_c_str(),
|
|
|
|
&[Token::Bytes(b"abc")],
|
|
|
|
);
|
2017-03-08 22:13:28 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_cstr_internal_null() {
|
|
|
|
assert_de_tokens_error::<Box<CStr>>(
|
2017-04-13 14:28:23 -05:00
|
|
|
&[Token::Bytes(b"a\0c")],
|
2017-04-19 13:38:57 -05:00
|
|
|
"nul byte found in provided data at position: 1",
|
2017-03-08 22:13:28 -06:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_cstr_internal_null_end() {
|
|
|
|
assert_de_tokens_error::<Box<CStr>>(
|
2017-04-13 14:28:23 -05:00
|
|
|
&[Token::Bytes(b"ac\0")],
|
2017-04-19 13:38:57 -05:00
|
|
|
"nul byte found in provided data at position: 2",
|
2017-03-08 22:13:28 -06:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-06-03 02:15:05 -05:00
|
|
|
#[cfg(feature = "unstable")]
|
|
|
|
#[test]
|
|
|
|
fn test_never_type() {
|
|
|
|
assert_de_tokens_error::<!>(&[], "cannot deserialize `!`");
|
|
|
|
|
|
|
|
assert_de_tokens_error::<Result<u8, !>>(
|
|
|
|
&[Token::NewtypeVariant {
|
|
|
|
name: "Result",
|
|
|
|
variant: "Err",
|
|
|
|
}],
|
|
|
|
"cannot deserialize `!`",
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-03-07 01:27:12 -06:00
|
|
|
declare_error_tests! {
|
2017-01-13 01:17:45 -06:00
|
|
|
test_unknown_field<StructDenyUnknown> {
|
|
|
|
&[
|
2017-11-12 11:52:39 -06:00
|
|
|
Token::Struct { name: "StructDenyUnknown", len: 1 },
|
2017-01-13 01:17:45 -06:00
|
|
|
Token::Str("a"),
|
|
|
|
Token::I32(0),
|
|
|
|
|
|
|
|
Token::Str("d"),
|
|
|
|
],
|
2017-04-19 13:38:57 -05:00
|
|
|
"unknown field `d`, expected `a`",
|
2017-01-13 01:17:45 -06:00
|
|
|
}
|
|
|
|
test_skipped_field_is_unknown<StructDenyUnknown> {
|
|
|
|
&[
|
2017-11-12 11:52:39 -06:00
|
|
|
Token::Struct { name: "StructDenyUnknown", len: 1 },
|
2017-01-13 01:17:45 -06:00
|
|
|
Token::Str("b"),
|
|
|
|
],
|
2017-04-19 13:38:57 -05:00
|
|
|
"unknown field `b`, expected `a`",
|
2017-01-13 01:17:45 -06:00
|
|
|
}
|
2017-01-13 03:12:31 -06:00
|
|
|
test_skip_all_deny_unknown<StructSkipAllDenyUnknown> {
|
|
|
|
&[
|
2017-11-12 11:52:39 -06:00
|
|
|
Token::Struct { name: "StructSkipAllDenyUnknown", len: 0 },
|
2017-01-13 03:12:31 -06:00
|
|
|
Token::Str("a"),
|
|
|
|
],
|
2017-04-19 13:38:57 -05:00
|
|
|
"unknown field `a`, there are no fields",
|
2017-01-13 03:12:31 -06:00
|
|
|
}
|
2016-03-07 01:27:12 -06:00
|
|
|
test_unknown_variant<Enum> {
|
2016-06-29 01:50:19 -05:00
|
|
|
&[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::UnitVariant { name: "Enum", variant: "Foo" },
|
2016-02-21 18:26:52 -06:00
|
|
|
],
|
2017-04-19 13:38:57 -05:00
|
|
|
"unknown variant `Foo`, expected one of `Unit`, `Simple`, `Seq`, `Map`",
|
2016-03-07 01:27:12 -06:00
|
|
|
}
|
2016-12-15 08:23:52 -06:00
|
|
|
test_enum_skipped_variant<Enum> {
|
|
|
|
&[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::UnitVariant { name: "Enum", variant: "Skipped" },
|
2016-12-15 08:23:52 -06:00
|
|
|
],
|
2017-04-19 13:38:57 -05:00
|
|
|
"unknown variant `Skipped`, expected one of `Unit`, `Simple`, `Seq`, `Map`",
|
2016-12-15 08:23:52 -06:00
|
|
|
}
|
2017-01-13 03:14:03 -06:00
|
|
|
test_enum_skip_all<EnumSkipAll> {
|
|
|
|
&[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::UnitVariant { name: "EnumSkipAll", variant: "Skipped" },
|
2017-01-13 03:14:03 -06:00
|
|
|
],
|
2017-04-19 13:38:57 -05:00
|
|
|
"unknown variant `Skipped`, there are no variants",
|
2016-03-07 01:27:12 -06:00
|
|
|
}
|
2016-05-10 11:52:51 -05:00
|
|
|
test_duplicate_field_struct<Struct> {
|
2016-06-29 01:50:19 -05:00
|
|
|
&[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Map { len: Some(3) },
|
2016-05-10 11:52:51 -05:00
|
|
|
Token::Str("a"),
|
|
|
|
Token::I32(1),
|
|
|
|
|
|
|
|
Token::Str("a"),
|
|
|
|
],
|
2017-04-19 13:38:57 -05:00
|
|
|
"duplicate field `a`",
|
2016-05-10 11:52:51 -05:00
|
|
|
}
|
|
|
|
test_duplicate_field_enum<Enum> {
|
2016-06-29 01:50:19 -05:00
|
|
|
&[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::StructVariant { name: "Enum", variant: "Map", len: 3 },
|
2016-05-10 11:52:51 -05:00
|
|
|
Token::Str("a"),
|
|
|
|
Token::I32(1),
|
|
|
|
|
|
|
|
Token::Str("a"),
|
|
|
|
],
|
2017-04-19 13:38:57 -05:00
|
|
|
"duplicate field `a`",
|
2016-05-10 11:52:51 -05:00
|
|
|
}
|
2017-01-18 01:52:06 -06:00
|
|
|
test_enum_out_of_range<Enum> {
|
2017-01-09 02:43:13 -06:00
|
|
|
&[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Enum { name: "Enum" },
|
2017-01-25 10:59:34 -06:00
|
|
|
Token::U32(4),
|
2017-01-09 02:43:13 -06:00
|
|
|
Token::Unit,
|
|
|
|
],
|
2017-04-19 13:38:57 -05:00
|
|
|
"invalid value: integer `4`, expected variant index 0 <= i < 4",
|
2017-01-09 02:43:13 -06:00
|
|
|
}
|
2017-01-28 17:00:54 -06:00
|
|
|
test_short_tuple<(u8, u8, u8)> {
|
|
|
|
&[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Tuple { len: 1 },
|
2017-01-28 17:00:54 -06:00
|
|
|
Token::U8(1),
|
|
|
|
Token::TupleEnd,
|
|
|
|
],
|
2017-04-19 13:38:57 -05:00
|
|
|
"invalid length 1, expected a tuple of size 3",
|
2017-01-28 17:00:54 -06:00
|
|
|
}
|
|
|
|
test_short_array<[u8; 3]> {
|
|
|
|
&[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Seq { len: Some(1) },
|
2017-01-28 17:00:54 -06:00
|
|
|
Token::U8(1),
|
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
2017-04-19 13:38:57 -05:00
|
|
|
"invalid length 1, expected an array of length 3",
|
2017-01-28 17:00:54 -06:00
|
|
|
}
|
2017-03-03 17:06:04 -06:00
|
|
|
test_cstring_internal_null<CString> {
|
|
|
|
&[
|
|
|
|
Token::Bytes(b"a\0c"),
|
|
|
|
],
|
2017-04-19 13:38:57 -05:00
|
|
|
"nul byte found in provided data at position: 1",
|
2017-03-03 17:06:04 -06:00
|
|
|
}
|
|
|
|
test_cstring_internal_null_end<CString> {
|
|
|
|
&[
|
|
|
|
Token::Bytes(b"ac\0"),
|
|
|
|
],
|
2017-04-19 13:38:57 -05:00
|
|
|
"nul byte found in provided data at position: 2",
|
2017-03-03 17:06:04 -06:00
|
|
|
}
|
2017-04-04 20:50:40 -05:00
|
|
|
test_unit_from_empty_seq<()> {
|
|
|
|
&[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Seq { len: Some(0) },
|
2017-04-04 20:50:40 -05:00
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
2017-04-19 13:38:57 -05:00
|
|
|
"invalid type: sequence, expected unit",
|
2017-04-04 20:50:40 -05:00
|
|
|
}
|
|
|
|
test_unit_from_empty_seq_without_len<()> {
|
|
|
|
&[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Seq { len: None },
|
2017-04-04 20:50:40 -05:00
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
2017-04-19 13:38:57 -05:00
|
|
|
"invalid type: sequence, expected unit",
|
2017-04-04 20:50:40 -05:00
|
|
|
}
|
|
|
|
test_unit_from_tuple_struct<()> {
|
|
|
|
&[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::TupleStruct { name: "Anything", len: 0 },
|
2017-04-04 20:50:40 -05:00
|
|
|
Token::TupleStructEnd,
|
|
|
|
],
|
2017-04-19 13:38:57 -05:00
|
|
|
"invalid type: sequence, expected unit",
|
2017-04-04 20:50:40 -05:00
|
|
|
}
|
|
|
|
test_string_from_unit<String> {
|
|
|
|
&[
|
|
|
|
Token::Unit,
|
|
|
|
],
|
2017-04-19 13:38:57 -05:00
|
|
|
"invalid type: unit value, expected a string",
|
2017-04-04 20:50:40 -05:00
|
|
|
}
|
|
|
|
test_btreeset_from_unit<BTreeSet<isize>> {
|
|
|
|
&[
|
|
|
|
Token::Unit,
|
|
|
|
],
|
2017-04-19 13:38:57 -05:00
|
|
|
"invalid type: unit value, expected a sequence",
|
2017-04-04 20:50:40 -05:00
|
|
|
}
|
|
|
|
test_btreeset_from_unit_struct<BTreeSet<isize>> {
|
|
|
|
&[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::UnitStruct { name: "Anything" },
|
2017-04-04 20:50:40 -05:00
|
|
|
],
|
2017-04-19 13:38:57 -05:00
|
|
|
"invalid type: unit value, expected a sequence",
|
2017-04-04 20:50:40 -05:00
|
|
|
}
|
|
|
|
test_hashset_from_unit<HashSet<isize>> {
|
|
|
|
&[
|
|
|
|
Token::Unit,
|
|
|
|
],
|
2017-04-19 13:38:57 -05:00
|
|
|
"invalid type: unit value, expected a sequence",
|
2017-04-04 20:50:40 -05:00
|
|
|
}
|
|
|
|
test_hashset_from_unit_struct<HashSet<isize>> {
|
|
|
|
&[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::UnitStruct { name: "Anything" },
|
2017-04-04 20:50:40 -05:00
|
|
|
],
|
2017-04-19 13:38:57 -05:00
|
|
|
"invalid type: unit value, expected a sequence",
|
2017-04-04 20:50:40 -05:00
|
|
|
}
|
|
|
|
test_vec_from_unit<Vec<isize>> {
|
|
|
|
&[
|
|
|
|
Token::Unit,
|
|
|
|
],
|
2017-04-19 13:38:57 -05:00
|
|
|
"invalid type: unit value, expected a sequence",
|
2017-04-04 20:50:40 -05:00
|
|
|
}
|
|
|
|
test_vec_from_unit_struct<Vec<isize>> {
|
|
|
|
&[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::UnitStruct { name: "Anything" },
|
2017-04-04 20:50:40 -05:00
|
|
|
],
|
2017-04-19 13:38:57 -05:00
|
|
|
"invalid type: unit value, expected a sequence",
|
2017-04-04 20:50:40 -05:00
|
|
|
}
|
|
|
|
test_zero_array_from_unit<[isize; 0]> {
|
|
|
|
&[
|
|
|
|
Token::Unit,
|
|
|
|
],
|
2017-04-19 13:38:57 -05:00
|
|
|
"invalid type: unit value, expected an empty array",
|
2017-04-04 20:50:40 -05:00
|
|
|
}
|
|
|
|
test_zero_array_from_unit_struct<[isize; 0]> {
|
|
|
|
&[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::UnitStruct { name: "Anything" },
|
2017-04-04 20:50:40 -05:00
|
|
|
],
|
2017-04-19 13:38:57 -05:00
|
|
|
"invalid type: unit value, expected an empty array",
|
2017-04-04 20:50:40 -05:00
|
|
|
}
|
|
|
|
test_btreemap_from_unit<BTreeMap<isize, isize>> {
|
|
|
|
&[
|
|
|
|
Token::Unit,
|
|
|
|
],
|
2017-04-19 13:38:57 -05:00
|
|
|
"invalid type: unit value, expected a map",
|
2017-04-04 20:50:40 -05:00
|
|
|
}
|
|
|
|
test_btreemap_from_unit_struct<BTreeMap<isize, isize>> {
|
|
|
|
&[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::UnitStruct { name: "Anything" },
|
2017-04-04 20:50:40 -05:00
|
|
|
],
|
2017-04-19 13:38:57 -05:00
|
|
|
"invalid type: unit value, expected a map",
|
2017-04-04 20:50:40 -05:00
|
|
|
}
|
|
|
|
test_hashmap_from_unit<HashMap<isize, isize>> {
|
|
|
|
&[
|
|
|
|
Token::Unit,
|
|
|
|
],
|
2017-04-19 13:38:57 -05:00
|
|
|
"invalid type: unit value, expected a map",
|
2017-04-04 20:50:40 -05:00
|
|
|
}
|
|
|
|
test_hashmap_from_unit_struct<HashMap<isize, isize>> {
|
|
|
|
&[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::UnitStruct { name: "Anything" },
|
2017-04-04 20:50:40 -05:00
|
|
|
],
|
2017-04-19 13:38:57 -05:00
|
|
|
"invalid type: unit value, expected a map",
|
2017-04-04 20:50:40 -05:00
|
|
|
}
|
|
|
|
test_bool_from_string<bool> {
|
|
|
|
&[
|
|
|
|
Token::Str("false"),
|
|
|
|
],
|
2017-04-19 13:38:57 -05:00
|
|
|
"invalid type: string \"false\", expected a boolean",
|
2017-04-04 20:50:40 -05:00
|
|
|
}
|
|
|
|
test_number_from_string<isize> {
|
|
|
|
&[
|
|
|
|
Token::Str("1"),
|
|
|
|
],
|
2017-04-19 13:38:57 -05:00
|
|
|
"invalid type: string \"1\", expected isize",
|
2017-04-04 20:50:40 -05:00
|
|
|
}
|
2017-04-05 13:22:47 -05:00
|
|
|
test_integer_from_float<isize> {
|
|
|
|
&[
|
|
|
|
Token::F32(0.0),
|
|
|
|
],
|
2017-04-19 13:38:57 -05:00
|
|
|
"invalid type: floating point `0`, expected isize",
|
2017-04-05 13:22:47 -05:00
|
|
|
}
|
2017-04-09 15:08:05 -05:00
|
|
|
test_unit_struct_from_seq<UnitStruct> {
|
|
|
|
&[
|
2017-04-19 15:06:31 -05:00
|
|
|
Token::Seq { len: Some(0) },
|
2017-04-09 15:08:05 -05:00
|
|
|
Token::SeqEnd,
|
|
|
|
],
|
2017-04-19 13:38:57 -05:00
|
|
|
"invalid type: sequence, expected unit struct UnitStruct",
|
2017-04-09 15:08:05 -05:00
|
|
|
}
|
2017-10-31 11:32:58 -05:00
|
|
|
test_wrapping_overflow<Wrapping<u16>> {
|
|
|
|
&[
|
2017-11-01 00:42:12 -05:00
|
|
|
Token::U32(65_536),
|
2017-10-31 11:32:58 -05:00
|
|
|
],
|
|
|
|
"invalid value: integer `65536`, expected u16",
|
|
|
|
}
|
2016-02-21 18:26:52 -06:00
|
|
|
}
|