Skip to content

Commit

Permalink
Merge pull request #93 from marcelbuesing/fix-keyword-in-label
Browse files Browse the repository at this point in the history
Avoid breaking keywords in labels.
  • Loading branch information
MarcAntoine-Arnaud committed Oct 12, 2020
2 parents 6e2930e + 798455f commit 15576ef
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
21 changes: 21 additions & 0 deletions yaserde/tests/deserializer.rs
Expand Up @@ -54,6 +54,27 @@ fn de_basic() {
);
}

#[test]
fn de_keyword() {
init();

#[derive(YaDeserialize, PartialEq, Debug)]
#[yaserde(root = "book")]
pub struct Book {
#[yaserde(attribute, rename = "ref")]
pub r#ref: String,
}

let content = "<book ref=\"978-1522968122\"></book>";
convert_and_validate!(
content,
Book,
Book {
r#ref: "978-1522968122".to_string()
}
);
}

#[test]
fn de_dash_param() {
init();
Expand Down
17 changes: 17 additions & 0 deletions yaserde/tests/serializer.rs
Expand Up @@ -326,6 +326,23 @@ fn ser_text_content_with_attributes() {
serialize_and_validate!(model, content);
}

#[test]
fn ser_keyword() {
#[derive(YaSerialize, PartialEq, Debug)]
#[yaserde(rename = "base")]
pub struct XmlStruct {
#[yaserde(attribute, rename = "ref")]
r#ref: String,
}

let model = XmlStruct {
r#ref: "978-1522968122".to_string(),
};

let content = "<base ref=\"978-1522968122\" />";
serialize_and_validate!(model, content);
}

#[test]
fn ser_name_issue_21() {
#[derive(YaSerialize, PartialEq, Debug)]
Expand Down
3 changes: 2 additions & 1 deletion yaserde_derive/src/common/field.rs
Expand Up @@ -3,6 +3,7 @@ use heck::CamelCase;
use proc_macro2::Span;
use proc_macro2::{Ident, TokenStream};
use std::fmt;
use syn::ext::IdentExt;
use syn::spanned::Spanned;
use syn::Type::Path;

Expand Down Expand Up @@ -43,7 +44,7 @@ impl YaSerdeField {
.syn_field
.ident
.clone()
.map(|ident| syn::Ident::new(&format!("__{}_value", ident.to_string()), ident.span()))
.map(|ident| syn::Ident::new(&format!("__{}_value", ident.unraw()), ident.span()))
}

pub fn renamed_label_without_namespace(&self) -> String {
Expand Down

0 comments on commit 15576ef

Please sign in to comment.