Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

40 structure names are missing if fields are named in cyrillic #41

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "xml_schema_generator"
version = "0.6.12"
version = "0.6.13"
description = "Create Rust struct for given XML file, that allows to deserliaze the given XML using serde or vice versa"
authors = ["Sebastian Detert <[email protected]>"]
edition = "2021"
Expand All @@ -22,7 +22,7 @@ path = "src/lib.rs"
env_logger = { version = "0.11.0", optional = true }
log = "0.4.20"
quick-xml = {version="0.36.0", features = ["serialize"] }
convert_string = "0.1.3"
convert_string = "0.2.0"
clap = { version = "4.4.11", features = ["derive"] }

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ You can add this dependency with:

```toml
[dependencies]
xml_schema_generator = "0.6.12"
xml_schema_generator = "0.6.13"
```

## Example
Expand Down
34 changes: 34 additions & 0 deletions src/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1437,4 +1437,38 @@ mod tests {
root.to_serde_struct(&Options::quick_xml_de())
);
}

// https://github.com/Thomblin/xml_schema_generator/issues/40
#[test]
fn to_serde_struct_with_cyrillic_names() {
let Классификатор = element!("Классификатор", None, vec!["Ид"]);
let КоммерческаяИнформация = element!(
"КоммерческаяИнформация",
None,
vec!["Наименование"],
vec![Классификатор]
);

let expected = concat!(
"#[derive(Serialize, Deserialize)]\n",
"pub struct КоммерческаяИнформация {\n",
" #[serde(rename = \"Наименование\")]\n",
" pub наименование: String,\n",
" #[serde(rename = \"Классификатор\")]\n",
" pub классификатор: Классификатор,\n",
"}\n",
"\n",
"#[derive(Serialize, Deserialize)]\n",
"pub struct Классификатор {\n",
" #[serde(rename = \"Ид\")]\n",
" pub ид: String,\n",
"}\n",
"\n"
);

assert_eq!(
String::from(expected),
КоммерческаяИнформация.to_serde_struct(&Options::serde_xml_rs())
);
}
}
18 changes: 18 additions & 0 deletions src/element/identifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,4 +274,22 @@ mod tests {
map.get_name("foo_attr", Type::Attribute).unwrap()
);
}

#[test]
fn return_cyrillic_names_unchanged() {
let element = element!(
"Классификатор",
Some("Классификатор"),
vec!["Ид"],
vec![element!("Наименование")]
);
let map = Map::new(&element);

assert_eq!("text", map.get_name("text", Type::TextContent).unwrap());
assert_eq!("ид", map.get_name("Ид", Type::Attribute).unwrap());
assert_eq!(
"наименование",
map.get_name("Наименование", Type::ChildElement).unwrap()
);
}
}
42 changes: 42 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,48 @@ pub struct TotalPriceDiffCurrency {
pub text: Option<String>,
}

";

assert_eq!(expected, root.to_serde_struct(&Options::quick_xml_de()));
}

// https://github.com/Thomblin/xml_schema_generator/issues/40
#[test]
fn parse_xml_and_return_struct_with_cyrillic_variables() {
let xml = "\
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<КоммерческаяИнформация>
<Классификатор>
<Ид>1</Ид>
<Наименование>Классификатор</Наименование>
<Владелец>Булат</Владелец>
</Классификатор>
</КоммерческаяИнформация>";
let mut reader = Reader::from_str(xml);

let root = into_struct(&mut reader).expect("expected to successfully parse into struct");

let expected = "\
#[derive(Serialize, Deserialize)]
pub struct КоммерческаяИнформация {
#[serde(rename = \"$text\")]
pub text: Option<String>,
#[serde(rename = \"Классификатор\")]
pub классификатор: Классификатор,
}

#[derive(Serialize, Deserialize)]
pub struct Классификатор {
#[serde(rename = \"$text\")]
pub text: Option<String>,
#[serde(rename = \"Ид\")]
pub ид: String,
#[serde(rename = \"Наименование\")]
pub наименование: String,
#[serde(rename = \"Владелец\")]
pub владелец: String,
}

";

assert_eq!(expected, root.to_serde_struct(&Options::quick_xml_de()));
Expand Down