Use string literals instead of idents for `rename_all`
This commit is contained in:
parent
92dc3c8e73
commit
0d29741b6f
|
@ -43,14 +43,14 @@ impl Default for RenameRule {
|
||||||
}
|
}
|
||||||
|
|
||||||
static RENAME_RULES: &[(&str, RenameRule)] = &[
|
static RENAME_RULES: &[(&str, RenameRule)] = &[
|
||||||
("lowercase", LowerCase),
|
("\"lowercase\"", LowerCase),
|
||||||
("UPPERCASE", UpperCase),
|
("\"UPPERCASE\"", UpperCase),
|
||||||
("PascalCase", PascalCase),
|
("\"PascalCase\"", PascalCase),
|
||||||
("camelCase", CamelCase),
|
("\"camelCase\"", CamelCase),
|
||||||
("snake_case", SnakeCase),
|
("\"snake_case\"", SnakeCase),
|
||||||
("SCREAMING_SNAKE_CASE", ScreamingSnakeCase),
|
("\"SCREAMING_SNAKE_CASE\"", ScreamingSnakeCase),
|
||||||
("kebab-case", KebabCase),
|
("\"kebab-case\"", KebabCase),
|
||||||
("SCREAMING-KEBAB-CASE", ScreamingKebabCase),
|
("\"SCREAMING-KEBAB-CASE\"", ScreamingKebabCase),
|
||||||
];
|
];
|
||||||
|
|
||||||
impl RenameRule {
|
impl RenameRule {
|
||||||
|
|
|
@ -498,8 +498,8 @@ fn meta_items(attrs: &[syn::Attribute]) -> Vec<MetaItem> {
|
||||||
items.push(MetaItem::Rename(lit));
|
items.push(MetaItem::Rename(lit));
|
||||||
MetaState::Comma
|
MetaState::Comma
|
||||||
}
|
}
|
||||||
(MetaState::RenameAllValue, TokenTree::Ident(ident)) => {
|
(MetaState::RenameAllValue, TokenTree::Literal(lit)) => {
|
||||||
items.push(MetaItem::RenameAll(ident));
|
items.push(MetaItem::RenameAll(lit));
|
||||||
MetaState::Comma
|
MetaState::Comma
|
||||||
}
|
}
|
||||||
(state, tree) => {
|
(state, tree) => {
|
||||||
|
@ -595,7 +595,7 @@ enum MetaItem {
|
||||||
Ns(NamespaceMeta),
|
Ns(NamespaceMeta),
|
||||||
Rename(Literal),
|
Rename(Literal),
|
||||||
Scalar,
|
Scalar,
|
||||||
RenameAll(Ident),
|
RenameAll(Literal),
|
||||||
}
|
}
|
||||||
|
|
||||||
enum Namespace {
|
enum Namespace {
|
||||||
|
@ -765,7 +765,7 @@ mod tests {
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
fn struct_rename_all_permitted() {
|
fn struct_rename_all_permitted() {
|
||||||
assert_eq!(super::ser::to_xml(&parse_quote! {
|
assert_eq!(super::ser::to_xml(&parse_quote! {
|
||||||
#[xml(rename_all = UPPERCASE)]
|
#[xml(rename_all = "UPPERCASE")]
|
||||||
pub struct TestStruct {
|
pub struct TestStruct {
|
||||||
field_1: String,
|
field_1: String,
|
||||||
field_2: u8,
|
field_2: u8,
|
||||||
|
@ -777,7 +777,7 @@ mod tests {
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
fn scalar_enum_rename_all_permitted() {
|
fn scalar_enum_rename_all_permitted() {
|
||||||
assert_eq!(super::ser::to_xml(&parse_quote! {
|
assert_eq!(super::ser::to_xml(&parse_quote! {
|
||||||
#[xml(scalar, rename_all = UPPERCASE)]
|
#[xml(scalar, rename_all = "UPPERCASE")]
|
||||||
pub enum TestEnum {
|
pub enum TestEnum {
|
||||||
Foo = 1,
|
Foo = 1,
|
||||||
Bar,
|
Bar,
|
||||||
|
@ -791,7 +791,7 @@ mod tests {
|
||||||
fn rename_all_attribute_not_permitted() {
|
fn rename_all_attribute_not_permitted() {
|
||||||
super::ser::to_xml(&parse_quote! {
|
super::ser::to_xml(&parse_quote! {
|
||||||
pub struct TestStruct {
|
pub struct TestStruct {
|
||||||
#[xml(rename_all = UPPERCASE)]
|
#[xml(rename_all = "UPPERCASE")]
|
||||||
field_1: String,
|
field_1: String,
|
||||||
field_2: u8,
|
field_2: u8,
|
||||||
}
|
}
|
||||||
|
@ -802,7 +802,7 @@ mod tests {
|
||||||
pub enum TestEnum {
|
pub enum TestEnum {
|
||||||
Foo = 1,
|
Foo = 1,
|
||||||
Bar,
|
Bar,
|
||||||
#[xml(rename_all = UPPERCASE)]
|
#[xml(rename_all = "UPPERCASE")]
|
||||||
Baz
|
Baz
|
||||||
}
|
}
|
||||||
}).to_string().find("compile_error ! { \"attribute 'rename_all' invalid in field xml attribute\" }").unwrap();
|
}).to_string().find("compile_error ! { \"attribute 'rename_all' invalid in field xml attribute\" }").unwrap();
|
||||||
|
@ -810,10 +810,10 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
#[should_panic(expected = "unknown rename rule `rename_all = \"forgetaboutit\"`, expected one of \"lowercase\", \"UPPERCASE\", \"PascalCase\", \"camelCase\", \"snake_case\", \"SCREAMING_SNAKE_CASE\", \"kebab-case\", \"SCREAMING-KEBAB-CASE\"")]
|
#[should_panic(expected = "unknown rename rule `rename_all = \"\\\"forgetaboutit\\\"\"`, expected one of \"\\\"lowercase\\\"\", \"\\\"UPPERCASE\\\"\", \"\\\"PascalCase\\\"\", \"\\\"camelCase\\\"\", \"\\\"snake_case\\\"\", \"\\\"SCREAMING_SNAKE_CASE\\\"\", \"\\\"kebab-case\\\"\", \"\\\"SCREAMING-KEBAB-CASE\\\"\"")]
|
||||||
fn bogus_rename_all_not_permitted() {
|
fn bogus_rename_all_not_permitted() {
|
||||||
super::ser::to_xml(&parse_quote! {
|
super::ser::to_xml(&parse_quote! {
|
||||||
#[xml(rename_all = forgetaboutit)]
|
#[xml(rename_all = "forgetaboutit")]
|
||||||
pub struct TestStruct {
|
pub struct TestStruct {
|
||||||
field_1: String,
|
field_1: String,
|
||||||
field_2: u8,
|
field_2: u8,
|
||||||
|
|
Loading…
Reference in New Issue