Finish updating to rust HEAD
This commit is contained in:
parent
b30965ede4
commit
d0b49d9b89
14
src/bytes.rs
14
src/bytes.rs
@ -12,10 +12,18 @@ pub struct Bytes<'a> {
|
||||
bytes: &'a [u8],
|
||||
}
|
||||
|
||||
impl<'a, T> From<T> for Bytes<'a> where T: Into<&'a [u8]> {
|
||||
fn from(bytes: T) -> Self {
|
||||
impl<'a> From<&'a [u8]> for Bytes<'a> {
|
||||
fn from(bytes: &'a [u8]) -> Self {
|
||||
Bytes {
|
||||
bytes: bytes.into(),
|
||||
bytes: bytes,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'a Vec<u8>> for Bytes<'a> {
|
||||
fn from(bytes: &'a Vec<u8>) -> Self {
|
||||
Bytes {
|
||||
bytes: &bytes,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
#![feature(convert, custom_derive, plugin, test)]
|
||||
#![feature(custom_derive, plugin, test)]
|
||||
#![plugin(serde_macros)]
|
||||
|
||||
extern crate test;
|
||||
@ -192,10 +192,12 @@ fn test_byte_buf_ser_bytes() {
|
||||
#[test]
|
||||
fn test_byte_buf_de_json() {
|
||||
let bytes = ByteBuf::new();
|
||||
assert_eq!(json::from_str("[]").unwrap(), bytes);
|
||||
let v: ByteBuf = json::from_str("[]").unwrap();
|
||||
assert_eq!(v, bytes);
|
||||
|
||||
let bytes = ByteBuf::from(vec![1, 2, 3]);
|
||||
assert_eq!(json::from_str("[1, 2, 3]").unwrap(), bytes);
|
||||
let v: ByteBuf = json::from_str("[1, 2, 3]").unwrap();
|
||||
assert_eq!(v, bytes);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -626,23 +626,20 @@ fn test_parse_ok<T>(errors: Vec<(&'static str, T)>)
|
||||
where T: Clone + Debug + PartialEq + ser::Serialize + de::Deserialize,
|
||||
{
|
||||
for (s, value) in errors {
|
||||
let v: Result<T, Error> = from_str(s);
|
||||
assert_eq!(v, Ok(value.clone()));
|
||||
let v: T = from_str(s).unwrap();
|
||||
assert_eq!(v, value.clone());
|
||||
|
||||
// Make sure we can deserialize into a `Value`.
|
||||
let json_value: Result<Value, Error> = from_str(s);
|
||||
assert_eq!(json_value, Ok(to_value(&value)));
|
||||
|
||||
let json_value = json_value.unwrap();
|
||||
|
||||
let json_value: Value = from_str(s).unwrap();
|
||||
assert_eq!(json_value, to_value(&value));
|
||||
|
||||
// Make sure we can deserialize from a `Value`.
|
||||
let v: Result<T, Error> = from_value(json_value.clone());
|
||||
assert_eq!(v, Ok(value));
|
||||
let v: T = from_value(json_value.clone()).unwrap();
|
||||
assert_eq!(v, value);
|
||||
|
||||
// Make sure we can round trip back to `Value`.
|
||||
let json_value2: Result<Value, Error> = from_value(json_value.clone());
|
||||
assert_eq!(json_value2, Ok(json_value));
|
||||
let json_value2: Value = from_value(json_value.clone()).unwrap();
|
||||
assert_eq!(json_value2, json_value);
|
||||
}
|
||||
}
|
||||
|
||||
@ -651,8 +648,20 @@ fn test_parse_err<T>(errors: Vec<(&'static str, Error)>)
|
||||
where T: Debug + PartialEq + de::Deserialize,
|
||||
{
|
||||
for (s, err) in errors {
|
||||
let v: Result<T, Error> = from_str(s);
|
||||
assert_eq!(v, Err(err));
|
||||
match (err, from_str::<T>(s).unwrap_err()) {
|
||||
(
|
||||
Error::SyntaxError(expected_code, expected_line, expected_col),
|
||||
Error::SyntaxError(actual_code, actual_line, actual_col),
|
||||
) => {
|
||||
assert_eq!(
|
||||
(expected_code, expected_line, expected_col),
|
||||
(actual_code, actual_line, actual_col)
|
||||
)
|
||||
}
|
||||
(expected_err, actual_err) => {
|
||||
panic!("unexpected errors {} != {}", expected_err, actual_err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -889,11 +898,13 @@ fn test_parse_struct() {
|
||||
)
|
||||
]);
|
||||
|
||||
let v: Outer = from_str("{}").unwrap();
|
||||
|
||||
assert_eq!(
|
||||
from_str("{}"),
|
||||
Ok(Outer {
|
||||
v,
|
||||
Outer {
|
||||
inner: vec![],
|
||||
})
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -142,10 +142,10 @@ fn test_named_unit() {
|
||||
Value::Null
|
||||
);
|
||||
|
||||
let v = json::from_str("null").unwrap();
|
||||
let v: NamedUnit = json::from_str("null").unwrap();
|
||||
assert_eq!(v, named_unit);
|
||||
|
||||
let v = json::from_value(Value::Null).unwrap();
|
||||
let v: NamedUnit = json::from_value(Value::Null).unwrap();
|
||||
assert_eq!(v, named_unit);
|
||||
}
|
||||
|
||||
@ -169,13 +169,15 @@ fn test_ser_named_tuple() {
|
||||
|
||||
#[test]
|
||||
fn test_de_named_tuple() {
|
||||
let v: DeNamedTuple<i32, i32, i32> = json::from_str("[1,2,3]").unwrap();
|
||||
assert_eq!(
|
||||
json::from_str("[1,2,3]").unwrap(),
|
||||
v,
|
||||
DeNamedTuple(1, 2, 3)
|
||||
);
|
||||
|
||||
let v: Value = json::from_str("[1,2,3]").unwrap();
|
||||
assert_eq!(
|
||||
json::from_str("[1,2,3]").unwrap(),
|
||||
v,
|
||||
Value::Array(vec![
|
||||
Value::U64(1),
|
||||
Value::U64(2),
|
||||
@ -218,19 +220,17 @@ fn test_de_named_map() {
|
||||
c: 7,
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
json::from_str("{\"a\":5,\"b\":6,\"c\":7}").unwrap(),
|
||||
v
|
||||
);
|
||||
let v2: DeNamedMap<i32, i32, i32> = json::from_str(
|
||||
"{\"a\":5,\"b\":6,\"c\":7}"
|
||||
).unwrap();
|
||||
assert_eq!(v, v2);
|
||||
|
||||
assert_eq!(
|
||||
json::from_value(Value::Object(btreemap![
|
||||
"a".to_string() => Value::U64(5),
|
||||
"b".to_string() => Value::U64(6),
|
||||
"c".to_string() => Value::U64(7)
|
||||
])).unwrap(),
|
||||
v
|
||||
);
|
||||
let v2 = json::from_value(Value::Object(btreemap![
|
||||
"a".to_string() => Value::U64(5),
|
||||
"b".to_string() => Value::U64(6),
|
||||
"c".to_string() => Value::U64(7)
|
||||
])).unwrap();
|
||||
assert_eq!(v, v2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -336,15 +336,17 @@ fn test_ser_enum_map() {
|
||||
|
||||
#[test]
|
||||
fn test_de_enum_unit() {
|
||||
let v: DeEnum<_, _, _> = json::from_str("{\"Unit\":[]}").unwrap();
|
||||
assert_eq!(
|
||||
json::from_str("{\"Unit\":[]}").unwrap(),
|
||||
v,
|
||||
DeEnum::Unit::<u32, u32, u32>
|
||||
);
|
||||
|
||||
let v: DeEnum<_, _, _> = json::from_value(Value::Object(btreemap!(
|
||||
"Unit".to_string() => Value::Array(vec![]))
|
||||
)).unwrap();
|
||||
assert_eq!(
|
||||
json::from_value(Value::Object(btreemap!(
|
||||
"Unit".to_string() => Value::Array(vec![]))
|
||||
)).unwrap(),
|
||||
v,
|
||||
DeEnum::Unit::<u32, u32, u32>
|
||||
);
|
||||
}
|
||||
@ -358,8 +360,9 @@ fn test_de_enum_seq() {
|
||||
let e = 5;
|
||||
//let f = 6;
|
||||
|
||||
let v: DeEnum<_, _, _> = json::from_str("{\"Seq\":[1,2,3,5]}").unwrap();
|
||||
assert_eq!(
|
||||
json::from_str("{\"Seq\":[1,2,3,5]}").unwrap(),
|
||||
v,
|
||||
DeEnum::Seq(
|
||||
a,
|
||||
b,
|
||||
@ -370,17 +373,18 @@ fn test_de_enum_seq() {
|
||||
)
|
||||
);
|
||||
|
||||
let v: DeEnum<_, _, _> = json::from_value(Value::Object(btreemap!(
|
||||
"Seq".to_string() => Value::Array(vec![
|
||||
Value::U64(1),
|
||||
Value::U64(2),
|
||||
Value::U64(3),
|
||||
//Value::U64(4),
|
||||
Value::U64(5),
|
||||
//Value::U64(6),
|
||||
])
|
||||
))).unwrap();
|
||||
assert_eq!(
|
||||
json::from_value(Value::Object(btreemap!(
|
||||
"Seq".to_string() => Value::Array(vec![
|
||||
Value::U64(1),
|
||||
Value::U64(2),
|
||||
Value::U64(3),
|
||||
//Value::U64(4),
|
||||
Value::U64(5),
|
||||
//Value::U64(6),
|
||||
])
|
||||
))).unwrap(),
|
||||
v,
|
||||
DeEnum::Seq(
|
||||
a,
|
||||
b,
|
||||
@ -401,8 +405,11 @@ fn test_de_enum_map() {
|
||||
let e = 5;
|
||||
//let f = 6;
|
||||
|
||||
let v: DeEnum<_, _, _> = json::from_str(
|
||||
"{\"Map\":{\"a\":1,\"b\":2,\"c\":3,\"e\":5}}"
|
||||
).unwrap();
|
||||
assert_eq!(
|
||||
json::from_str("{\"Map\":{\"a\":1,\"b\":2,\"c\":3,\"e\":5}}").unwrap(),
|
||||
v,
|
||||
DeEnum::Map {
|
||||
a: a,
|
||||
b: b,
|
||||
@ -413,17 +420,19 @@ fn test_de_enum_map() {
|
||||
}
|
||||
);
|
||||
|
||||
let v: DeEnum<_, _, _> = json::from_value(Value::Object(btreemap!(
|
||||
"Map".to_string() => Value::Object(btreemap![
|
||||
"a".to_string() => Value::U64(1),
|
||||
"b".to_string() => Value::U64(2),
|
||||
"c".to_string() => Value::U64(3),
|
||||
//"d".to_string() => Value::U64(4)
|
||||
"e".to_string() => Value::U64(5)
|
||||
//"f".to_string() => Value::U64(6)
|
||||
])
|
||||
))).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
json::from_value(Value::Object(btreemap!(
|
||||
"Map".to_string() => Value::Object(btreemap![
|
||||
"a".to_string() => Value::U64(1),
|
||||
"b".to_string() => Value::U64(2),
|
||||
"c".to_string() => Value::U64(3),
|
||||
//"d".to_string() => Value::U64(4)
|
||||
"e".to_string() => Value::U64(5)
|
||||
//"f".to_string() => Value::U64(6)
|
||||
])
|
||||
))).unwrap(),
|
||||
v,
|
||||
DeEnum::Map {
|
||||
a: a,
|
||||
b: b,
|
||||
|
Loading…
x
Reference in New Issue
Block a user