Allow struct fields be named as 'name' (issue #21)

This commit is contained in:
Dmitry Samoylov
2019-12-10 13:16:28 +07:00
parent 2a3716c828
commit 85f461573b
3 changed files with 55 additions and 8 deletions

View File

@@ -350,3 +350,21 @@ fn de_attribute_enum() {
}
);
}
#[test]
fn de_name_issue_21() {
#[derive(YaDeserialize, PartialEq, Debug)]
#[yaserde(root = "book")]
pub struct Book {
name: String,
}
let content = "<book><name>Little prince</name></book>";
convert_and_validate!(
content,
Book,
Book {
name: String::from("Little prince"),
}
);
}

View File

@@ -298,3 +298,19 @@ fn ser_attribute_enum() {
let content = "<?xml version=\"1.0\" encoding=\"utf-8\"?><base color=\"pink\" />";
convert_and_validate!(model, content);
}
#[test]
fn ser_name_issue_21() {
#[derive(YaSerialize, PartialEq, Debug)]
#[yaserde(root = "base")]
pub struct XmlStruct {
name: String,
}
let model = XmlStruct {
name: "something".to_string(),
};
let content = "<?xml version=\"1.0\" encoding=\"utf-8\"?><base><name>something</name></base>";
convert_and_validate!(model, content);
}