From 6ade4190308463bff7ac77ee239a4ea804a41475 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Sch=C3=A4fer?= Date: Mon, 24 Jun 2024 14:43:15 +0200 Subject: [PATCH] xso-proc: improve combinatorial test coverage for attribute fields This is to avoid another regression slip through the test suite, as had happened in d4d520e (fixed in this commit's parent). --- parsers/src/util/macro_tests.rs | 34 ++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/parsers/src/util/macro_tests.rs b/parsers/src/util/macro_tests.rs index 8f6904408c833a155a3699af356eac257aa10ed4..aed19c834886097e0ff920e456074d18d9e60bd9 100644 --- a/parsers/src/util/macro_tests.rs +++ b/parsers/src/util/macro_tests.rs @@ -65,8 +65,16 @@ type Option = ((),); type Result = ((),); static NS1: &str = "urn:example:ns1"; +static NS2: &str = "urn:example:ns2"; -static SOME_NAME: &::xso::exports::rxml::strings::NcNameStr = { +static FOO_NAME: &::xso::exports::rxml::strings::NcNameStr = { + #[allow(unsafe_code)] + unsafe { + ::xso::exports::rxml::strings::NcNameStr::from_str_unchecked("foo") + } +}; + +static BAR_NAME: &::xso::exports::rxml::strings::NcNameStr = { #[allow(unsafe_code)] unsafe { ::xso::exports::rxml::strings::NcNameStr::from_str_unchecked("bar") @@ -157,7 +165,7 @@ fn empty_qname_check_has_precedence_over_attr_check() { } #[derive(FromXml, IntoXml, PartialEq, Debug, Clone)] -#[xml(namespace = NS1, name = SOME_NAME)] +#[xml(namespace = NS1, name = BAR_NAME)] struct NamePath; #[test] @@ -234,7 +242,7 @@ fn required_attribute_missing() { struct RenamedAttribute { #[xml(attribute = "a1")] foo: String, - #[xml(attribute = SOME_NAME)] + #[xml(attribute = BAR_NAME)] bar: String, } @@ -251,10 +259,14 @@ fn renamed_attribute_roundtrip() { #[derive(FromXml, IntoXml, PartialEq, Debug, Clone)] #[xml(namespace = NS1, name = "attr")] struct NamespacedAttribute { - #[xml(attribute(namespace = "urn:example:ns1", name = "foo"))] - foo: String, - #[xml(attribute(namespace = "urn:example:ns2", name = "foo"))] - bar: String, + #[xml(attribute(namespace = "urn:example:ns1", name = FOO_NAME))] + foo_1: String, + #[xml(attribute(namespace = NS2, name = "foo"))] + foo_2: String, + #[xml(attribute(namespace = NS1, name = BAR_NAME))] + bar_1: String, + #[xml(attribute(namespace = "urn:example:ns2", name = "bar"))] + bar_2: String, } #[test] @@ -266,8 +278,8 @@ fn namespaced_attribute_roundtrip_a() { }; roundtrip_full::( "", + xmlns:tns0='urn:example:ns1' tns0:foo='a1' tns0:bar='a3' + xmlns:tns1='urn:example:ns2' tns1:foo='a2' tns1:bar='a4'/>", ); } @@ -280,8 +292,8 @@ fn namespaced_attribute_roundtrip_b() { }; roundtrip_full::( "", + xmlns:tns0='urn:example:ns1' tns0:foo='a1' tns0:bar='a3' + xmlns:tns1='urn:example:ns2' tns1:foo='a2' tns1:bar='a4'/>", ); }