Merge pull request #78 from media-io/fix_visitor_label
Fix visitor label
This commit is contained in:
commit
06dfc427fe
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "yaserde"
|
name = "yaserde"
|
||||||
version = "0.3.16"
|
version = "0.3.17"
|
||||||
authors = ["Marc-Antoine Arnaud <arnaud.marcantoine@gmail.com>"]
|
authors = ["Marc-Antoine Arnaud <arnaud.marcantoine@gmail.com>"]
|
||||||
description = "Serialization and deserialization library"
|
description = "Serialization and deserialization library"
|
||||||
keywords = ["Serialization", "Deserialization", "XML"]
|
keywords = ["Serialization", "Deserialization", "XML"]
|
||||||
|
|||||||
@ -46,6 +46,39 @@ fn de_basic() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn de_dash_param() {
|
||||||
|
#[derive(YaDeserialize, PartialEq, Debug)]
|
||||||
|
#[yaserde(root = "book")]
|
||||||
|
pub struct Book {
|
||||||
|
#[yaserde(rename = "author-release")]
|
||||||
|
author: String,
|
||||||
|
title: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
let content =
|
||||||
|
"<book><author-release>Antoine de Saint-Exupéry</author-release><title>Little prince</title></book>";
|
||||||
|
convert_and_validate!(
|
||||||
|
content,
|
||||||
|
Book,
|
||||||
|
Book {
|
||||||
|
author: String::from("Antoine de Saint-Exupéry"),
|
||||||
|
title: String::from("Little prince"),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
let content =
|
||||||
|
"<book><title>Little prince</title><author-release>Antoine de Saint-Exupéry</author-release></book>";
|
||||||
|
convert_and_validate!(
|
||||||
|
content,
|
||||||
|
Book,
|
||||||
|
Book {
|
||||||
|
author: String::from("Antoine de Saint-Exupéry"),
|
||||||
|
title: String::from("Little prince"),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn de_multiple_segments() {
|
fn de_multiple_segments() {
|
||||||
mod other_mod {
|
mod other_mod {
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "yaserde_derive"
|
name = "yaserde_derive"
|
||||||
version = "0.3.16"
|
version = "0.3.17"
|
||||||
authors = ["Marc-Antoine Arnaud <arnaud.marcantoine@gmail.com>"]
|
authors = ["Marc-Antoine Arnaud <arnaud.marcantoine@gmail.com>"]
|
||||||
description = "Serialization and deserialization macros"
|
description = "Serialization and deserialization macros"
|
||||||
keywords = ["Serialization", "Deserialization"]
|
keywords = ["Serialization", "Deserialization"]
|
||||||
@ -12,6 +12,7 @@ readme = "../README.md"
|
|||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
heck = "0.3.1"
|
||||||
syn = { version = "~1.0", features = ["visit", "extra-traits"] }
|
syn = { version = "~1.0", features = ["visit", "extra-traits"] }
|
||||||
proc-macro2 = "~1.0"
|
proc-macro2 = "~1.0"
|
||||||
quote = "~1.0"
|
quote = "~1.0"
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
use crate::common::attribute::YaSerdeAttribute;
|
use crate::common::attribute::YaSerdeAttribute;
|
||||||
|
use heck::CamelCase;
|
||||||
use proc_macro2::Span;
|
use proc_macro2::Span;
|
||||||
use proc_macro2::{Ident, TokenStream};
|
use proc_macro2::{Ident, TokenStream};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
@ -84,7 +85,11 @@ impl YaSerdeField {
|
|||||||
);
|
);
|
||||||
|
|
||||||
Ident::new(
|
Ident::new(
|
||||||
&format!("__Visitor_{}_{}", label.replace(".", "_"), struct_id),
|
&format!(
|
||||||
|
"__Visitor_{}_{}",
|
||||||
|
label.replace(".", "_").to_camel_case(),
|
||||||
|
struct_id
|
||||||
|
),
|
||||||
self.get_span(),
|
self.get_span(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
use crate::common::{Field, YaSerdeAttribute, YaSerdeField};
|
use crate::common::{Field, YaSerdeAttribute, YaSerdeField};
|
||||||
use crate::de::build_default_value::build_default_value;
|
use crate::de::build_default_value::build_default_value;
|
||||||
|
use heck::CamelCase;
|
||||||
use proc_macro2::{Span, TokenStream};
|
use proc_macro2::{Span, TokenStream};
|
||||||
use syn::{DataStruct, Ident};
|
use syn::{DataStruct, Ident};
|
||||||
|
|
||||||
@ -447,7 +448,11 @@ fn build_visitor_ident(label: &str, span: Span, struct_name: Option<&syn::Path>)
|
|||||||
);
|
);
|
||||||
|
|
||||||
Ident::new(
|
Ident::new(
|
||||||
&format!("__Visitor_{}_{}", label.replace(".", "_"), struct_id),
|
&format!(
|
||||||
|
"__Visitor_{}_{}",
|
||||||
|
label.replace(".", "_").to_camel_case(),
|
||||||
|
struct_id
|
||||||
|
),
|
||||||
span,
|
span,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user