Fixed all the tests
This commit is contained in:
parent
bfd1fb0ee9
commit
997d3901c1
@ -49,7 +49,7 @@ mod decoder {
|
||||
pub fn new(values: HashMap<String, int>) -> IntDecoder {
|
||||
IntDecoder {
|
||||
len: values.len(),
|
||||
iter: values.move_iter(),
|
||||
iter: values.into_iter(),
|
||||
stack: vec!(),
|
||||
}
|
||||
}
|
||||
@ -195,7 +195,7 @@ mod deserializer {
|
||||
IntDeserializer {
|
||||
stack: vec!(StartState),
|
||||
len: values.len(),
|
||||
iter: values.move_iter(),
|
||||
iter: values.into_iter(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -214,7 +214,7 @@ mod decoder {
|
||||
match self.stack.pop() {
|
||||
Some(VecState(value)) => {
|
||||
let len = value.len();
|
||||
for inner in value.move_iter().rev() {
|
||||
for inner in value.into_iter().rev() {
|
||||
self.stack.push(InnerState(inner));
|
||||
}
|
||||
f(self, len)
|
||||
@ -232,7 +232,7 @@ mod decoder {
|
||||
match self.stack.pop() {
|
||||
Some(MapState(map)) => {
|
||||
let len = map.len();
|
||||
for (key, value) in map.move_iter() {
|
||||
for (key, value) in map.into_iter() {
|
||||
match value {
|
||||
Some(c) => {
|
||||
self.stack.push(CharState(c));
|
||||
@ -322,7 +322,7 @@ mod deserializer {
|
||||
Some(VecState(value)) => {
|
||||
self.stack.push(EndState);
|
||||
let len = value.len();
|
||||
for inner in value.move_iter().rev() {
|
||||
for inner in value.into_iter().rev() {
|
||||
self.stack.push(InnerState(inner));
|
||||
}
|
||||
Some(Ok(de::SeqStart(len)))
|
||||
@ -330,7 +330,7 @@ mod deserializer {
|
||||
Some(MapState(value)) => {
|
||||
self.stack.push(EndState);
|
||||
let len = value.len();
|
||||
for (key, value) in value.move_iter() {
|
||||
for (key, value) in value.into_iter() {
|
||||
match value {
|
||||
Some(c) => {
|
||||
self.stack.push(CharState(c));
|
||||
|
@ -41,7 +41,7 @@ mod decoder {
|
||||
pub fn new(values: Vec<int>) -> IntDecoder {
|
||||
IntDecoder {
|
||||
len: values.len(),
|
||||
iter: values.move_iter(),
|
||||
iter: values.into_iter(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -146,7 +146,7 @@ mod decoder {
|
||||
pub fn new(values: Vec<u8>) -> U8Decoder {
|
||||
U8Decoder {
|
||||
len: values.len(),
|
||||
iter: values.move_iter(),
|
||||
iter: values.into_iter(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -271,7 +271,7 @@ mod deserializer {
|
||||
IntDeserializer {
|
||||
state: StartState,
|
||||
len: values.len(),
|
||||
iter: values.move_iter(),
|
||||
iter: values.into_iter(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -343,7 +343,7 @@ mod deserializer {
|
||||
U8Deserializer {
|
||||
state: StartState,
|
||||
len: values.len(),
|
||||
iter: values.move_iter(),
|
||||
iter: values.into_iter(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
20
src/de.rs
20
src/de.rs
@ -991,6 +991,7 @@ impl<D: Deserializer<E>, E> Deserializable<D, E> for GatherTokens {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::collections::TreeMap;
|
||||
use std::{option, string};
|
||||
use serialize::Decoder;
|
||||
|
||||
use super::{Deserializer, Deserializable, Token, TokenKind};
|
||||
@ -1035,7 +1036,7 @@ mod tests {
|
||||
struct Inner {
|
||||
a: (),
|
||||
b: uint,
|
||||
c: TreeMap<String, Option<char>>,
|
||||
c: TreeMap<string::String, option::Option<char>>,
|
||||
}
|
||||
|
||||
impl<
|
||||
@ -1075,7 +1076,7 @@ mod tests {
|
||||
#[deriving(Clone, PartialEq, Show, Decodable)]
|
||||
enum Animal {
|
||||
Dog,
|
||||
Frog(String, int)
|
||||
Frog(string::String, int)
|
||||
}
|
||||
|
||||
impl<D: Deserializer<E>, E> Deserializable<D, E> for Animal {
|
||||
@ -1126,7 +1127,7 @@ mod tests {
|
||||
|
||||
impl<Iter: Iterator<Token>> Iterator<Result<Token, Error>> for TokenDeserializer<Iter> {
|
||||
#[inline]
|
||||
fn next(&mut self) -> Option<Result<Token, Error>> {
|
||||
fn next(&mut self) -> option::Option<Result<Token, Error>> {
|
||||
match self.tokens.next() {
|
||||
None => None,
|
||||
Some(token) => Some(Ok(token)),
|
||||
@ -1166,7 +1167,7 @@ mod tests {
|
||||
#[test]
|
||||
fn $name() {
|
||||
$(
|
||||
let mut deserializer = TokenDeserializer::new($tokens.move_iter());
|
||||
let mut deserializer = TokenDeserializer::new($tokens.into_iter());
|
||||
let value: $ty = Deserializable::deserialize(&mut deserializer).unwrap();
|
||||
|
||||
assert_eq!(value, $value);
|
||||
@ -1193,7 +1194,7 @@ mod tests {
|
||||
vec!(F64(5.0)) => 5.0: f64,
|
||||
vec!(Char('c')) => 'c': char,
|
||||
vec!(Str("abc")) => "abc": &str,
|
||||
vec!(String("abc".to_string())) => "abc".to_string(): String
|
||||
vec!(String("abc".to_string())) => "abc".to_string(): string::String
|
||||
])
|
||||
|
||||
test_value!(test_tuples, [
|
||||
@ -1227,12 +1228,12 @@ mod tests {
|
||||
])
|
||||
|
||||
test_value!(test_options, [
|
||||
vec!(Option(false)) => None: Option<int>,
|
||||
vec!(Option(false)) => None: option::Option<int>,
|
||||
|
||||
vec!(
|
||||
Option(true),
|
||||
Int(5),
|
||||
) => Some(5): Option<int>
|
||||
) => Some(5): option::Option<int>
|
||||
])
|
||||
|
||||
test_value!(test_structs, [
|
||||
@ -1334,7 +1335,7 @@ mod tests {
|
||||
vec!(
|
||||
MapStart(0),
|
||||
End,
|
||||
) => treemap!(): TreeMap<int, String>,
|
||||
) => treemap!(): TreeMap<int, string::String>,
|
||||
|
||||
vec!(
|
||||
MapStart(2),
|
||||
@ -1344,6 +1345,7 @@ mod tests {
|
||||
Int(6),
|
||||
String("b".to_string()),
|
||||
End,
|
||||
) => treemap!(5i => "a".to_string(), 6i => "b".to_string()): TreeMap<int, String>
|
||||
) => treemap!(5i => "a".to_string(), 6i => "b".to_string()): TreeMap<int, string::
|
||||
String>
|
||||
])
|
||||
}
|
||||
|
@ -2340,6 +2340,7 @@ mod tests {
|
||||
use std::fmt::Show;
|
||||
use std::io;
|
||||
use std::str;
|
||||
use std::string;
|
||||
use std::collections::TreeMap;
|
||||
|
||||
use super::{Json, Null, Boolean, Floating, String, List, Object};
|
||||
@ -2378,7 +2379,7 @@ mod tests {
|
||||
#[deriving_deserializable]
|
||||
enum Animal {
|
||||
Dog,
|
||||
Frog(String, Vec<int>)
|
||||
Frog(string::String, Vec<int>)
|
||||
}
|
||||
|
||||
impl ToJson for Animal {
|
||||
@ -2408,7 +2409,7 @@ mod tests {
|
||||
struct Inner {
|
||||
a: (),
|
||||
b: uint,
|
||||
c: Vec<String>,
|
||||
c: Vec<string::String>,
|
||||
}
|
||||
|
||||
impl ToJson for Inner {
|
||||
@ -2922,7 +2923,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_parse_string() {
|
||||
test_parse_err::<String>([
|
||||
test_parse_err::<string::String>([
|
||||
("\"", SyntaxError(EOFWhileParsingString, 1, 2)),
|
||||
("\"lol", SyntaxError(EOFWhileParsingString, 1, 5)),
|
||||
("\"lol\"a", SyntaxError(TrailingCharacters, 1, 6)),
|
||||
@ -3018,7 +3019,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_parse_object() {
|
||||
test_parse_err::<TreeMap<String, int>>([
|
||||
test_parse_err::<TreeMap<string::String, int>>([
|
||||
("{", SyntaxError(EOFWhileParsingString, 1, 2)),
|
||||
("{ ", SyntaxError(EOFWhileParsingString, 1, 3)),
|
||||
("{1", SyntaxError(KeyMustBeAString, 1, 2)),
|
||||
@ -3187,7 +3188,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_multiline_errors() {
|
||||
test_parse_err::<TreeMap<String, String>>([
|
||||
test_parse_err::<TreeMap<string::String, string::String>>([
|
||||
("{\n \"foo\":\n \"bar\"", SyntaxError(EOFWhileParsingObject, 3u, 8u)),
|
||||
]);
|
||||
}
|
||||
@ -3283,7 +3284,7 @@ mod tests {
|
||||
fn test_as_object() {
|
||||
let json_value: Json = from_str("{}").unwrap();
|
||||
let json_object = json_value.as_object();
|
||||
let map = TreeMap::<String, Json>::new();
|
||||
let map = TreeMap::<string::String, Json>::new();
|
||||
assert_eq!(json_object, Some(&map));
|
||||
}
|
||||
|
||||
@ -3717,6 +3718,7 @@ mod tests {
|
||||
#[cfg(test)]
|
||||
mod bench {
|
||||
use std::collections::TreeMap;
|
||||
use std::string;
|
||||
use serialize;
|
||||
use test::Bencher;
|
||||
|
||||
@ -3732,7 +3734,7 @@ mod bench {
|
||||
})
|
||||
}
|
||||
|
||||
fn json_str(count: uint) -> String {
|
||||
fn json_str(count: uint) -> string::String {
|
||||
let mut src = "[".to_string();
|
||||
for _ in range(0, count) {
|
||||
src.push_str(r#"{"a":true,"b":null,"c":3.1415,"d":"Hello world","e":[1,2,3]},"#);
|
||||
@ -3741,7 +3743,7 @@ mod bench {
|
||||
src
|
||||
}
|
||||
|
||||
fn pretty_json_str(count: uint) -> String {
|
||||
fn pretty_json_str(count: uint) -> string::String {
|
||||
let mut src = "[\n".to_string();
|
||||
for _ in range(0, count) {
|
||||
src.push_str(
|
||||
|
36
src/ser.rs
36
src/ser.rs
@ -321,6 +321,8 @@ impl_serialize_tuple! { T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, }
|
||||
mod tests {
|
||||
use std::collections::{HashMap, TreeMap};
|
||||
|
||||
use std::{option, string};
|
||||
|
||||
use serialize::Decoder;
|
||||
|
||||
use super::{Serializer, Serializable};
|
||||
@ -332,7 +334,7 @@ mod tests {
|
||||
struct Inner {
|
||||
a: (),
|
||||
b: uint,
|
||||
c: HashMap<String, Option<char>>,
|
||||
c: HashMap<string::String, option::Option<char>>,
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
@ -535,7 +537,7 @@ mod tests {
|
||||
|
||||
fn serialize_option<
|
||||
T: Serializable<AssertSerializer<Iter>, Error>
|
||||
>(&mut self, v: &Option<T>) -> Result<(), Error> {
|
||||
>(&mut self, v: &option::Option<T>) -> Result<(), Error> {
|
||||
match *v {
|
||||
Some(ref v) => {
|
||||
try!(self.serialize(Option(true)));
|
||||
@ -581,7 +583,7 @@ mod tests {
|
||||
let tokens = vec!(
|
||||
Int(5)
|
||||
);
|
||||
let mut serializer = AssertSerializer::new(tokens.move_iter());
|
||||
let mut serializer = AssertSerializer::new(tokens.into_iter());
|
||||
5i.serialize(&mut serializer).unwrap();
|
||||
assert_eq!(serializer.iter.next(), None);
|
||||
}
|
||||
@ -592,7 +594,7 @@ mod tests {
|
||||
Str("a"),
|
||||
);
|
||||
|
||||
let mut serializer = AssertSerializer::new(tokens.move_iter());
|
||||
let mut serializer = AssertSerializer::new(tokens.into_iter());
|
||||
"a".serialize(&mut serializer).unwrap();
|
||||
assert_eq!(serializer.iter.next(), None);
|
||||
}
|
||||
@ -603,7 +605,7 @@ mod tests {
|
||||
Null,
|
||||
);
|
||||
|
||||
let mut serializer = AssertSerializer::new(tokens.move_iter());
|
||||
let mut serializer = AssertSerializer::new(tokens.into_iter());
|
||||
().serialize(&mut serializer).unwrap();
|
||||
assert_eq!(serializer.iter.next(), None);
|
||||
}
|
||||
@ -614,7 +616,7 @@ mod tests {
|
||||
Option(false),
|
||||
);
|
||||
|
||||
let mut serializer = AssertSerializer::new(tokens.move_iter());
|
||||
let mut serializer = AssertSerializer::new(tokens.into_iter());
|
||||
None::<int>.serialize(&mut serializer).unwrap();
|
||||
assert_eq!(serializer.iter.next(), None);
|
||||
}
|
||||
@ -626,7 +628,7 @@ mod tests {
|
||||
Int(5),
|
||||
);
|
||||
|
||||
let mut serializer = AssertSerializer::new(tokens.move_iter());
|
||||
let mut serializer = AssertSerializer::new(tokens.into_iter());
|
||||
Some(5i).serialize(&mut serializer).unwrap();
|
||||
assert_eq!(serializer.iter.next(), None);
|
||||
}
|
||||
@ -643,7 +645,7 @@ mod tests {
|
||||
TupleEnd,
|
||||
);
|
||||
|
||||
let mut serializer = AssertSerializer::new(tokens.move_iter());
|
||||
let mut serializer = AssertSerializer::new(tokens.into_iter());
|
||||
(5i, "a").serialize(&mut serializer).unwrap();
|
||||
assert_eq!(serializer.iter.next(), None);
|
||||
}
|
||||
@ -669,7 +671,7 @@ mod tests {
|
||||
TupleEnd,
|
||||
);
|
||||
|
||||
let mut serializer = AssertSerializer::new(tokens.move_iter());
|
||||
let mut serializer = AssertSerializer::new(tokens.into_iter());
|
||||
((), (), (5i, "a")).serialize(&mut serializer).unwrap();
|
||||
assert_eq!(serializer.iter.next(), None);
|
||||
}
|
||||
@ -684,7 +686,7 @@ mod tests {
|
||||
StructEnd,
|
||||
);
|
||||
|
||||
let mut serializer = AssertSerializer::new(tokens.move_iter());
|
||||
let mut serializer = AssertSerializer::new(tokens.into_iter());
|
||||
Outer { inner: vec!() }.serialize(&mut serializer).unwrap();
|
||||
assert_eq!(serializer.iter.next(), None);
|
||||
}
|
||||
@ -713,7 +715,7 @@ mod tests {
|
||||
StructEnd,
|
||||
);
|
||||
|
||||
let mut serializer = AssertSerializer::new(tokens.move_iter());
|
||||
let mut serializer = AssertSerializer::new(tokens.into_iter());
|
||||
|
||||
let mut map = HashMap::new();
|
||||
map.insert("abc".to_string(), Some('c'));
|
||||
@ -737,7 +739,7 @@ mod tests {
|
||||
EnumEnd,
|
||||
);
|
||||
|
||||
let mut serializer = AssertSerializer::new(tokens.move_iter());
|
||||
let mut serializer = AssertSerializer::new(tokens.into_iter());
|
||||
Dog.serialize(&mut serializer).unwrap();
|
||||
assert_eq!(serializer.iter.next(), None);
|
||||
|
||||
@ -751,7 +753,7 @@ mod tests {
|
||||
EnumEnd,
|
||||
);
|
||||
|
||||
let mut serializer = AssertSerializer::new(tokens.move_iter());
|
||||
let mut serializer = AssertSerializer::new(tokens.into_iter());
|
||||
Frog("Henry".to_string(), 349).serialize(&mut serializer).unwrap();
|
||||
assert_eq!(serializer.iter.next(), None);
|
||||
}
|
||||
@ -763,7 +765,7 @@ mod tests {
|
||||
SeqEnd,
|
||||
);
|
||||
|
||||
let mut serializer = AssertSerializer::new(tokens.move_iter());
|
||||
let mut serializer = AssertSerializer::new(tokens.into_iter());
|
||||
let v: Vec<int> = vec!();
|
||||
v.serialize(&mut serializer).unwrap();
|
||||
assert_eq!(serializer.iter.next(), None);
|
||||
@ -779,7 +781,7 @@ mod tests {
|
||||
SeqEnd,
|
||||
);
|
||||
|
||||
let mut serializer = AssertSerializer::new(tokens.move_iter());
|
||||
let mut serializer = AssertSerializer::new(tokens.into_iter());
|
||||
(vec!(5i, 6, 7)).serialize(&mut serializer).unwrap();
|
||||
assert_eq!(serializer.iter.next(), None);
|
||||
}
|
||||
@ -805,7 +807,7 @@ mod tests {
|
||||
SeqEnd,
|
||||
);
|
||||
|
||||
let mut serializer = AssertSerializer::new(tokens.move_iter());
|
||||
let mut serializer = AssertSerializer::new(tokens.into_iter());
|
||||
(vec!(vec!(1i), vec!(2, 3), vec!(4, 5, 6))).serialize(&mut serializer).unwrap();
|
||||
assert_eq!(serializer.iter.next(), None);
|
||||
}
|
||||
@ -822,7 +824,7 @@ mod tests {
|
||||
MapEnd,
|
||||
);
|
||||
|
||||
let mut serializer = AssertSerializer::new(tokens.move_iter());
|
||||
let mut serializer = AssertSerializer::new(tokens.into_iter());
|
||||
|
||||
let mut map = TreeMap::new();
|
||||
map.insert(5i, "a".to_string());
|
||||
|
Loading…
Reference in New Issue
Block a user