import Testing @testable import PureXML /// An `xsi:type` value is a QName resolved in the instance's namespace context: /// an unprefixed name uses the in-scope default namespace, and with none it is in /// no namespace, so it does not name a namespaced type of the same local name. /// Mirrors W3C XSTS targetNS00101m (CType): a schema with a `targetNamespace` /// declares a type but no element, and a root with `xsi:type` but no element /// declaration is valid only when the `xsi:type` QName resolves to that type. @Suite("xsi:type QName resolves in the instance namespace context") struct SchemaXSITypeNamespaceTests { private func schema() throws -> PureXML.Schema.Document { try PureXML.Schema.Document(""" """) } @Test("an unprefixed xsi:type with no default namespace does not name a namespaced type") func test_unprefixedNoDefault() throws { // xsi:type="Test" with no default namespace in scope -> no-namespace Test, // which does not exist; the root `test` has no declaration -> invalid. let xml = """ 1 """ #expect(try !schema().validate(xml).isEmpty) } @Test("a prefixed xsi:type resolves through its prefix's namespace") func test_prefixedResolves() throws { let xml = """ 1 """ #expect(try schema().validate(xml).isEmpty) } @Test("an unprefixed xsi:type resolves through the in-scope default namespace") func test_unprefixedDefaultNamespace() throws { // A simpleContent type and a default namespace equal to the target namespace: // unprefixed "T" names {targetNS}T and the text content validates, with no // child-element qualification to confound the resolution under test. let schema = try PureXML.Schema.Document(""" """) let xml = """ hello """ #expect(try schema.validate(xml).isEmpty) } }