From c5ea2ae07f804bba432e720b1e43175d605d1aaf Mon Sep 17 00:00:00 2001 From: Linus Kirkwood Date: Sat, 20 Apr 2024 16:39:21 +1000 Subject: [PATCH 1/9] Fix xsd::any generator ast test always failing --- xsd-parser/tests/any/expected.rs | 3 +++ xsd-parser/tests/any/mod.rs | 1 + 2 files changed, 4 insertions(+) diff --git a/xsd-parser/tests/any/expected.rs b/xsd-parser/tests/any/expected.rs index f568b7ff..917fe12f 100644 --- a/xsd-parser/tests/any/expected.rs +++ b/xsd-parser/tests/any/expected.rs @@ -4,3 +4,6 @@ pub struct FooType { #[yaserde(prefix = "tns", rename = "Name")] pub name: String, } + +impl Validate for FooType {} +// pub type Foo = FooType; diff --git a/xsd-parser/tests/any/mod.rs b/xsd-parser/tests/any/mod.rs index e151f6e8..7244a1cf 100644 --- a/xsd-parser/tests/any/mod.rs +++ b/xsd-parser/tests/any/mod.rs @@ -3,6 +3,7 @@ use super::utils; #[test] fn deserialization_works() { mod expected { + use xsd_parser::generator::validator::Validate; use yaserde_derive::{YaDeserialize, YaSerialize}; include!("expected.rs"); From f757ee4472f81454b420d25e1db7e5b5e9c2f75a Mon Sep 17 00:00:00 2001 From: Linus Kirkwood Date: Sat, 20 Apr 2024 16:49:29 +1000 Subject: [PATCH 2/9] Fix xsd::choice generator ast test always failing --- xsd-parser/tests/choice/expected.rs | 9 +++++++++ xsd-parser/tests/choice/mod.rs | 1 + 2 files changed, 10 insertions(+) diff --git a/xsd-parser/tests/choice/expected.rs b/xsd-parser/tests/choice/expected.rs index 325a8d7f..52c1f6ae 100644 --- a/xsd-parser/tests/choice/expected.rs +++ b/xsd-parser/tests/choice/expected.rs @@ -1,9 +1,13 @@ #[derive(Default, PartialEq, Debug, UtilsTupleIo, UtilsDefaultSerde)] pub struct BarType(pub String); +impl Validate for BarType {} + #[derive(Default, PartialEq, Debug, UtilsTupleIo, UtilsDefaultSerde)] pub struct BazType(pub i32); +impl Validate for BazType {} + #[derive(PartialEq, Debug, YaSerialize, YaDeserialize)] #[yaserde(prefix = "tns", namespace = "tns: http://example.com")] pub enum FooTypeChoice { @@ -18,9 +22,14 @@ impl Default for FooTypeChoice { } } +impl Validate for FooTypeChoice {} + #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] #[yaserde(prefix = "tns", namespace = "tns: http://example.com")] pub struct FooType { #[yaserde(flatten)] pub foo_type_choice: FooTypeChoice, } + +impl Validate for FooType {} +// pub type Foo = FooType; diff --git a/xsd-parser/tests/choice/mod.rs b/xsd-parser/tests/choice/mod.rs index 9e307a65..89f664b1 100644 --- a/xsd-parser/tests/choice/mod.rs +++ b/xsd-parser/tests/choice/mod.rs @@ -6,6 +6,7 @@ fn deserialization_works() { use std::str::FromStr; use xsd_macro_utils::*; + use xsd_parser::generator::validator::Validate; use yaserde_derive::{YaDeserialize, YaSerialize}; include!("expected.rs"); From c12283666229b09676debcca4028b59b06be40db Mon Sep 17 00:00:00 2001 From: Linus Kirkwood Date: Sat, 20 Apr 2024 19:18:52 +1000 Subject: [PATCH 3/9] Fix simple_type generator ast test always failing --- xsd-parser/tests/simple_type/expected.rs | 5 ++++- xsd-parser/tests/simple_type/mod.rs | 6 +----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/xsd-parser/tests/simple_type/expected.rs b/xsd-parser/tests/simple_type/expected.rs index a67851b5..7b16aa3f 100644 --- a/xsd-parser/tests/simple_type/expected.rs +++ b/xsd-parser/tests/simple_type/expected.rs @@ -1,2 +1,5 @@ #[derive(Default, PartialEq, Debug, UtilsTupleIo, UtilsDefaultSerde)] -pub struct FooType (pub String); +pub struct FooType(pub String); + +impl Validate for FooType {} +// pub type Foo = FooType; diff --git a/xsd-parser/tests/simple_type/mod.rs b/xsd-parser/tests/simple_type/mod.rs index a4843eeb..6dbfe7c0 100644 --- a/xsd-parser/tests/simple_type/mod.rs +++ b/xsd-parser/tests/simple_type/mod.rs @@ -4,12 +4,8 @@ use super::utils; fn deserialization_works() { mod expected { use std::str::FromStr; - use xsd_macro_utils::*; - - trait Validate { - fn validate(&self) -> Result<(), String>; - } + use xsd_parser::generator::validator::Validate; include!("expected.rs"); } From a413980b4887b443176200d579290c1802c6e94e Mon Sep 17 00:00:00 2001 From: Linus Kirkwood Date: Sat, 20 Apr 2024 20:40:35 +1000 Subject: [PATCH 4/9] Fix tuple_with_integer generator ast test --- xsd-parser/tests/tuple_with_integer/expected.rs | 5 ++++- xsd-parser/tests/tuple_with_integer/mod.rs | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/xsd-parser/tests/tuple_with_integer/expected.rs b/xsd-parser/tests/tuple_with_integer/expected.rs index 2e78b1cf..0347b2fa 100644 --- a/xsd-parser/tests/tuple_with_integer/expected.rs +++ b/xsd-parser/tests/tuple_with_integer/expected.rs @@ -1,2 +1,5 @@ #[derive(Default, PartialEq, Debug, UtilsTupleIo, UtilsDefaultSerde)] -pub struct FooType (pub Integer); +pub struct FooType(pub xs::Integer); + +impl Validate for FooType {} +// pub type Foo = FooType; diff --git a/xsd-parser/tests/tuple_with_integer/mod.rs b/xsd-parser/tests/tuple_with_integer/mod.rs index 7a88f83f..561495a9 100644 --- a/xsd-parser/tests/tuple_with_integer/mod.rs +++ b/xsd-parser/tests/tuple_with_integer/mod.rs @@ -7,9 +7,10 @@ use super::utils; fn deserialization_works() { mod expected { use std::str::FromStr; + use xsd_parser::generator::validator::Validate; use xsd_macro_utils::*; - use xsd_types::types::Integer; + use xsd_types::types as xs; include!("expected.rs"); } From b1dba57cca059c80956c4636a1d54b916b915415 Mon Sep 17 00:00:00 2001 From: Linus Kirkwood Date: Sat, 20 Apr 2024 20:56:32 +1000 Subject: [PATCH 5/9] Fix tuple_with_vec generator ast test --- xsd-parser/tests/tuple_with_vec/expected.rs | 3 +++ xsd-parser/tests/tuple_with_vec/input.xsd | 2 +- xsd-parser/tests/tuple_with_vec/mod.rs | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/xsd-parser/tests/tuple_with_vec/expected.rs b/xsd-parser/tests/tuple_with_vec/expected.rs index d7968913..356541fc 100644 --- a/xsd-parser/tests/tuple_with_vec/expected.rs +++ b/xsd-parser/tests/tuple_with_vec/expected.rs @@ -1,2 +1,5 @@ #[derive(Default, PartialEq, Debug, UtilsTupleIo, UtilsDefaultSerde)] pub struct FooType(pub Vec); + +impl Validate for FooType {} +// pub type Foo = FooType; diff --git a/xsd-parser/tests/tuple_with_vec/input.xsd b/xsd-parser/tests/tuple_with_vec/input.xsd index 07f41ff3..2b757d35 100644 --- a/xsd-parser/tests/tuple_with_vec/input.xsd +++ b/xsd-parser/tests/tuple_with_vec/input.xsd @@ -4,7 +4,7 @@ targetNamespace="http://example.com" elementFormDefault="qualified"> - + diff --git a/xsd-parser/tests/tuple_with_vec/mod.rs b/xsd-parser/tests/tuple_with_vec/mod.rs index 86f41c4f..b63d15ef 100644 --- a/xsd-parser/tests/tuple_with_vec/mod.rs +++ b/xsd-parser/tests/tuple_with_vec/mod.rs @@ -4,6 +4,7 @@ use super::utils; fn deserialization_works() { mod expected { use std::str::FromStr; + use xsd_parser::generator::validator::Validate; use xsd_macro_utils::*; From 134fed9f2711ddee8961d8fd3d9ab927bf1497e2 Mon Sep 17 00:00:00 2001 From: Linus Kirkwood Date: Sat, 20 Apr 2024 20:58:55 +1000 Subject: [PATCH 6/9] Moved tuple_with_vec tests to tuple_with_vec_int --- xsd-parser/tests/mod.rs | 2 +- .../tests/{tuple_with_vec => tuple_with_vec_int}/example.xml | 0 .../tests/{tuple_with_vec => tuple_with_vec_int}/expected.rs | 0 .../tests/{tuple_with_vec => tuple_with_vec_int}/input.xsd | 0 xsd-parser/tests/{tuple_with_vec => tuple_with_vec_int}/mod.rs | 0 5 files changed, 1 insertion(+), 1 deletion(-) rename xsd-parser/tests/{tuple_with_vec => tuple_with_vec_int}/example.xml (100%) rename xsd-parser/tests/{tuple_with_vec => tuple_with_vec_int}/expected.rs (100%) rename xsd-parser/tests/{tuple_with_vec => tuple_with_vec_int}/input.xsd (100%) rename xsd-parser/tests/{tuple_with_vec => tuple_with_vec_int}/mod.rs (100%) diff --git a/xsd-parser/tests/mod.rs b/xsd-parser/tests/mod.rs index 0b33f849..e3e37b83 100644 --- a/xsd-parser/tests/mod.rs +++ b/xsd-parser/tests/mod.rs @@ -15,7 +15,7 @@ mod restriction_any_type; mod simple_type; mod tuple_with_integer; mod tuple_with_string; -mod tuple_with_vec; +mod tuple_with_vec_int; mod type_name_clash; mod union; mod xsd_string; diff --git a/xsd-parser/tests/tuple_with_vec/example.xml b/xsd-parser/tests/tuple_with_vec_int/example.xml similarity index 100% rename from xsd-parser/tests/tuple_with_vec/example.xml rename to xsd-parser/tests/tuple_with_vec_int/example.xml diff --git a/xsd-parser/tests/tuple_with_vec/expected.rs b/xsd-parser/tests/tuple_with_vec_int/expected.rs similarity index 100% rename from xsd-parser/tests/tuple_with_vec/expected.rs rename to xsd-parser/tests/tuple_with_vec_int/expected.rs diff --git a/xsd-parser/tests/tuple_with_vec/input.xsd b/xsd-parser/tests/tuple_with_vec_int/input.xsd similarity index 100% rename from xsd-parser/tests/tuple_with_vec/input.xsd rename to xsd-parser/tests/tuple_with_vec_int/input.xsd diff --git a/xsd-parser/tests/tuple_with_vec/mod.rs b/xsd-parser/tests/tuple_with_vec_int/mod.rs similarity index 100% rename from xsd-parser/tests/tuple_with_vec/mod.rs rename to xsd-parser/tests/tuple_with_vec_int/mod.rs From edd3a93d388e7abc87b6520c97416357a1c40968 Mon Sep 17 00:00:00 2001 From: Linus Kirkwood Date: Sat, 20 Apr 2024 21:05:38 +1000 Subject: [PATCH 7/9] Added tuple_with_vec_string --- xsd-parser/tests/mod.rs | 1 + .../tests/tuple_with_vec_string/example.xml | 1 + .../tests/tuple_with_vec_string/expected.rs | 5 +++ .../tests/tuple_with_vec_string/input.xsd | 11 ++++++ xsd-parser/tests/tuple_with_vec_string/mod.rs | 35 +++++++++++++++++++ 5 files changed, 53 insertions(+) create mode 100644 xsd-parser/tests/tuple_with_vec_string/example.xml create mode 100644 xsd-parser/tests/tuple_with_vec_string/expected.rs create mode 100644 xsd-parser/tests/tuple_with_vec_string/input.xsd create mode 100644 xsd-parser/tests/tuple_with_vec_string/mod.rs diff --git a/xsd-parser/tests/mod.rs b/xsd-parser/tests/mod.rs index e3e37b83..ba4a1fa7 100644 --- a/xsd-parser/tests/mod.rs +++ b/xsd-parser/tests/mod.rs @@ -16,6 +16,7 @@ mod simple_type; mod tuple_with_integer; mod tuple_with_string; mod tuple_with_vec_int; +mod tuple_with_vec_string; mod type_name_clash; mod union; mod xsd_string; diff --git a/xsd-parser/tests/tuple_with_vec_string/example.xml b/xsd-parser/tests/tuple_with_vec_string/example.xml new file mode 100644 index 00000000..b907b02e --- /dev/null +++ b/xsd-parser/tests/tuple_with_vec_string/example.xml @@ -0,0 +1 @@ +1 2 3 diff --git a/xsd-parser/tests/tuple_with_vec_string/expected.rs b/xsd-parser/tests/tuple_with_vec_string/expected.rs new file mode 100644 index 00000000..82f0579c --- /dev/null +++ b/xsd-parser/tests/tuple_with_vec_string/expected.rs @@ -0,0 +1,5 @@ +#[derive(Default, PartialEq, Debug, UtilsTupleIo, UtilsDefaultSerde)] +pub struct FooType(pub Vec); + +impl Validate for FooType {} +// pub type Foo = FooType; diff --git a/xsd-parser/tests/tuple_with_vec_string/input.xsd b/xsd-parser/tests/tuple_with_vec_string/input.xsd new file mode 100644 index 00000000..07f41ff3 --- /dev/null +++ b/xsd-parser/tests/tuple_with_vec_string/input.xsd @@ -0,0 +1,11 @@ + + + + + + + + diff --git a/xsd-parser/tests/tuple_with_vec_string/mod.rs b/xsd-parser/tests/tuple_with_vec_string/mod.rs new file mode 100644 index 00000000..5cdf26bc --- /dev/null +++ b/xsd-parser/tests/tuple_with_vec_string/mod.rs @@ -0,0 +1,35 @@ +use super::utils; + +#[test] +fn deserialization_works() { + mod expected { + use std::str::FromStr; + use xsd_parser::generator::validator::Validate; + + use xsd_macro_utils::*; + + include!("expected.rs"); + } + + let ser = include_str!("example.xml"); + + let de: expected::FooType = yaserde::de::from_str(ser).unwrap(); + + assert_eq!(de, expected::FooType(vec!["1".to_string(), "2".to_string(), "3".to_string()])); + + assert_eq!( + r#"1 2 3"#, + yaserde::ser::to_string(&de).unwrap() + ); +} + +#[test] +fn generator_does_not_panic() { + println!("{}", utils::generate(include_str!("input.xsd"))) +} + +#[test] +#[ignore] // Validation is not needed in this case +fn generator_output_has_correct_ast() { + utils::ast_test(include_str!("input.xsd"), include_str!("expected.rs")); +} From aca62ecfc6a3648ebe1a8e689321c71616f5d36e Mon Sep 17 00:00:00 2001 From: Linus Kirkwood Date: Sat, 20 Apr 2024 21:07:07 +1000 Subject: [PATCH 8/9] Remove tuple_with_string for redundancy --- xsd-parser/tests/mod.rs | 1 - .../tests/tuple_with_string/example.xml | 1 - .../tests/tuple_with_string/example_empty.xml | 1 - .../tests/tuple_with_string/expected.rs | 2 - xsd-parser/tests/tuple_with_string/input.xsd | 11 ----- xsd-parser/tests/tuple_with_string/mod.rs | 40 ------------------- 6 files changed, 56 deletions(-) delete mode 100644 xsd-parser/tests/tuple_with_string/example.xml delete mode 100644 xsd-parser/tests/tuple_with_string/example_empty.xml delete mode 100644 xsd-parser/tests/tuple_with_string/expected.rs delete mode 100644 xsd-parser/tests/tuple_with_string/input.xsd delete mode 100644 xsd-parser/tests/tuple_with_string/mod.rs diff --git a/xsd-parser/tests/mod.rs b/xsd-parser/tests/mod.rs index ba4a1fa7..bead4221 100644 --- a/xsd-parser/tests/mod.rs +++ b/xsd-parser/tests/mod.rs @@ -14,7 +14,6 @@ mod rename_only_where_needed; mod restriction_any_type; mod simple_type; mod tuple_with_integer; -mod tuple_with_string; mod tuple_with_vec_int; mod tuple_with_vec_string; mod type_name_clash; diff --git a/xsd-parser/tests/tuple_with_string/example.xml b/xsd-parser/tests/tuple_with_string/example.xml deleted file mode 100644 index d8fb5a0b..00000000 --- a/xsd-parser/tests/tuple_with_string/example.xml +++ /dev/null @@ -1 +0,0 @@ -abc diff --git a/xsd-parser/tests/tuple_with_string/example_empty.xml b/xsd-parser/tests/tuple_with_string/example_empty.xml deleted file mode 100644 index 9a9174d3..00000000 --- a/xsd-parser/tests/tuple_with_string/example_empty.xml +++ /dev/null @@ -1 +0,0 @@ - diff --git a/xsd-parser/tests/tuple_with_string/expected.rs b/xsd-parser/tests/tuple_with_string/expected.rs deleted file mode 100644 index ef82ccf1..00000000 --- a/xsd-parser/tests/tuple_with_string/expected.rs +++ /dev/null @@ -1,2 +0,0 @@ -#[derive(Default, PartialEq, Debug, UtilsTupleIo, UtilsDefaultSerde)] -pub struct FooType(pub String); diff --git a/xsd-parser/tests/tuple_with_string/input.xsd b/xsd-parser/tests/tuple_with_string/input.xsd deleted file mode 100644 index 1bbb4046..00000000 --- a/xsd-parser/tests/tuple_with_string/input.xsd +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - diff --git a/xsd-parser/tests/tuple_with_string/mod.rs b/xsd-parser/tests/tuple_with_string/mod.rs deleted file mode 100644 index ef829ba2..00000000 --- a/xsd-parser/tests/tuple_with_string/mod.rs +++ /dev/null @@ -1,40 +0,0 @@ -use super::utils; - -#[test] -fn deserialization_works() { - mod expected { - use std::str::FromStr; - - use xsd_macro_utils::*; - - include!("expected.rs"); - } - - { - let ser = include_str!("example.xml"); - - let de: expected::FooType = yaserde::de::from_str(ser).unwrap(); - - assert_eq!(de, expected::FooType("abc".to_string())); - } - - { - // Empty element should be deserialized into an empty string - let ser = include_str!("example_empty.xml"); - - let de: expected::FooType = yaserde::de::from_str(ser).unwrap(); - - assert_eq!(de, expected::FooType("".to_string())); - } -} - -#[test] -fn generator_does_not_panic() { - println!("{}", utils::generate(include_str!("input.xsd"))) -} - -#[test] -#[ignore] // Validation is not needed in this case -fn generator_output_has_correct_ast() { - utils::ast_test(include_str!("input.xsd"), include_str!("expected.rs")); -} From c749b2a92c542a11ad9c0e94cb57c898dac17d85 Mon Sep 17 00:00:00 2001 From: Linus Kirkwood Date: Sat, 20 Apr 2024 21:08:00 +1000 Subject: [PATCH 9/9] Unignored fixed tests --- xsd-parser/tests/any/mod.rs | 1 - xsd-parser/tests/choice/mod.rs | 1 - xsd-parser/tests/simple_type/mod.rs | 1 - xsd-parser/tests/tuple_with_integer/mod.rs | 1 - xsd-parser/tests/tuple_with_vec_int/mod.rs | 1 - xsd-parser/tests/tuple_with_vec_string/mod.rs | 1 - 6 files changed, 6 deletions(-) diff --git a/xsd-parser/tests/any/mod.rs b/xsd-parser/tests/any/mod.rs index 7244a1cf..2135641e 100644 --- a/xsd-parser/tests/any/mod.rs +++ b/xsd-parser/tests/any/mod.rs @@ -22,7 +22,6 @@ fn generator_does_not_panic() { } #[test] -#[ignore] fn generator_output_has_correct_ast() { utils::ast_test(include_str!("input.xsd"), include_str!("expected.rs")); } diff --git a/xsd-parser/tests/choice/mod.rs b/xsd-parser/tests/choice/mod.rs index 89f664b1..4ff1888b 100644 --- a/xsd-parser/tests/choice/mod.rs +++ b/xsd-parser/tests/choice/mod.rs @@ -28,7 +28,6 @@ fn generator_does_not_panic() { } #[test] -#[ignore] // Validation is not needed in this case fn generator_output_has_correct_ast() { utils::ast_test(include_str!("input.xsd"), include_str!("expected.rs")); } diff --git a/xsd-parser/tests/simple_type/mod.rs b/xsd-parser/tests/simple_type/mod.rs index 6dbfe7c0..63bef91a 100644 --- a/xsd-parser/tests/simple_type/mod.rs +++ b/xsd-parser/tests/simple_type/mod.rs @@ -23,7 +23,6 @@ fn generator_does_not_panic() { } #[test] -#[ignore] // Validation is not needed in this case fn generator_output_has_correct_ast() { utils::ast_test(include_str!("input.xsd"), include_str!("expected.rs")); } diff --git a/xsd-parser/tests/tuple_with_integer/mod.rs b/xsd-parser/tests/tuple_with_integer/mod.rs index 561495a9..d12f2c8a 100644 --- a/xsd-parser/tests/tuple_with_integer/mod.rs +++ b/xsd-parser/tests/tuple_with_integer/mod.rs @@ -28,7 +28,6 @@ fn generator_does_not_panic() { } #[test] -#[ignore] // Validation is not needed in this case fn generator_output_has_correct_ast() { utils::ast_test(include_str!("input.xsd"), include_str!("expected.rs")); } diff --git a/xsd-parser/tests/tuple_with_vec_int/mod.rs b/xsd-parser/tests/tuple_with_vec_int/mod.rs index b63d15ef..cb335e3e 100644 --- a/xsd-parser/tests/tuple_with_vec_int/mod.rs +++ b/xsd-parser/tests/tuple_with_vec_int/mod.rs @@ -29,7 +29,6 @@ fn generator_does_not_panic() { } #[test] -#[ignore] // Validation is not needed in this case fn generator_output_has_correct_ast() { utils::ast_test(include_str!("input.xsd"), include_str!("expected.rs")); } diff --git a/xsd-parser/tests/tuple_with_vec_string/mod.rs b/xsd-parser/tests/tuple_with_vec_string/mod.rs index 5cdf26bc..512b7f2b 100644 --- a/xsd-parser/tests/tuple_with_vec_string/mod.rs +++ b/xsd-parser/tests/tuple_with_vec_string/mod.rs @@ -29,7 +29,6 @@ fn generator_does_not_panic() { } #[test] -#[ignore] // Validation is not needed in this case fn generator_output_has_correct_ast() { utils::ast_test(include_str!("input.xsd"), include_str!("expected.rs")); }