Reenable the tests

This commit is contained in:
Erick Tryzelaar 2014-05-25 21:59:58 -07:00
parent 7206db4b0b
commit a0788f5c92

136
de.rs
View File

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