diff --git a/xsd-parser/tests/attribute_group/example.xml b/xsd-parser/tests/attribute_group/example.xml new file mode 100644 index 00000000..1fe42c64 --- /dev/null +++ b/xsd-parser/tests/attribute_group/example.xml @@ -0,0 +1 @@ + diff --git a/xsd-parser/tests/attribute_group/expected.rs b/xsd-parser/tests/attribute_group/expected.rs new file mode 100644 index 00000000..4caec64f --- /dev/null +++ b/xsd-parser/tests/attribute_group/expected.rs @@ -0,0 +1,14 @@ +#[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] +#[yaserde(prefix = "tns", namespace = "tns: http://example.com")] +pub struct FooType { + #[yaserde(attribute, rename = "id")] + pub id: Option, + + #[yaserde(attribute, rename = "aNumber")] + pub a_number: Option, +} + +impl Validate for FooType {} + + +// pub type Foo = FooType; diff --git a/xsd-parser/tests/attribute_group/input.xsd b/xsd-parser/tests/attribute_group/input.xsd new file mode 100644 index 00000000..90abfcaf --- /dev/null +++ b/xsd-parser/tests/attribute_group/input.xsd @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + diff --git a/xsd-parser/tests/attribute_group/mod.rs b/xsd-parser/tests/attribute_group/mod.rs new file mode 100644 index 00000000..0159d4dc --- /dev/null +++ b/xsd-parser/tests/attribute_group/mod.rs @@ -0,0 +1,33 @@ +use super::utils; + +#[test] +fn deserialization_works() { + mod expected { + use xsd_parser::generator::validator::Validate; + use yaserde_derive::{YaDeserialize, YaSerialize}; + + include!("expected.rs"); + } + + let ser = include_str!("example.xml"); + + let de: expected::FooType = yaserde::de::from_str(ser).unwrap(); + + assert_eq!( + de, + expected::FooType { + id: Some("abcd".to_string()), + a_number: Some(1234), + } + ); +} + +#[test] +fn generator_does_not_panic() { + println!("{}", utils::generate(include_str!("input.xsd"))) +} + +#[test] +fn generator_output_has_correct_ast() { + utils::ast_test(include_str!("input.xsd"), include_str!("expected.rs")); +} diff --git a/xsd-parser/tests/mod.rs b/xsd-parser/tests/mod.rs index 6daeaa9f..cedc5e42 100644 --- a/xsd-parser/tests/mod.rs +++ b/xsd-parser/tests/mod.rs @@ -1,6 +1,7 @@ #[macro_use] mod utils; mod any; +mod attribute_group; mod choice; mod complex_type; mod complex_type_subtypes_clash;