@testable import PureXML import Testing @Suite("XSD namespace qualification") struct XSDNamespaceTests { private func validate(_ xsd: String, _ xml: String) throws -> [PureXML.Validation.ValidationError] { try PureXML.Schema.Document(xsd).validate(xml) } @Test("A root element in the schema target namespace validates") func test_targetNamespaceRoot() throws { let xsd = """ """ #expect(try validate(xsd, "x").isEmpty) } @Test("A root element not in the target namespace is rejected") func test_targetNamespaceMismatch() throws { let xsd = """ """ // No namespace on the instance. #expect(try !validate(xsd, "x").isEmpty) // Wrong namespace on the instance. #expect(try !validate(xsd, "x").isEmpty) } @Test("elementFormDefault=qualified requires local children in the target namespace") func test_elementFormQualified() throws { let xsd = """ """ // The default namespace qualifies both the root and the local child. #expect(try validate(xsd, "x").isEmpty) // An unqualified child does not match the qualified declaration. let mixed = "x" #expect(try !validate(xsd, mixed).isEmpty) } @Test("elementFormDefault=unqualified keeps local children in no namespace") func test_elementFormUnqualified() throws { let xsd = """ """ // The root is qualified; the local child is unqualified, so it must carry no // namespace (the prefixed root keeps the default namespace off the child). let xml = "x" #expect(try validate(xsd, xml).isEmpty) } @Test("attributeFormDefault=qualified requires a qualified attribute") func test_attributeFormQualified() throws { let xsd = """ """ // A prefixed (qualified) attribute matches the qualified declaration. #expect(try validate(xsd, "").isEmpty) // An unqualified attribute is undeclared under attributeFormDefault=qualified. #expect(try !validate(xsd, "").isEmpty) } @Test("xs:all with maxOccurs>1 on a member is a schema error") func test_allMemberMaxOccurs() throws { let xsd = """ """ #expect(throws: PureXML.Schema.SchemaError.self) { _ = try PureXML.Schema.Document(xsd) } } @Test("xs:all containing a nested model group is a schema error") func test_allNestedGroup() throws { let xsd = """ """ #expect(throws: PureXML.Schema.SchemaError.self) { _ = try PureXML.Schema.Document(xsd) } } @Test("A valid xs:all still compiles and validates order-independently") func test_allValid() throws { let xsd = """ """ #expect(try validate(xsd, "21").isEmpty) } }