import Testing @testable import PureXML /// The ur-type `xsd:anyType` processes its element and attribute wildcards as /// `lax`, not `skip` (XSD 1.0 ยง3.4.7). A child or attribute of an untyped element /// that has a global declaration is validated against it; undeclared content is /// admitted. Lax lookup matches a global declaration only by full qualified name, /// so an unqualified instance element is never conflated with a namespaced global /// of the same local name. @Suite("anyType lax wildcard processing") struct SchemaAnyTypeLaxTests { /// No target namespace: the untyped `data` element laxly validates its `item` /// child, whose `anyAttribute` (strict by default) in turn validates the /// duration-typed attribute. "P" is not a valid duration, so it is rejected; /// a well-formed duration passes; an undeclared child is admitted (lax skips). private func noNamespaceSchema() throws -> PureXML.Schema.Document { try PureXML.Schema.Document(""" """) } @Test("a declared child under an untyped element is laxly validated") func test_declaredChildValidated() throws { let schema = try noNamespaceSchema() #expect(try !schema.validate(#""#).isEmpty) #expect(try schema.validate(#""#).isEmpty) } @Test("an undeclared child under an untyped element is admitted") func test_undeclaredChildAdmitted() throws { let schema = try noNamespaceSchema() #expect(try schema.validate(#"anything"#).isEmpty) } /// An unqualified instance element must not match a namespaced global of the /// same local name. Here `testContent` (type `xs:short`) is in the target /// namespace; an unqualified `any text` under an /// untyped element is undeclared in no-namespace, so lax processing skips it /// rather than validating "any text" as `xs:short`. @Test("lax lookup does not conflate an unqualified child with a namespaced global") func test_noNamespaceConflation() throws { let schema = try PureXML.Schema.Document(""" """) // Unqualified `testContent` is undeclared in no-namespace: admitted (lax skip). #expect(try schema.validate(#"any text"#).isEmpty) // The namespaced `testContent` IS declared `xs:short`: a non-short value is rejected. #expect(try !schema.validate(#"any text"#).isEmpty) // A valid short under the namespaced declaration passes. #expect(try schema.validate(#"123"#).isEmpty) } }