mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-04-25 18:37:55 +00:00
missing field errors displayed original field name instead of renamed
closes #63
This commit is contained in:
+24
-1
@@ -1,4 +1,4 @@
|
||||
#![feature(custom_derive, plugin, test)]
|
||||
#![feature(custom_derive, plugin, test, custom_attribute)]
|
||||
#![plugin(serde_macros)]
|
||||
|
||||
extern crate test;
|
||||
@@ -1019,3 +1019,26 @@ fn test_missing_field() {
|
||||
))).unwrap();
|
||||
assert_eq!(value, Foo { x: Some(5) });
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_missing_renamed_field() {
|
||||
#[derive(Debug, PartialEq, Deserialize)]
|
||||
struct Foo {
|
||||
#[serde(rename_deserialize="y")]
|
||||
x: Option<u32>,
|
||||
}
|
||||
|
||||
let value: Foo = from_str("{}").unwrap();
|
||||
assert_eq!(value, Foo { x: None });
|
||||
|
||||
let value: Foo = from_str("{\"y\": 5}").unwrap();
|
||||
assert_eq!(value, Foo { x: Some(5) });
|
||||
|
||||
let value: Foo = from_value(Value::Object(treemap!())).unwrap();
|
||||
assert_eq!(value, Foo { x: None });
|
||||
|
||||
let value: Foo = from_value(Value::Object(treemap!(
|
||||
"y".to_string() => Value::I64(5)
|
||||
))).unwrap();
|
||||
assert_eq!(value, Foo { x: Some(5) });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user