mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-06-13 05:31:02 +00:00
Update to rust HEAD
This commit is contained in:
+2
-2
@@ -275,7 +275,7 @@ fn bench_decoder_dog(b: &mut Bencher) {
|
|||||||
#[bench]
|
#[bench]
|
||||||
fn bench_decoder_frog(b: &mut Bencher) {
|
fn bench_decoder_frog(b: &mut Bencher) {
|
||||||
b.iter(|| {
|
b.iter(|| {
|
||||||
let animal = Frog("Henry".to_strbuf(), 349);
|
let animal = Frog("Henry".to_string(), 349);
|
||||||
|
|
||||||
let mut d = decoder::AnimalDecoder::new(animal.clone());
|
let mut d = decoder::AnimalDecoder::new(animal.clone());
|
||||||
let value: Animal = Decodable::decode(&mut d).unwrap();
|
let value: Animal = Decodable::decode(&mut d).unwrap();
|
||||||
@@ -299,7 +299,7 @@ fn bench_deserializer_dog(b: &mut Bencher) {
|
|||||||
#[bench]
|
#[bench]
|
||||||
fn bench_deserializer_frog(b: &mut Bencher) {
|
fn bench_deserializer_frog(b: &mut Bencher) {
|
||||||
b.iter(|| {
|
b.iter(|| {
|
||||||
let animal = Frog("Henry".to_strbuf(), 349);
|
let animal = Frog("Henry".to_string(), 349);
|
||||||
|
|
||||||
let mut d = deserializer::AnimalDeserializer::new(animal.clone());
|
let mut d = deserializer::AnimalDeserializer::new(animal.clone());
|
||||||
let value: Animal = Deserializable::deserialize(&mut d).unwrap();
|
let value: Animal = Deserializable::deserialize(&mut d).unwrap();
|
||||||
|
|||||||
+12
-12
@@ -461,7 +461,7 @@ mod deserializer {
|
|||||||
fn bench_decoder_0_0(b: &mut Bencher) {
|
fn bench_decoder_0_0(b: &mut Bencher) {
|
||||||
b.iter(|| {
|
b.iter(|| {
|
||||||
let mut map = HashMap::new();
|
let mut map = HashMap::new();
|
||||||
map.insert("abc".to_strbuf(), Some('c'));
|
map.insert("abc".to_string(), Some('c'));
|
||||||
|
|
||||||
let outer = Outer {
|
let outer = Outer {
|
||||||
inner: vec!(),
|
inner: vec!(),
|
||||||
@@ -500,11 +500,11 @@ fn bench_decoder_1_0(b: &mut Bencher) {
|
|||||||
fn bench_decoder_1_5(b: &mut Bencher) {
|
fn bench_decoder_1_5(b: &mut Bencher) {
|
||||||
b.iter(|| {
|
b.iter(|| {
|
||||||
let mut map = HashMap::new();
|
let mut map = HashMap::new();
|
||||||
map.insert("1".to_strbuf(), Some('a'));
|
map.insert("1".to_string(), Some('a'));
|
||||||
map.insert("2".to_strbuf(), None);
|
map.insert("2".to_string(), None);
|
||||||
map.insert("3".to_strbuf(), Some('b'));
|
map.insert("3".to_string(), Some('b'));
|
||||||
map.insert("4".to_strbuf(), None);
|
map.insert("4".to_string(), None);
|
||||||
map.insert("5".to_strbuf(), Some('c'));
|
map.insert("5".to_string(), Some('c'));
|
||||||
|
|
||||||
let outer = Outer {
|
let outer = Outer {
|
||||||
inner: vec!(
|
inner: vec!(
|
||||||
@@ -527,7 +527,7 @@ fn bench_decoder_1_5(b: &mut Bencher) {
|
|||||||
fn bench_deserializer_0_0(b: &mut Bencher) {
|
fn bench_deserializer_0_0(b: &mut Bencher) {
|
||||||
b.iter(|| {
|
b.iter(|| {
|
||||||
let mut map = HashMap::new();
|
let mut map = HashMap::new();
|
||||||
map.insert("abc".to_strbuf(), Some('c'));
|
map.insert("abc".to_string(), Some('c'));
|
||||||
|
|
||||||
let outer = Outer {
|
let outer = Outer {
|
||||||
inner: vec!(),
|
inner: vec!(),
|
||||||
@@ -566,11 +566,11 @@ fn bench_deserializer_1_0(b: &mut Bencher) {
|
|||||||
fn bench_deserializer_1_5(b: &mut Bencher) {
|
fn bench_deserializer_1_5(b: &mut Bencher) {
|
||||||
b.iter(|| {
|
b.iter(|| {
|
||||||
let mut map = HashMap::new();
|
let mut map = HashMap::new();
|
||||||
map.insert("1".to_strbuf(), Some('a'));
|
map.insert("1".to_string(), Some('a'));
|
||||||
map.insert("2".to_strbuf(), None);
|
map.insert("2".to_string(), None);
|
||||||
map.insert("3".to_strbuf(), Some('b'));
|
map.insert("3".to_string(), Some('b'));
|
||||||
map.insert("4".to_strbuf(), None);
|
map.insert("4".to_string(), None);
|
||||||
map.insert("5".to_strbuf(), Some('c'));
|
map.insert("5".to_string(), Some('c'));
|
||||||
|
|
||||||
let outer = Outer {
|
let outer = Outer {
|
||||||
inner: vec!(
|
inner: vec!(
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ pub trait Deserializer<E>: Iterator<Result<Token, E>> {
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn expect_strbuf(&mut self, token: Token) -> Result<String, E> {
|
fn expect_strbuf(&mut self, token: Token) -> Result<String, E> {
|
||||||
match token {
|
match token {
|
||||||
Str(value) => Ok(value.to_strbuf()),
|
Str(value) => Ok(value.to_string()),
|
||||||
String(value) => Ok(value),
|
String(value) => Ok(value),
|
||||||
_ => Err(self.syntax_error()),
|
_ => Err(self.syntax_error()),
|
||||||
}
|
}
|
||||||
@@ -716,13 +716,13 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_tokens_strbuf() {
|
fn test_tokens_strbuf() {
|
||||||
let tokens = vec!(
|
let tokens = vec!(
|
||||||
String("a".to_strbuf()),
|
String("a".to_string()),
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut deserializer = TokenDeserializer::new(tokens);
|
let mut deserializer = TokenDeserializer::new(tokens);
|
||||||
let value: String = Deserializable::deserialize(&mut deserializer).unwrap();
|
let value: String = Deserializable::deserialize(&mut deserializer).unwrap();
|
||||||
|
|
||||||
assert_eq!(value, "a".to_strbuf());
|
assert_eq!(value, "a".to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -781,14 +781,14 @@ mod tests {
|
|||||||
TupleStart(2),
|
TupleStart(2),
|
||||||
Int(5),
|
Int(5),
|
||||||
|
|
||||||
String("a".to_strbuf()),
|
String("a".to_string()),
|
||||||
End,
|
End,
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut deserializer = TokenDeserializer::new(tokens);
|
let mut deserializer = TokenDeserializer::new(tokens);
|
||||||
let value: (int, String) = Deserializable::deserialize(&mut deserializer).unwrap();
|
let value: (int, String) = Deserializable::deserialize(&mut deserializer).unwrap();
|
||||||
|
|
||||||
assert_eq!(value, (5, "a".to_strbuf()));
|
assert_eq!(value, (5, "a".to_string()));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -803,7 +803,7 @@ mod tests {
|
|||||||
TupleStart(2),
|
TupleStart(2),
|
||||||
Int(5),
|
Int(5),
|
||||||
|
|
||||||
String("a".to_strbuf()),
|
String("a".to_string()),
|
||||||
End,
|
End,
|
||||||
End,
|
End,
|
||||||
);
|
);
|
||||||
@@ -811,7 +811,7 @@ mod tests {
|
|||||||
let mut deserializer = TokenDeserializer::new(tokens);
|
let mut deserializer = TokenDeserializer::new(tokens);
|
||||||
let value: ((), (), (int, String)) = Deserializable::deserialize(&mut deserializer).unwrap();
|
let value: ((), (), (int, String)) = Deserializable::deserialize(&mut deserializer).unwrap();
|
||||||
|
|
||||||
assert_eq!(value, ((), (), (5, "a".to_strbuf())));
|
assert_eq!(value, ((), (), (5, "a".to_string())));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -845,7 +845,7 @@ mod tests {
|
|||||||
|
|
||||||
Str("c"),
|
Str("c"),
|
||||||
MapStart(1),
|
MapStart(1),
|
||||||
String("abc".to_strbuf()),
|
String("abc".to_string()),
|
||||||
|
|
||||||
Option(true),
|
Option(true),
|
||||||
Char('c'),
|
Char('c'),
|
||||||
@@ -859,7 +859,7 @@ mod tests {
|
|||||||
let value: Outer = Deserializable::deserialize(&mut deserializer).unwrap();
|
let value: Outer = Deserializable::deserialize(&mut deserializer).unwrap();
|
||||||
|
|
||||||
let mut map = HashMap::new();
|
let mut map = HashMap::new();
|
||||||
map.insert("abc".to_strbuf(), Some('c'));
|
map.insert("abc".to_string(), Some('c'));
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
value,
|
value,
|
||||||
@@ -888,7 +888,7 @@ mod tests {
|
|||||||
|
|
||||||
let tokens = vec!(
|
let tokens = vec!(
|
||||||
EnumStart("Animal", "Frog", 2),
|
EnumStart("Animal", "Frog", 2),
|
||||||
String("Henry".to_strbuf()),
|
String("Henry".to_string()),
|
||||||
Int(349),
|
Int(349),
|
||||||
End,
|
End,
|
||||||
);
|
);
|
||||||
@@ -896,7 +896,7 @@ mod tests {
|
|||||||
let mut deserializer = TokenDeserializer::new(tokens);
|
let mut deserializer = TokenDeserializer::new(tokens);
|
||||||
let value: Animal = Deserializable::deserialize(&mut deserializer).unwrap();
|
let value: Animal = Deserializable::deserialize(&mut deserializer).unwrap();
|
||||||
|
|
||||||
assert_eq!(value, Frog("Henry".to_strbuf(), 349));
|
assert_eq!(value, Frog("Henry".to_string(), 349));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -966,11 +966,11 @@ mod tests {
|
|||||||
MapStart(2),
|
MapStart(2),
|
||||||
Int(5),
|
Int(5),
|
||||||
|
|
||||||
String("a".to_strbuf()),
|
String("a".to_string()),
|
||||||
|
|
||||||
Int(6),
|
Int(6),
|
||||||
|
|
||||||
String("b".to_strbuf()),
|
String("b".to_string()),
|
||||||
End,
|
End,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -978,8 +978,8 @@ mod tests {
|
|||||||
let value: HashMap<int, String> = Deserializable::deserialize(&mut deserializer).unwrap();
|
let value: HashMap<int, String> = Deserializable::deserialize(&mut deserializer).unwrap();
|
||||||
|
|
||||||
let mut map = HashMap::new();
|
let mut map = HashMap::new();
|
||||||
map.insert(5, "a".to_strbuf());
|
map.insert(5, "a".to_string());
|
||||||
map.insert(6, "b".to_strbuf());
|
map.insert(6, "b".to_string());
|
||||||
|
|
||||||
assert_eq!(value, map);
|
assert_eq!(value, map);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ use serialize::{json, Encodable};
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let to_encode_object = TestStruct{data_str:"example of string to encode".to_strbuf()};
|
let to_encode_object = TestStruct{data_str:"example of string to encode".to_string()};
|
||||||
let mut m = io::MemWriter::new();
|
let mut m = io::MemWriter::new();
|
||||||
{
|
{
|
||||||
let mut encoder = json::Encoder::new(&mut m as &mut std::io::Writer);
|
let mut encoder = json::Encoder::new(&mut m as &mut std::io::Writer);
|
||||||
@@ -85,7 +85,7 @@ into a string (String) or buffer (~[u8]): `str_encode(&m)` and `buffer_encode(&m
|
|||||||
|
|
||||||
```rust
|
```rust
|
||||||
use serialize::json;
|
use serialize::json;
|
||||||
let to_encode_object = "example of string to encode".to_strbuf();
|
let to_encode_object = "example of string to encode".to_string();
|
||||||
let encoded_str: String = json::Encoder::str_encode(&to_encode_object);
|
let encoded_str: String = json::Encoder::str_encode(&to_encode_object);
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -114,16 +114,16 @@ pub struct MyStruct {
|
|||||||
impl ToJson for MyStruct {
|
impl ToJson for MyStruct {
|
||||||
fn to_json( &self ) -> json::Json {
|
fn to_json( &self ) -> json::Json {
|
||||||
let mut d = box TreeMap::new();
|
let mut d = box TreeMap::new();
|
||||||
d.insert("attr1".to_strbuf(), self.attr1.to_json());
|
d.insert("attr1".to_string(), self.attr1.to_json());
|
||||||
d.insert("attr2".to_strbuf(), self.attr2.to_json());
|
d.insert("attr2".to_string(), self.attr2.to_json());
|
||||||
json::Object(d)
|
json::Object(d)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let test2: MyStruct = MyStruct {attr1: 1, attr2:"test".to_strbuf()};
|
let test2: MyStruct = MyStruct {attr1: 1, attr2:"test".to_string()};
|
||||||
let tjson: json::Json = test2.to_json();
|
let tjson: json::Json = test2.to_json();
|
||||||
let json_str: String = tjson.to_str().into_strbuf();
|
let json_str: String = tjson.to_str().into_string();
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -141,7 +141,7 @@ pub struct MyStruct {
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let json_str_to_decode: String =
|
let json_str_to_decode: String =
|
||||||
"{\"attr1\":1,\"attr2\":\"toto\"}".to_strbuf();
|
"{\"attr1\":1,\"attr2\":\"toto\"}".to_string();
|
||||||
let json_object = json::from_str(json_str_to_decode.as_slice());
|
let json_object = json::from_str(json_str_to_decode.as_slice());
|
||||||
let mut decoder = json::Decoder::new(json_object.unwrap());
|
let mut decoder = json::Decoder::new(json_object.unwrap());
|
||||||
let decoded_object: MyStruct = match Decodable::decode(&mut decoder) {
|
let decoded_object: MyStruct = match Decodable::decode(&mut decoder) {
|
||||||
@@ -173,7 +173,7 @@ use serialize::{json, Encodable, Decodable};
|
|||||||
// It calls the generated `Encodable` impl.
|
// It calls the generated `Encodable` impl.
|
||||||
fn main() {
|
fn main() {
|
||||||
let to_encode_object = TestStruct1
|
let to_encode_object = TestStruct1
|
||||||
{data_int: 1, data_str:"toto".to_strbuf(), data_vector:vec![2,3,4,5]};
|
{data_int: 1, data_str:"toto".to_string(), data_vector:vec![2,3,4,5]};
|
||||||
let encoded_str: String = json::Encoder::str_encode(&to_encode_object);
|
let encoded_str: String = json::Encoder::str_encode(&to_encode_object);
|
||||||
|
|
||||||
// To deserialize use the `json::from_str` and `json::Decoder`
|
// To deserialize use the `json::from_str` and `json::Decoder`
|
||||||
@@ -207,9 +207,9 @@ pub struct TestStruct1 {
|
|||||||
impl ToJson for TestStruct1 {
|
impl ToJson for TestStruct1 {
|
||||||
fn to_json( &self ) -> json::Json {
|
fn to_json( &self ) -> json::Json {
|
||||||
let mut d = box TreeMap::new();
|
let mut d = box TreeMap::new();
|
||||||
d.insert("data_int".to_strbuf(), self.data_int.to_json());
|
d.insert("data_int".to_string(), self.data_int.to_json());
|
||||||
d.insert("data_str".to_strbuf(), self.data_str.to_json());
|
d.insert("data_str".to_string(), self.data_str.to_json());
|
||||||
d.insert("data_vector".to_strbuf(), self.data_vector.to_json());
|
d.insert("data_vector".to_string(), self.data_vector.to_json());
|
||||||
json::Object(d)
|
json::Object(d)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -217,10 +217,10 @@ impl ToJson for TestStruct1 {
|
|||||||
fn main() {
|
fn main() {
|
||||||
// Serialization using our impl of to_json
|
// Serialization using our impl of to_json
|
||||||
|
|
||||||
let test2: TestStruct1 = TestStruct1 {data_int: 1, data_str:"toto".to_strbuf(),
|
let test2: TestStruct1 = TestStruct1 {data_int: 1, data_str:"toto".to_string(),
|
||||||
data_vector:vec![2,3,4,5]};
|
data_vector:vec![2,3,4,5]};
|
||||||
let tjson: json::Json = test2.to_json();
|
let tjson: json::Json = test2.to_json();
|
||||||
let json_str: String = tjson.to_str().into_strbuf();
|
let json_str: String = tjson.to_str().into_string();
|
||||||
|
|
||||||
// Deserialize like before.
|
// Deserialize like before.
|
||||||
|
|
||||||
@@ -299,11 +299,11 @@ impl<E, D: de::Deserializer<E>> de::Deserializable<E, D> for Json {
|
|||||||
let token = de::SeqStart(len);
|
let token = de::SeqStart(len);
|
||||||
let fields: Vec<Json> = try!(de::Deserializable::deserialize_token(d, token));
|
let fields: Vec<Json> = try!(de::Deserializable::deserialize_token(d, token));
|
||||||
if fields.is_empty() {
|
if fields.is_empty() {
|
||||||
Ok(String(name.to_strbuf()))
|
Ok(String(name.to_string()))
|
||||||
} else {
|
} else {
|
||||||
let mut object = TreeMap::new();
|
let mut object = TreeMap::new();
|
||||||
object.insert("variant".to_strbuf(), String(name.to_strbuf()));
|
object.insert("variant".to_string(), String(name.to_string()));
|
||||||
object.insert("fields".to_strbuf(), List(fields));
|
object.insert("fields".to_string(), List(fields));
|
||||||
Ok(Object(object))
|
Ok(Object(object))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -528,7 +528,7 @@ impl<'a> Encoder<'a> {
|
|||||||
to_encode_object: &T)
|
to_encode_object: &T)
|
||||||
-> String {
|
-> String {
|
||||||
let buff = Encoder::buffer_encode(to_encode_object);
|
let buff = Encoder::buffer_encode(to_encode_object);
|
||||||
str::from_utf8(buff.as_slice()).unwrap().to_strbuf()
|
str::from_utf8(buff.as_slice()).unwrap().to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -974,7 +974,7 @@ impl Json {
|
|||||||
pub fn to_pretty_str(&self) -> String {
|
pub fn to_pretty_str(&self) -> String {
|
||||||
let mut s = MemWriter::new();
|
let mut s = MemWriter::new();
|
||||||
self.to_pretty_writer(&mut s as &mut io::Writer).unwrap();
|
self.to_pretty_writer(&mut s as &mut io::Writer).unwrap();
|
||||||
str::from_utf8(s.unwrap().as_slice()).unwrap().to_strbuf()
|
str::from_utf8(s.unwrap().as_slice()).unwrap().to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// If the Json value is an Object, returns the value associated with the provided key.
|
/// If the Json value is an Object, returns the value associated with the provided key.
|
||||||
@@ -1761,35 +1761,35 @@ impl<T: Iterator<char>> de::Deserializer<ParserError> for Parser<T> {
|
|||||||
let name = match self.pop() {
|
let name = match self.pop() {
|
||||||
String(s) => s,
|
String(s) => s,
|
||||||
Object(mut o) => {
|
Object(mut o) => {
|
||||||
let n = match o.pop(&"variant".to_strbuf()) {
|
let n = match o.pop(&"variant".to_string()) {
|
||||||
Some(String(s)) => s,
|
Some(String(s)) => s,
|
||||||
Some(val) => {
|
Some(val) => {
|
||||||
return Err(ExpectedError("String".to_strbuf(),
|
return Err(ExpectedError("String".to_string(),
|
||||||
format_strbuf!("{}", val)))
|
format!("{}", val)))
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
return Err(MissingFieldError("variant".to_strbuf()))
|
return Err(MissingFieldError("variant".to_string()))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
match o.pop(&"fields".to_strbuf()) {
|
match o.pop(&"fields".to_string()) {
|
||||||
Some(List(l)) => {
|
Some(List(l)) => {
|
||||||
for field in l.move_iter().rev() {
|
for field in l.move_iter().rev() {
|
||||||
self.stack.push(field.clone());
|
self.stack.push(field.clone());
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Some(val) => {
|
Some(val) => {
|
||||||
return Err(ExpectedError("List".to_strbuf(),
|
return Err(ExpectedError("List".to_string(),
|
||||||
format_strbuf!("{}", val)))
|
format!("{}", val)))
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
return Err(MissingFieldError("fields".to_strbuf()))
|
return Err(MissingFieldError("fields".to_string()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
n
|
n
|
||||||
}
|
}
|
||||||
json => {
|
json => {
|
||||||
return Err(ExpectedError("String or Object".to_strbuf(),
|
return Err(ExpectedError("String or Object".to_string(),
|
||||||
format_strbuf!("{}", json)))
|
format!("{}", json)))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let idx = match names.iter()
|
let idx = match names.iter()
|
||||||
@@ -1886,7 +1886,7 @@ impl<T: Iterator<char>> Builder<T> {
|
|||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
let key = match self.parser.stack().top() {
|
let key = match self.parser.stack().top() {
|
||||||
Some(Key(k)) => { k.to_strbuf() }
|
Some(Key(k)) => { k.to_string() }
|
||||||
_ => { fail!("invalid state"); }
|
_ => { fail!("invalid state"); }
|
||||||
};
|
};
|
||||||
match self.build_value() {
|
match self.build_value() {
|
||||||
@@ -1938,7 +1938,7 @@ pub fn from_json<
|
|||||||
Err(e) => return Err(io_error_to_error(e))
|
Err(e) => return Err(io_error_to_error(e))
|
||||||
};
|
};
|
||||||
let s = match str::from_utf8(contents.as_slice()) {
|
let s = match str::from_utf8(contents.as_slice()) {
|
||||||
Some(s) => s.to_strbuf(),
|
Some(s) => s.to_string(),
|
||||||
None => return Err(SyntaxError(NotUtf8, 0, 0))
|
None => return Err(SyntaxError(NotUtf8, 0, 0))
|
||||||
};
|
};
|
||||||
let mut builder = Builder::new(s.as_slice().chars());
|
let mut builder = Builder::new(s.as_slice().chars());
|
||||||
@@ -1978,16 +1978,16 @@ macro_rules! expect(
|
|||||||
($e:expr, Null) => ({
|
($e:expr, Null) => ({
|
||||||
match $e {
|
match $e {
|
||||||
Null => Ok(()),
|
Null => Ok(()),
|
||||||
other => Err(ExpectedError("Null".to_strbuf(),
|
other => Err(ExpectedError("Null".to_string(),
|
||||||
format_strbuf!("{}", other)))
|
format!("{}", other)))
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
($e:expr, $t:ident) => ({
|
($e:expr, $t:ident) => ({
|
||||||
match $e {
|
match $e {
|
||||||
$t(v) => Ok(v),
|
$t(v) => Ok(v),
|
||||||
other => {
|
other => {
|
||||||
Err(ExpectedError(stringify!($t).to_strbuf(),
|
Err(ExpectedError(stringify!($t).to_string(),
|
||||||
format_strbuf!("{}", other)))
|
format!("{}", other)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -2030,8 +2030,8 @@ impl ::Decoder<DecoderError> for Decoder {
|
|||||||
Ok(FromStr::from_str(s.as_slice()).unwrap())
|
Ok(FromStr::from_str(s.as_slice()).unwrap())
|
||||||
},
|
},
|
||||||
value => {
|
value => {
|
||||||
Err(ExpectedError("Number".to_strbuf(),
|
Err(ExpectedError("Number".to_string(),
|
||||||
format_strbuf!("{}", value)))
|
format!("{}", value)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2048,8 +2048,8 @@ impl ::Decoder<DecoderError> for Decoder {
|
|||||||
_ => ()
|
_ => ()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(ExpectedError("single character string".to_strbuf(),
|
Err(ExpectedError("single character string".to_string(),
|
||||||
format_strbuf!("{}", s)))
|
format!("{}", s)))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_str(&mut self) -> DecodeResult<String> {
|
fn read_str(&mut self) -> DecodeResult<String> {
|
||||||
@@ -2072,35 +2072,35 @@ impl ::Decoder<DecoderError> for Decoder {
|
|||||||
let name = match self.pop() {
|
let name = match self.pop() {
|
||||||
String(s) => s,
|
String(s) => s,
|
||||||
Object(mut o) => {
|
Object(mut o) => {
|
||||||
let n = match o.pop(&"variant".to_strbuf()) {
|
let n = match o.pop(&"variant".to_string()) {
|
||||||
Some(String(s)) => s,
|
Some(String(s)) => s,
|
||||||
Some(val) => {
|
Some(val) => {
|
||||||
return Err(ExpectedError("String".to_strbuf(),
|
return Err(ExpectedError("String".to_string(),
|
||||||
format_strbuf!("{}", val)))
|
format!("{}", val)))
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
return Err(MissingFieldError("variant".to_strbuf()))
|
return Err(MissingFieldError("variant".to_string()))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
match o.pop(&"fields".to_strbuf()) {
|
match o.pop(&"fields".to_string()) {
|
||||||
Some(List(l)) => {
|
Some(List(l)) => {
|
||||||
for field in l.move_iter().rev() {
|
for field in l.move_iter().rev() {
|
||||||
self.stack.push(field.clone());
|
self.stack.push(field.clone());
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Some(val) => {
|
Some(val) => {
|
||||||
return Err(ExpectedError("List".to_strbuf(),
|
return Err(ExpectedError("List".to_string(),
|
||||||
format_strbuf!("{}", val)))
|
format!("{}", val)))
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
return Err(MissingFieldError("fields".to_strbuf()))
|
return Err(MissingFieldError("fields".to_string()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
n
|
n
|
||||||
}
|
}
|
||||||
json => {
|
json => {
|
||||||
return Err(ExpectedError("String or Object".to_strbuf(),
|
return Err(ExpectedError("String or Object".to_string(),
|
||||||
format_strbuf!("{}", json)))
|
format!("{}", json)))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let idx = match names.iter()
|
let idx = match names.iter()
|
||||||
@@ -2156,8 +2156,8 @@ impl ::Decoder<DecoderError> for Decoder {
|
|||||||
debug!("read_struct_field(name={}, idx={})", name, idx);
|
debug!("read_struct_field(name={}, idx={})", name, idx);
|
||||||
let mut obj = try!(expect!(self.pop(), Object));
|
let mut obj = try!(expect!(self.pop(), Object));
|
||||||
|
|
||||||
let value = match obj.pop(&name.to_strbuf()) {
|
let value = match obj.pop(&name.to_string()) {
|
||||||
None => return Err(MissingFieldError(name.to_strbuf())),
|
None => return Err(MissingFieldError(name.to_string())),
|
||||||
Some(json) => {
|
Some(json) => {
|
||||||
self.stack.push(json);
|
self.stack.push(json);
|
||||||
try!(f(self))
|
try!(f(self))
|
||||||
@@ -2637,67 +2637,67 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_write_null() {
|
fn test_write_null() {
|
||||||
assert_eq!(Null.to_str().into_strbuf(), "null".to_strbuf());
|
assert_eq!(Null.to_str().into_string(), "null".to_string());
|
||||||
assert_eq!(Null.to_pretty_str().into_strbuf(), "null".to_strbuf());
|
assert_eq!(Null.to_pretty_str().into_string(), "null".to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_write_number() {
|
fn test_write_number() {
|
||||||
assert_eq!(Number(3.0).to_str().into_strbuf(), "3".to_strbuf());
|
assert_eq!(Number(3.0).to_str().into_string(), "3".to_string());
|
||||||
assert_eq!(Number(3.0).to_pretty_str().into_strbuf(), "3".to_strbuf());
|
assert_eq!(Number(3.0).to_pretty_str().into_string(), "3".to_string());
|
||||||
|
|
||||||
assert_eq!(Number(3.1).to_str().into_strbuf(), "3.1".to_strbuf());
|
assert_eq!(Number(3.1).to_str().into_string(), "3.1".to_string());
|
||||||
assert_eq!(Number(3.1).to_pretty_str().into_strbuf(), "3.1".to_strbuf());
|
assert_eq!(Number(3.1).to_pretty_str().into_string(), "3.1".to_string());
|
||||||
|
|
||||||
assert_eq!(Number(-1.5).to_str().into_strbuf(), "-1.5".to_strbuf());
|
assert_eq!(Number(-1.5).to_str().into_string(), "-1.5".to_string());
|
||||||
assert_eq!(Number(-1.5).to_pretty_str().into_strbuf(), "-1.5".to_strbuf());
|
assert_eq!(Number(-1.5).to_pretty_str().into_string(), "-1.5".to_string());
|
||||||
|
|
||||||
assert_eq!(Number(0.5).to_str().into_strbuf(), "0.5".to_strbuf());
|
assert_eq!(Number(0.5).to_str().into_string(), "0.5".to_string());
|
||||||
assert_eq!(Number(0.5).to_pretty_str().into_strbuf(), "0.5".to_strbuf());
|
assert_eq!(Number(0.5).to_pretty_str().into_string(), "0.5".to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_write_str() {
|
fn test_write_str() {
|
||||||
assert_eq!(String("".to_strbuf()).to_str().into_strbuf(), "\"\"".to_strbuf());
|
assert_eq!(String("".to_string()).to_str().into_string(), "\"\"".to_string());
|
||||||
assert_eq!(String("".to_strbuf()).to_pretty_str().into_strbuf(), "\"\"".to_strbuf());
|
assert_eq!(String("".to_string()).to_pretty_str().into_string(), "\"\"".to_string());
|
||||||
|
|
||||||
assert_eq!(String("foo".to_strbuf()).to_str().into_strbuf(), "\"foo\"".to_strbuf());
|
assert_eq!(String("foo".to_string()).to_str().into_string(), "\"foo\"".to_string());
|
||||||
assert_eq!(String("foo".to_strbuf()).to_pretty_str().into_strbuf(), "\"foo\"".to_strbuf());
|
assert_eq!(String("foo".to_string()).to_pretty_str().into_string(), "\"foo\"".to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_write_bool() {
|
fn test_write_bool() {
|
||||||
assert_eq!(Boolean(true).to_str().into_strbuf(), "true".to_strbuf());
|
assert_eq!(Boolean(true).to_str().into_string(), "true".to_string());
|
||||||
assert_eq!(Boolean(true).to_pretty_str().into_strbuf(), "true".to_strbuf());
|
assert_eq!(Boolean(true).to_pretty_str().into_string(), "true".to_string());
|
||||||
|
|
||||||
assert_eq!(Boolean(false).to_str().into_strbuf(), "false".to_strbuf());
|
assert_eq!(Boolean(false).to_str().into_string(), "false".to_string());
|
||||||
assert_eq!(Boolean(false).to_pretty_str().into_strbuf(), "false".to_strbuf());
|
assert_eq!(Boolean(false).to_pretty_str().into_string(), "false".to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_write_list() {
|
fn test_write_list() {
|
||||||
assert_eq!(List(vec![]).to_str().into_strbuf(), "[]".to_strbuf());
|
assert_eq!(List(vec![]).to_str().into_string(), "[]".to_string());
|
||||||
assert_eq!(List(vec![]).to_pretty_str().into_strbuf(), "[]".to_strbuf());
|
assert_eq!(List(vec![]).to_pretty_str().into_string(), "[]".to_string());
|
||||||
|
|
||||||
assert_eq!(List(vec![Boolean(true)]).to_str().into_strbuf(), "[true]".to_strbuf());
|
assert_eq!(List(vec![Boolean(true)]).to_str().into_string(), "[true]".to_string());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
List(vec![Boolean(true)]).to_pretty_str().into_strbuf(),
|
List(vec![Boolean(true)]).to_pretty_str().into_string(),
|
||||||
"\
|
"\
|
||||||
[\n \
|
[\n \
|
||||||
true\n\
|
true\n\
|
||||||
]".to_strbuf()
|
]".to_string()
|
||||||
);
|
);
|
||||||
|
|
||||||
let long_test_list = List(vec![
|
let long_test_list = List(vec![
|
||||||
Boolean(false),
|
Boolean(false),
|
||||||
Null,
|
Null,
|
||||||
List(vec![String("foo\nbar".to_strbuf()), Number(3.5)])]);
|
List(vec![String("foo\nbar".to_string()), Number(3.5)])]);
|
||||||
|
|
||||||
assert_eq!(long_test_list.to_str().into_strbuf(),
|
assert_eq!(long_test_list.to_str().into_string(),
|
||||||
"[false,null,[\"foo\\nbar\",3.5]]".to_strbuf());
|
"[false,null,[\"foo\\nbar\",3.5]]".to_string());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
long_test_list.to_pretty_str().into_strbuf(),
|
long_test_list.to_pretty_str().into_string(),
|
||||||
"\
|
"\
|
||||||
[\n \
|
[\n \
|
||||||
false,\n \
|
false,\n \
|
||||||
@@ -2706,47 +2706,47 @@ mod tests {
|
|||||||
\"foo\\nbar\",\n \
|
\"foo\\nbar\",\n \
|
||||||
3.5\n \
|
3.5\n \
|
||||||
]\n\
|
]\n\
|
||||||
]".to_strbuf()
|
]".to_string()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_write_object() {
|
fn test_write_object() {
|
||||||
assert_eq!(mk_object([]).to_str().into_strbuf(), "{}".to_strbuf());
|
assert_eq!(mk_object([]).to_str().into_string(), "{}".to_string());
|
||||||
assert_eq!(mk_object([]).to_pretty_str().into_strbuf(), "{}".to_strbuf());
|
assert_eq!(mk_object([]).to_pretty_str().into_string(), "{}".to_string());
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
mk_object([
|
mk_object([
|
||||||
("a".to_strbuf(), Boolean(true))
|
("a".to_string(), Boolean(true))
|
||||||
]).to_str().into_strbuf(),
|
]).to_str().into_string(),
|
||||||
"{\"a\":true}".to_strbuf()
|
"{\"a\":true}".to_string()
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
mk_object([("a".to_strbuf(), Boolean(true))]).to_pretty_str(),
|
mk_object([("a".to_string(), Boolean(true))]).to_pretty_str(),
|
||||||
"\
|
"\
|
||||||
{\n \
|
{\n \
|
||||||
\"a\": true\n\
|
\"a\": true\n\
|
||||||
}".to_strbuf()
|
}".to_string()
|
||||||
);
|
);
|
||||||
|
|
||||||
let complex_obj = mk_object([
|
let complex_obj = mk_object([
|
||||||
("b".to_strbuf(), List(vec![
|
("b".to_string(), List(vec![
|
||||||
mk_object([("c".to_strbuf(), String("\x0c\r".to_strbuf()))]),
|
mk_object([("c".to_string(), String("\x0c\r".to_string()))]),
|
||||||
mk_object([("d".to_strbuf(), String("".to_strbuf()))])
|
mk_object([("d".to_string(), String("".to_string()))])
|
||||||
]))
|
]))
|
||||||
]);
|
]);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
complex_obj.to_str().into_strbuf(),
|
complex_obj.to_str().into_string(),
|
||||||
"{\
|
"{\
|
||||||
\"b\":[\
|
\"b\":[\
|
||||||
{\"c\":\"\\f\\r\"},\
|
{\"c\":\"\\f\\r\"},\
|
||||||
{\"d\":\"\"}\
|
{\"d\":\"\"}\
|
||||||
]\
|
]\
|
||||||
}".to_strbuf()
|
}".to_string()
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
complex_obj.to_pretty_str().into_strbuf(),
|
complex_obj.to_pretty_str().into_string(),
|
||||||
"\
|
"\
|
||||||
{\n \
|
{\n \
|
||||||
\"b\": [\n \
|
\"b\": [\n \
|
||||||
@@ -2757,14 +2757,14 @@ mod tests {
|
|||||||
\"d\": \"\"\n \
|
\"d\": \"\"\n \
|
||||||
}\n \
|
}\n \
|
||||||
]\n\
|
]\n\
|
||||||
}".to_strbuf()
|
}".to_string()
|
||||||
);
|
);
|
||||||
|
|
||||||
let a = mk_object([
|
let a = mk_object([
|
||||||
("a".to_strbuf(), Boolean(true)),
|
("a".to_string(), Boolean(true)),
|
||||||
("b".to_strbuf(), List(vec![
|
("b".to_string(), List(vec![
|
||||||
mk_object([("c".to_strbuf(), String("\x0c\r".to_strbuf()))]),
|
mk_object([("c".to_string(), String("\x0c\r".to_string()))]),
|
||||||
mk_object([("d".to_strbuf(), String("".to_strbuf()))])
|
mk_object([("d".to_string(), String("".to_string()))])
|
||||||
]))
|
]))
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -2781,7 +2781,7 @@ mod tests {
|
|||||||
|
|
||||||
let mut m = MemWriter::new();
|
let mut m = MemWriter::new();
|
||||||
f(&mut m as &mut io::Writer);
|
f(&mut m as &mut io::Writer);
|
||||||
str::from_utf8(m.unwrap().as_slice()).unwrap().to_strbuf()
|
str::from_utf8(m.unwrap().as_slice()).unwrap().to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -2792,23 +2792,23 @@ mod tests {
|
|||||||
let mut encoder = Encoder::new(wr);
|
let mut encoder = Encoder::new(wr);
|
||||||
animal.encode(&mut encoder).unwrap();
|
animal.encode(&mut encoder).unwrap();
|
||||||
}),
|
}),
|
||||||
"\"Dog\"".to_strbuf()
|
"\"Dog\"".to_string()
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
with_str_writer(|wr| {
|
with_str_writer(|wr| {
|
||||||
let mut encoder = PrettyEncoder::new(wr);
|
let mut encoder = PrettyEncoder::new(wr);
|
||||||
animal.encode(&mut encoder).unwrap();
|
animal.encode(&mut encoder).unwrap();
|
||||||
}),
|
}),
|
||||||
"\"Dog\"".to_strbuf()
|
"\"Dog\"".to_string()
|
||||||
);
|
);
|
||||||
|
|
||||||
let animal = Frog("Henry".to_strbuf(), 349);
|
let animal = Frog("Henry".to_string(), 349);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
with_str_writer(|wr| {
|
with_str_writer(|wr| {
|
||||||
let mut encoder = Encoder::new(wr);
|
let mut encoder = Encoder::new(wr);
|
||||||
animal.encode(&mut encoder).unwrap();
|
animal.encode(&mut encoder).unwrap();
|
||||||
}),
|
}),
|
||||||
"{\"variant\":\"Frog\",\"fields\":[\"Henry\",349]}".to_strbuf()
|
"{\"variant\":\"Frog\",\"fields\":[\"Henry\",349]}".to_string()
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
with_str_writer(|wr| {
|
with_str_writer(|wr| {
|
||||||
@@ -2820,25 +2820,25 @@ mod tests {
|
|||||||
\"Frog\",\n \
|
\"Frog\",\n \
|
||||||
\"Henry\",\n \
|
\"Henry\",\n \
|
||||||
349\n\
|
349\n\
|
||||||
]".to_strbuf()
|
]".to_string()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_write_some() {
|
fn test_write_some() {
|
||||||
let value = Some("jodhpurs".to_strbuf());
|
let value = Some("jodhpurs".to_string());
|
||||||
let s = with_str_writer(|wr| {
|
let s = with_str_writer(|wr| {
|
||||||
let mut encoder = Encoder::new(wr);
|
let mut encoder = Encoder::new(wr);
|
||||||
value.encode(&mut encoder).unwrap();
|
value.encode(&mut encoder).unwrap();
|
||||||
});
|
});
|
||||||
assert_eq!(s, "\"jodhpurs\"".to_strbuf());
|
assert_eq!(s, "\"jodhpurs\"".to_string());
|
||||||
|
|
||||||
let value = Some("jodhpurs".to_strbuf());
|
let value = Some("jodhpurs".to_string());
|
||||||
let s = with_str_writer(|wr| {
|
let s = with_str_writer(|wr| {
|
||||||
let mut encoder = PrettyEncoder::new(wr);
|
let mut encoder = PrettyEncoder::new(wr);
|
||||||
value.encode(&mut encoder).unwrap();
|
value.encode(&mut encoder).unwrap();
|
||||||
});
|
});
|
||||||
assert_eq!(s, "\"jodhpurs\"".to_strbuf());
|
assert_eq!(s, "\"jodhpurs\"".to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -2848,13 +2848,13 @@ mod tests {
|
|||||||
let mut encoder = Encoder::new(wr);
|
let mut encoder = Encoder::new(wr);
|
||||||
value.encode(&mut encoder).unwrap();
|
value.encode(&mut encoder).unwrap();
|
||||||
});
|
});
|
||||||
assert_eq!(s, "null".to_strbuf());
|
assert_eq!(s, "null".to_string());
|
||||||
|
|
||||||
let s = with_str_writer(|wr| {
|
let s = with_str_writer(|wr| {
|
||||||
let mut encoder = Encoder::new(wr);
|
let mut encoder = Encoder::new(wr);
|
||||||
value.encode(&mut encoder).unwrap();
|
value.encode(&mut encoder).unwrap();
|
||||||
});
|
});
|
||||||
assert_eq!(s, "null".to_strbuf());
|
assert_eq!(s, "null".to_string());
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn test_read_identifiers() {
|
fn test_read_identifiers() {
|
||||||
@@ -3014,16 +3014,16 @@ mod tests {
|
|||||||
assert_eq!(from_str("\""), Err(SyntaxError(EOFWhileParsingString, 1, 2)));
|
assert_eq!(from_str("\""), Err(SyntaxError(EOFWhileParsingString, 1, 2)));
|
||||||
assert_eq!(from_str("\"lol"), Err(SyntaxError(EOFWhileParsingString, 1, 5)));
|
assert_eq!(from_str("\"lol"), Err(SyntaxError(EOFWhileParsingString, 1, 5)));
|
||||||
|
|
||||||
assert_eq!(from_str("\"\""), Ok(String("".to_strbuf())));
|
assert_eq!(from_str("\"\""), Ok(String("".to_string())));
|
||||||
assert_eq!(from_str("\"foo\""), Ok(String("foo".to_strbuf())));
|
assert_eq!(from_str("\"foo\""), Ok(String("foo".to_string())));
|
||||||
assert_eq!(from_str("\"\\\"\""), Ok(String("\"".to_strbuf())));
|
assert_eq!(from_str("\"\\\"\""), Ok(String("\"".to_string())));
|
||||||
assert_eq!(from_str("\"\\b\""), Ok(String("\x08".to_strbuf())));
|
assert_eq!(from_str("\"\\b\""), Ok(String("\x08".to_string())));
|
||||||
assert_eq!(from_str("\"\\n\""), Ok(String("\n".to_strbuf())));
|
assert_eq!(from_str("\"\\n\""), Ok(String("\n".to_string())));
|
||||||
assert_eq!(from_str("\"\\r\""), Ok(String("\r".to_strbuf())));
|
assert_eq!(from_str("\"\\r\""), Ok(String("\r".to_string())));
|
||||||
assert_eq!(from_str("\"\\t\""), Ok(String("\t".to_strbuf())));
|
assert_eq!(from_str("\"\\t\""), Ok(String("\t".to_string())));
|
||||||
assert_eq!(from_str(" \"foo\" "), Ok(String("foo".to_strbuf())));
|
assert_eq!(from_str(" \"foo\" "), Ok(String("foo".to_string())));
|
||||||
assert_eq!(from_str("\"\\u12ab\""), Ok(String("\u12ab".to_strbuf())));
|
assert_eq!(from_str("\"\\u12ab\""), Ok(String("\u12ab".to_string())));
|
||||||
assert_eq!(from_str("\"\\uAB12\""), Ok(String("\uAB12".to_strbuf())));
|
assert_eq!(from_str("\"\\uAB12\""), Ok(String("\uAB12".to_string())));
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -3139,22 +3139,22 @@ mod tests {
|
|||||||
|
|
||||||
assert_eq!(from_str("{}").unwrap(), mk_object([]));
|
assert_eq!(from_str("{}").unwrap(), mk_object([]));
|
||||||
assert_eq!(from_str("{\"a\": 3}").unwrap(),
|
assert_eq!(from_str("{\"a\": 3}").unwrap(),
|
||||||
mk_object([("a".to_strbuf(), Number(3.0))]));
|
mk_object([("a".to_string(), Number(3.0))]));
|
||||||
|
|
||||||
assert_eq!(from_str(
|
assert_eq!(from_str(
|
||||||
"{ \"a\": null, \"b\" : true }").unwrap(),
|
"{ \"a\": null, \"b\" : true }").unwrap(),
|
||||||
mk_object([
|
mk_object([
|
||||||
("a".to_strbuf(), Null),
|
("a".to_string(), Null),
|
||||||
("b".to_strbuf(), Boolean(true))]));
|
("b".to_string(), Boolean(true))]));
|
||||||
assert_eq!(from_str("\n{ \"a\": null, \"b\" : true }\n").unwrap(),
|
assert_eq!(from_str("\n{ \"a\": null, \"b\" : true }\n").unwrap(),
|
||||||
mk_object([
|
mk_object([
|
||||||
("a".to_strbuf(), Null),
|
("a".to_string(), Null),
|
||||||
("b".to_strbuf(), Boolean(true))]));
|
("b".to_string(), Boolean(true))]));
|
||||||
assert_eq!(from_str(
|
assert_eq!(from_str(
|
||||||
"{\"a\" : 1.0 ,\"b\": [ true ]}").unwrap(),
|
"{\"a\" : 1.0 ,\"b\": [ true ]}").unwrap(),
|
||||||
mk_object([
|
mk_object([
|
||||||
("a".to_strbuf(), Number(1.0)),
|
("a".to_string(), Number(1.0)),
|
||||||
("b".to_strbuf(), List(vec![Boolean(true)]))
|
("b".to_string(), List(vec![Boolean(true)]))
|
||||||
]));
|
]));
|
||||||
assert_eq!(from_str(
|
assert_eq!(from_str(
|
||||||
"{\
|
"{\
|
||||||
@@ -3166,12 +3166,12 @@ mod tests {
|
|||||||
]\
|
]\
|
||||||
}").unwrap(),
|
}").unwrap(),
|
||||||
mk_object([
|
mk_object([
|
||||||
("a".to_strbuf(), Number(1.0)),
|
("a".to_string(), Number(1.0)),
|
||||||
("b".to_strbuf(), List(vec![
|
("b".to_string(), List(vec![
|
||||||
Boolean(true),
|
Boolean(true),
|
||||||
String("foo\nbar".to_strbuf()),
|
String("foo\nbar".to_string()),
|
||||||
mk_object([
|
mk_object([
|
||||||
("c".to_strbuf(), mk_object([("d".to_strbuf(), Null)]))
|
("c".to_string(), mk_object([("d".to_string(), Null)]))
|
||||||
])
|
])
|
||||||
]))
|
]))
|
||||||
]));
|
]));
|
||||||
@@ -3256,7 +3256,7 @@ mod tests {
|
|||||||
v,
|
v,
|
||||||
Outer {
|
Outer {
|
||||||
inner: vec![
|
inner: vec![
|
||||||
Inner { a: (), b: 2, c: vec!["abc".to_strbuf(), "xyz".to_strbuf()] }
|
Inner { a: (), b: 2, c: vec!["abc".to_string(), "xyz".to_string()] }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -3268,7 +3268,7 @@ mod tests {
|
|||||||
assert_eq!(value, Ok(None));
|
assert_eq!(value, Ok(None));
|
||||||
|
|
||||||
let value: Result<Option<String>, ParserError> = from_iter("\"jodhpurs\"".chars());
|
let value: Result<Option<String>, ParserError> = from_iter("\"jodhpurs\"".chars());
|
||||||
assert_eq!(value, Ok(Some("jodhpurs".to_strbuf())));
|
assert_eq!(value, Ok(Some("jodhpurs".to_string())));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -3279,7 +3279,7 @@ mod tests {
|
|||||||
|
|
||||||
let s = "{\"variant\":\"Frog\",\"fields\":[\"Henry\",349]}";
|
let s = "{\"variant\":\"Frog\",\"fields\":[\"Henry\",349]}";
|
||||||
let value: Result<Animal, ParserError> = from_iter(s.chars());
|
let value: Result<Animal, ParserError> = from_iter(s.chars());
|
||||||
assert_eq!(value, Ok(Frog("Henry".to_strbuf(), 349)));
|
assert_eq!(value, Ok(Frog("Henry".to_string(), 349)));
|
||||||
|
|
||||||
let mut decoder = Decoder::new(from_str("\"Dog\"").unwrap());
|
let mut decoder = Decoder::new(from_str("\"Dog\"").unwrap());
|
||||||
let value: Animal = Decodable::decode(&mut decoder).unwrap();
|
let value: Animal = Decodable::decode(&mut decoder).unwrap();
|
||||||
@@ -3288,7 +3288,7 @@ mod tests {
|
|||||||
let s = "{\"variant\":\"Frog\",\"fields\":[\"Henry\",349]}";
|
let s = "{\"variant\":\"Frog\",\"fields\":[\"Henry\",349]}";
|
||||||
let mut decoder = Decoder::new(from_str(s).unwrap());
|
let mut decoder = Decoder::new(from_str(s).unwrap());
|
||||||
let value: Animal = Decodable::decode(&mut decoder).unwrap();
|
let value: Animal = Decodable::decode(&mut decoder).unwrap();
|
||||||
assert_eq!(value, Frog("Henry".to_strbuf(), 349));
|
assert_eq!(value, Frog("Henry".to_string(), 349));
|
||||||
assert_eq!(value, Dog);
|
assert_eq!(value, Dog);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
@@ -3301,8 +3301,8 @@ mod tests {
|
|||||||
let mut decoder = Decoder::new(from_str(s).unwrap());
|
let mut decoder = Decoder::new(from_str(s).unwrap());
|
||||||
let mut map: TreeMap<String, Animal> = Decodable::decode(&mut decoder).unwrap();
|
let mut map: TreeMap<String, Animal> = Decodable::decode(&mut decoder).unwrap();
|
||||||
|
|
||||||
assert_eq!(map.pop(&"a".to_strbuf()), Some(Dog));
|
assert_eq!(map.pop(&"a".to_string()), Some(Dog));
|
||||||
assert_eq!(map.pop(&"b".to_strbuf()), Some(Frog("Henry".to_strbuf(), 349)));
|
assert_eq!(map.pop(&"b".to_string()), Some(Frog("Henry".to_string(), 349)));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -3341,51 +3341,51 @@ mod tests {
|
|||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn test_decode_errors_struct() {
|
fn test_decode_errors_struct() {
|
||||||
check_err::<DecodeStruct>("[]", ExpectedError("Object".to_strbuf(), "[]".to_strbuf()));
|
check_err::<DecodeStruct>("[]", ExpectedError("Object".to_string(), "[]".to_string()));
|
||||||
check_err::<DecodeStruct>("{\"x\": true, \"y\": true, \"z\": \"\", \"w\": []}",
|
check_err::<DecodeStruct>("{\"x\": true, \"y\": true, \"z\": \"\", \"w\": []}",
|
||||||
ExpectedError("Number".to_strbuf(), "true".to_strbuf()));
|
ExpectedError("Number".to_string(), "true".to_string()));
|
||||||
check_err::<DecodeStruct>("{\"x\": 1, \"y\": [], \"z\": \"\", \"w\": []}",
|
check_err::<DecodeStruct>("{\"x\": 1, \"y\": [], \"z\": \"\", \"w\": []}",
|
||||||
ExpectedError("Boolean".to_strbuf(), "[]".to_strbuf()));
|
ExpectedError("Boolean".to_string(), "[]".to_string()));
|
||||||
check_err::<DecodeStruct>("{\"x\": 1, \"y\": true, \"z\": {}, \"w\": []}",
|
check_err::<DecodeStruct>("{\"x\": 1, \"y\": true, \"z\": {}, \"w\": []}",
|
||||||
ExpectedError("String".to_strbuf(), "{}".to_strbuf()));
|
ExpectedError("String".to_string(), "{}".to_string()));
|
||||||
check_err::<DecodeStruct>("{\"x\": 1, \"y\": true, \"z\": \"\", \"w\": null}",
|
check_err::<DecodeStruct>("{\"x\": 1, \"y\": true, \"z\": \"\", \"w\": null}",
|
||||||
ExpectedError("List".to_strbuf(), "null".to_strbuf()));
|
ExpectedError("List".to_string(), "null".to_string()));
|
||||||
check_err::<DecodeStruct>("{\"x\": 1, \"y\": true, \"z\": \"\"}",
|
check_err::<DecodeStruct>("{\"x\": 1, \"y\": true, \"z\": \"\"}",
|
||||||
MissingFieldError("w".to_strbuf()));
|
MissingFieldError("w".to_string()));
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn test_decode_errors_enum() {
|
fn test_decode_errors_enum() {
|
||||||
check_err::<DecodeEnum>("{}",
|
check_err::<DecodeEnum>("{}",
|
||||||
MissingFieldError("variant".to_strbuf()));
|
MissingFieldError("variant".to_string()));
|
||||||
check_err::<DecodeEnum>("{\"variant\": 1}",
|
check_err::<DecodeEnum>("{\"variant\": 1}",
|
||||||
ExpectedError("String".to_strbuf(), "1".to_strbuf()));
|
ExpectedError("String".to_string(), "1".to_string()));
|
||||||
check_err::<DecodeEnum>("{\"variant\": \"A\"}",
|
check_err::<DecodeEnum>("{\"variant\": \"A\"}",
|
||||||
MissingFieldError("fields".to_strbuf()));
|
MissingFieldError("fields".to_string()));
|
||||||
check_err::<DecodeEnum>("{\"variant\": \"A\", \"fields\": null}",
|
check_err::<DecodeEnum>("{\"variant\": \"A\", \"fields\": null}",
|
||||||
ExpectedError("List".to_strbuf(), "null".to_strbuf()));
|
ExpectedError("List".to_string(), "null".to_string()));
|
||||||
check_err::<DecodeEnum>("{\"variant\": \"C\", \"fields\": []}",
|
check_err::<DecodeEnum>("{\"variant\": \"C\", \"fields\": []}",
|
||||||
UnknownVariantError("C".to_strbuf()));
|
UnknownVariantError("C".to_string()));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_find(){
|
fn test_find(){
|
||||||
let json_value = from_str("{\"dog\" : \"cat\"}").unwrap();
|
let json_value = from_str("{\"dog\" : \"cat\"}").unwrap();
|
||||||
let found_str = json_value.find(&"dog".to_strbuf());
|
let found_str = json_value.find(&"dog".to_string());
|
||||||
assert!(found_str.is_some() && found_str.unwrap().as_string().unwrap() == "cat");
|
assert!(found_str.is_some() && found_str.unwrap().as_string().unwrap() == "cat");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_find_path(){
|
fn test_find_path(){
|
||||||
let json_value = from_str("{\"dog\":{\"cat\": {\"mouse\" : \"cheese\"}}}").unwrap();
|
let json_value = from_str("{\"dog\":{\"cat\": {\"mouse\" : \"cheese\"}}}").unwrap();
|
||||||
let found_str = json_value.find_path(&[&"dog".to_strbuf(),
|
let found_str = json_value.find_path(&[&"dog".to_string(),
|
||||||
&"cat".to_strbuf(), &"mouse".to_strbuf()]);
|
&"cat".to_string(), &"mouse".to_string()]);
|
||||||
assert!(found_str.is_some() && found_str.unwrap().as_string().unwrap() == "cheese");
|
assert!(found_str.is_some() && found_str.unwrap().as_string().unwrap() == "cheese");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_search(){
|
fn test_search(){
|
||||||
let json_value = from_str("{\"dog\":{\"cat\": {\"mouse\" : \"cheese\"}}}").unwrap();
|
let json_value = from_str("{\"dog\":{\"cat\": {\"mouse\" : \"cheese\"}}}").unwrap();
|
||||||
let found_str = json_value.search(&"mouse".to_strbuf()).and_then(|j| j.as_string());
|
let found_str = json_value.search(&"mouse".to_string()).and_then(|j| j.as_string());
|
||||||
assert!(found_str.is_some());
|
assert!(found_str.is_some());
|
||||||
assert!(found_str.unwrap() == "cheese");
|
assert!(found_str.unwrap() == "cheese");
|
||||||
}
|
}
|
||||||
@@ -3548,7 +3548,7 @@ mod tests {
|
|||||||
r#"{ "foo":"bar", "array" : [0, 1, 2,3 ,4,5], "idents":[null,true,false]}"#,
|
r#"{ "foo":"bar", "array" : [0, 1, 2,3 ,4,5], "idents":[null,true,false]}"#,
|
||||||
~[
|
~[
|
||||||
(ObjectStart, ~[]),
|
(ObjectStart, ~[]),
|
||||||
(StringValue("bar".to_strbuf()), ~[Key("foo")]),
|
(StringValue("bar".to_string()), ~[Key("foo")]),
|
||||||
(ListStart, ~[Key("array")]),
|
(ListStart, ~[Key("array")]),
|
||||||
(NumberValue(0.0), ~[Key("array"), Index(0)]),
|
(NumberValue(0.0), ~[Key("array"), Index(0)]),
|
||||||
(NumberValue(1.0), ~[Key("array"), Index(1)]),
|
(NumberValue(1.0), ~[Key("array"), Index(1)]),
|
||||||
@@ -3637,7 +3637,7 @@ mod tests {
|
|||||||
(NumberValue(1.0), ~[Key("a")]),
|
(NumberValue(1.0), ~[Key("a")]),
|
||||||
(ListStart, ~[Key("b")]),
|
(ListStart, ~[Key("b")]),
|
||||||
(BooleanValue(true), ~[Key("b"), Index(0)]),
|
(BooleanValue(true), ~[Key("b"), Index(0)]),
|
||||||
(StringValue("foo\nbar".to_strbuf()), ~[Key("b"), Index(1)]),
|
(StringValue("foo\nbar".to_string()), ~[Key("b"), Index(1)]),
|
||||||
(ObjectStart, ~[Key("b"), Index(2)]),
|
(ObjectStart, ~[Key("b"), Index(2)]),
|
||||||
(ObjectStart, ~[Key("b"), Index(2), Key("c")]),
|
(ObjectStart, ~[Key("b"), Index(2), Key("c")]),
|
||||||
(NullValue, ~[Key("b"), Index(2), Key("c"), Key("d")]),
|
(NullValue, ~[Key("b"), Index(2), Key("c"), Key("d")]),
|
||||||
@@ -3770,7 +3770,7 @@ mod tests {
|
|||||||
assert!(stack.last_is_index());
|
assert!(stack.last_is_index());
|
||||||
assert!(stack.get(0) == Index(1));
|
assert!(stack.get(0) == Index(1));
|
||||||
|
|
||||||
stack.push_key("foo".to_strbuf());
|
stack.push_key("foo".to_string());
|
||||||
|
|
||||||
assert!(stack.len() == 2);
|
assert!(stack.len() == 2);
|
||||||
assert!(stack.is_equal_to([Index(1), Key("foo")]));
|
assert!(stack.is_equal_to([Index(1), Key("foo")]));
|
||||||
@@ -3782,7 +3782,7 @@ mod tests {
|
|||||||
assert!(stack.get(0) == Index(1));
|
assert!(stack.get(0) == Index(1));
|
||||||
assert!(stack.get(1) == Key("foo"));
|
assert!(stack.get(1) == Key("foo"));
|
||||||
|
|
||||||
stack.push_key("bar".to_strbuf());
|
stack.push_key("bar".to_string());
|
||||||
|
|
||||||
assert!(stack.len() == 3);
|
assert!(stack.len() == 3);
|
||||||
assert!(stack.is_equal_to([Index(1), Key("foo"), Key("bar")]));
|
assert!(stack.is_equal_to([Index(1), Key("foo"), Key("bar")]));
|
||||||
@@ -3846,7 +3846,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn big_json() -> String {
|
fn big_json() -> String {
|
||||||
let mut src = "[\n".to_strbuf();
|
let mut src = "[\n".to_string();
|
||||||
for _ in range(0, 500) {
|
for _ in range(0, 500) {
|
||||||
src.push_str(r#"{ "a": true, "b": null, "c":3.1415, "d": "Hello world", "e": \
|
src.push_str(r#"{ "a": true, "b": null, "c":3.1415, "d": "Hello world", "e": \
|
||||||
[1,2,3]},"#);
|
[1,2,3]},"#);
|
||||||
|
|||||||
Reference in New Issue
Block a user