Reenable the tests
This commit is contained in:
parent
7206db4b0b
commit
a0788f5c92
136
de.rs
136
de.rs
@ -88,14 +88,13 @@ pub trait Deserializer<E>: Iterator<Result<Token, E>> {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
#[inline]
|
||||
fn expect_bool(&mut self) -> Result<bool, E> {
|
||||
match_token! {
|
||||
Bool(value) => Ok(value)
|
||||
fn expect_bool(&mut self, token: Token) -> Result<bool, E> {
|
||||
match token {
|
||||
Bool(value) => Ok(value),
|
||||
_ => Err(self.syntax_error()),
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
#[inline]
|
||||
fn expect_num<T: NumCast>(&mut self, token: Token) -> Result<T, E> {
|
||||
@ -112,25 +111,25 @@ pub trait Deserializer<E>: Iterator<Result<Token, E>> {
|
||||
U64(x) => to_result!(num::cast(x), self.syntax_error()),
|
||||
F32(x) => to_result!(num::cast(x), self.syntax_error()),
|
||||
F64(x) => to_result!(num::cast(x), self.syntax_error()),
|
||||
_ => { return Err(self.syntax_error()); }
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
#[inline]
|
||||
fn expect_char(&mut self) -> Result<char, E> {
|
||||
match_token! {
|
||||
Char(value) => Ok(value)
|
||||
_ => Err(self.syntax_error()),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn expect_str(&mut self) -> Result<&'static str, E> {
|
||||
match_token! {
|
||||
Str(value) => Ok(value)
|
||||
fn expect_char(&mut self, token: Token) -> Result<char, E> {
|
||||
match token {
|
||||
Char(value) => Ok(value),
|
||||
_ => Err(self.syntax_error()),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn expect_str(&mut self, token: Token) -> Result<&'static str, E> {
|
||||
match token {
|
||||
Str(value) => Ok(value),
|
||||
_ => Err(self.syntax_error()),
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
#[inline]
|
||||
fn expect_strbuf(&mut self, token: Token) -> Result<StrBuf, E> {
|
||||
@ -141,20 +140,19 @@ pub trait Deserializer<E>: Iterator<Result<Token, E>> {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
#[inline]
|
||||
fn expect_option<
|
||||
T: Deserializable<E, Self>
|
||||
>(&mut self) -> Result<Option<T>, E> {
|
||||
match_token! {
|
||||
>(&mut self, token: Token) -> Result<Option<T>, E> {
|
||||
match token {
|
||||
Option(false) => Ok(None),
|
||||
Option(true) => {
|
||||
let value: T = try!(Deserializable::deserialize(self));
|
||||
Ok(Some(value))
|
||||
}
|
||||
_ => Err(self.syntax_error()),
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
#[inline]
|
||||
fn expect_tuple_start(&mut self, token: Token, len: uint) -> Result<(), E> {
|
||||
@ -170,17 +168,9 @@ pub trait Deserializer<E>: Iterator<Result<Token, E>> {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
#[inline]
|
||||
fn expect_tuple_elt<T: Deserializable<E, Self>>(&mut self) -> Result<T, E> {
|
||||
match_token! {
|
||||
Sep => Deserializable::deserialize(self)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn expect_struct_start(&mut self, name: &str) -> Result<(), E> {
|
||||
match_token! {
|
||||
fn expect_struct_start(&mut self, token: Token, name: &str) -> Result<(), E> {
|
||||
match token {
|
||||
StructStart(n) => {
|
||||
if name == n {
|
||||
Ok(())
|
||||
@ -188,6 +178,7 @@ pub trait Deserializer<E>: Iterator<Result<Token, E>> {
|
||||
Err(self.syntax_error())
|
||||
}
|
||||
}
|
||||
_ => Err(self.syntax_error()),
|
||||
}
|
||||
}
|
||||
|
||||
@ -195,7 +186,13 @@ pub trait Deserializer<E>: Iterator<Result<Token, E>> {
|
||||
fn expect_struct_field<
|
||||
T: Deserializable<E, Self>
|
||||
>(&mut self, name: &str) -> Result<T, E> {
|
||||
match_token! {
|
||||
let token = match self.next() {
|
||||
Some(Ok(token)) => token,
|
||||
Some(Err(err)) => { return Err(err); }
|
||||
None => { return Err(self.end_of_stream_error()); }
|
||||
};
|
||||
|
||||
match token {
|
||||
StructField(n) => {
|
||||
if name == n {
|
||||
Deserializable::deserialize(self)
|
||||
@ -203,9 +200,9 @@ pub trait Deserializer<E>: Iterator<Result<Token, E>> {
|
||||
Err(self.syntax_error())
|
||||
}
|
||||
}
|
||||
_ => Err(self.syntax_error()),
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
#[inline]
|
||||
fn expect_enum_start<'a>(&mut self, token: Token, name: &str, variants: &[&str]) -> Result<uint, E> {
|
||||
@ -224,7 +221,6 @@ pub trait Deserializer<E>: Iterator<Result<Token, E>> {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
#[inline]
|
||||
fn expect_collection<
|
||||
T: Deserializable<E, Self>,
|
||||
@ -242,7 +238,6 @@ pub trait Deserializer<E>: Iterator<Result<Token, E>> {
|
||||
|
||||
expect_rest_of_collection(self, len)
|
||||
}
|
||||
*/
|
||||
|
||||
#[inline]
|
||||
fn expect_seq_start(&mut self, token: Token) -> Result<uint, E> {
|
||||
@ -252,7 +247,6 @@ pub trait Deserializer<E>: Iterator<Result<Token, E>> {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
#[inline]
|
||||
fn expect_map<
|
||||
K: Deserializable<E, Self>,
|
||||
@ -266,7 +260,6 @@ pub trait Deserializer<E>: Iterator<Result<Token, E>> {
|
||||
|
||||
expect_rest_of_collection(self, len)
|
||||
}
|
||||
*/
|
||||
|
||||
#[inline]
|
||||
fn expect_end(&mut self) -> Result<(), E> {
|
||||
@ -281,7 +274,6 @@ pub trait Deserializer<E>: Iterator<Result<Token, E>> {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/*
|
||||
// FIXME: https://github.com/mozilla/rust/issues/11751
|
||||
#[inline]
|
||||
fn expect_rest_of_collection<
|
||||
@ -306,7 +298,6 @@ fn expect_rest_of_collection<
|
||||
|
||||
result::collect_with_capacity(iter, len)
|
||||
}
|
||||
*/
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ -339,7 +330,7 @@ macro_rules! impl_deserializable {
|
||||
}
|
||||
}
|
||||
|
||||
//impl_deserializable!(bool, expect_bool)
|
||||
impl_deserializable!(bool, expect_bool)
|
||||
impl_deserializable!(int, expect_num)
|
||||
impl_deserializable!(i8, expect_num)
|
||||
impl_deserializable!(i16, expect_num)
|
||||
@ -352,14 +343,10 @@ impl_deserializable!(u32, expect_num)
|
||||
impl_deserializable!(u64, expect_num)
|
||||
impl_deserializable!(f32, expect_num)
|
||||
impl_deserializable!(f64, expect_num)
|
||||
/*
|
||||
impl_deserializable!(char, expect_char)
|
||||
impl_deserializable!(&'static str, expect_str)
|
||||
*/
|
||||
impl_deserializable!(StrBuf, expect_strbuf)
|
||||
|
||||
/*
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
impl<
|
||||
@ -368,11 +355,10 @@ impl<
|
||||
T: Deserializable<E, D>
|
||||
> Deserializable<E, D> for Option<T> {
|
||||
#[inline]
|
||||
fn deserialize(d: &mut D) -> Result<Option<T>, E> {
|
||||
d.expect_option()
|
||||
fn deserialize_token(d: &mut D, token: Token) -> Result<Option<T>, E> {
|
||||
d.expect_option(token)
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ -402,7 +388,6 @@ impl<
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
impl<
|
||||
E,
|
||||
D: Deserializer<E>,
|
||||
@ -410,11 +395,10 @@ impl<
|
||||
V: Deserializable<E, D>
|
||||
> Deserializable<E, D> for HashMap<K, V> {
|
||||
#[inline]
|
||||
fn deserialize(d: &mut D) -> Result<HashMap<K, V>, E> {
|
||||
d.expect_map()
|
||||
fn deserialize_token(d: &mut D, token: Token) -> Result<HashMap<K, V>, E> {
|
||||
d.expect_map(token)
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ -470,7 +454,6 @@ deserialize_tuple! { T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, }
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/*
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use collections::HashMap;
|
||||
@ -480,7 +463,7 @@ mod tests {
|
||||
|
||||
use super::{Token, Null, Int, Uint, Str, StrBuf, Char, Option};
|
||||
use super::{TupleStart, StructStart, StructField, EnumStart};
|
||||
use super::{SeqStart, MapStart, Sep, End};
|
||||
use super::{SeqStart, MapStart, End};
|
||||
use super::{Deserializer, Deserializable};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
@ -494,8 +477,8 @@ mod tests {
|
||||
|
||||
impl<E, D: Deserializer<E>> Deserializable<E, D> for Inner {
|
||||
#[inline]
|
||||
fn deserialize(d: &mut D) -> Result<Inner, E> {
|
||||
try!(d.expect_struct_start("Inner"));
|
||||
fn deserialize_token(d: &mut D, token: Token) -> Result<Inner, E> {
|
||||
try!(d.expect_struct_start(token, "Inner"));
|
||||
let a = try!(d.expect_struct_field("a"));
|
||||
let b = try!(d.expect_struct_field("b"));
|
||||
let c = try!(d.expect_struct_field("c"));
|
||||
@ -513,8 +496,8 @@ mod tests {
|
||||
|
||||
impl<E, D: Deserializer<E>> Deserializable<E, D> for Outer {
|
||||
#[inline]
|
||||
fn deserialize(d: &mut D) -> Result<Outer, E> {
|
||||
try!(d.expect_struct_start("Outer"));
|
||||
fn deserialize_token(d: &mut D, token: Token) -> Result<Outer, E> {
|
||||
try!(d.expect_struct_start(token, "Outer"));
|
||||
let inner = try!(d.expect_struct_field("inner"));
|
||||
try!(d.expect_end());
|
||||
Ok(Outer { inner: inner })
|
||||
@ -531,8 +514,8 @@ mod tests {
|
||||
|
||||
impl<E, D: Deserializer<E>> Deserializable<E, D> for Animal {
|
||||
#[inline]
|
||||
fn deserialize(d: &mut D) -> Result<Animal, E> {
|
||||
match try!(d.expect_enum_start("Animal", ["Dog", "Frog"])) {
|
||||
fn deserialize_token(d: &mut D, token: Token) -> Result<Animal, E> {
|
||||
match try!(d.expect_enum_start(token, "Animal", ["Dog", "Frog"])) {
|
||||
0 => {
|
||||
try!(d.expect_end());
|
||||
Ok(Dog)
|
||||
@ -685,10 +668,8 @@ mod tests {
|
||||
fn test_tokens_tuple() {
|
||||
let tokens = vec!(
|
||||
TupleStart(2),
|
||||
Sep,
|
||||
Int(5),
|
||||
|
||||
Sep,
|
||||
StrBuf("a".to_strbuf()),
|
||||
End,
|
||||
);
|
||||
@ -703,19 +684,14 @@ mod tests {
|
||||
fn test_tokens_tuple_compound() {
|
||||
let tokens = vec!(
|
||||
TupleStart(3),
|
||||
Sep,
|
||||
Null,
|
||||
|
||||
Sep,
|
||||
TupleStart(0),
|
||||
End,
|
||||
|
||||
Sep,
|
||||
TupleStart(2),
|
||||
Sep,
|
||||
Int(5),
|
||||
|
||||
Sep,
|
||||
StrBuf("a".to_strbuf()),
|
||||
End,
|
||||
End,
|
||||
@ -749,7 +725,6 @@ mod tests {
|
||||
StructStart("Outer"),
|
||||
StructField("inner"),
|
||||
SeqStart(1),
|
||||
Sep,
|
||||
StructStart("Inner"),
|
||||
StructField("a"),
|
||||
Null,
|
||||
@ -759,12 +734,9 @@ mod tests {
|
||||
|
||||
StructField("c"),
|
||||
MapStart(1),
|
||||
Sep,
|
||||
TupleStart(2),
|
||||
Sep,
|
||||
StrBuf("abc".to_strbuf()),
|
||||
|
||||
Sep,
|
||||
Option(true),
|
||||
Char('c'),
|
||||
End,
|
||||
@ -835,13 +807,10 @@ mod tests {
|
||||
fn test_tokens_vec() {
|
||||
let tokens = vec!(
|
||||
SeqStart(3),
|
||||
Sep,
|
||||
Int(5),
|
||||
|
||||
Sep,
|
||||
Int(6),
|
||||
|
||||
Sep,
|
||||
Int(7),
|
||||
End,
|
||||
);
|
||||
@ -856,30 +825,21 @@ mod tests {
|
||||
fn test_tokens_vec_compound() {
|
||||
let tokens = vec!(
|
||||
SeqStart(0),
|
||||
Sep,
|
||||
SeqStart(1),
|
||||
Sep,
|
||||
Int(1),
|
||||
End,
|
||||
|
||||
Sep,
|
||||
SeqStart(2),
|
||||
Sep,
|
||||
Int(2),
|
||||
|
||||
Sep,
|
||||
Int(3),
|
||||
End,
|
||||
|
||||
Sep,
|
||||
SeqStart(3),
|
||||
Sep,
|
||||
Int(4),
|
||||
|
||||
Sep,
|
||||
Int(5),
|
||||
|
||||
Sep,
|
||||
Int(6),
|
||||
End,
|
||||
End,
|
||||
@ -895,21 +855,15 @@ mod tests {
|
||||
fn test_tokens_hashmap() {
|
||||
let tokens = vec!(
|
||||
MapStart(2),
|
||||
Sep,
|
||||
TupleStart(2),
|
||||
Sep,
|
||||
Int(5),
|
||||
|
||||
Sep,
|
||||
StrBuf("a".to_strbuf()),
|
||||
End,
|
||||
|
||||
Sep,
|
||||
TupleStart(2),
|
||||
Sep,
|
||||
Int(6),
|
||||
|
||||
Sep,
|
||||
StrBuf("b".to_strbuf()),
|
||||
End,
|
||||
End,
|
||||
@ -930,13 +884,10 @@ mod tests {
|
||||
b.iter(|| {
|
||||
let tokens = vec!(
|
||||
SeqStart(3),
|
||||
Sep,
|
||||
Int(5),
|
||||
|
||||
Sep,
|
||||
Int(6),
|
||||
|
||||
Sep,
|
||||
Int(7),
|
||||
End,
|
||||
);
|
||||
@ -948,4 +899,3 @@ mod tests {
|
||||
})
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user