@testable import PureXML import Testing @Suite("XSD include composition (#161)") struct SchemaIncludeTests { @Test("chameleon include: no-namespace library merges into a target-namespace main schema") func test_chameleonIncludeWithTargetNamespace() throws { let library = """ """ let main = """ """ let doc = try PureXML.Schema.Document(main, schemaLoader: { $0 == "lib.xsd" ? library : nil }) #expect(try doc.validate("ABC").isEmpty) #expect(try !doc.validate("abc").isEmpty) } @Test("xs:include with a mismatched targetNamespace is rejected") func test_invalidIncludeDifferentTargetNamespace() { let included = """ """ let main = """ """ #expect(throws: Error.self) { _ = try PureXML.Schema.Document(main, schemaLoader: { $0 == "other.xsd" ? included : nil }) } } @Test("xs:include with matching targetNamespace is accepted") func test_includeMatchingTargetNamespace() throws { let included = """ """ let main = """ """ let doc = try PureXML.Schema.Document(main, schemaLoader: { $0 == "lib.xsd" ? included : nil }) #expect(try doc.validate("ABC").isEmpty) } @Test("chameleon include: attribute refs inside the included schema resolve after merge") func test_chameleonIncludeAttributeGroupRef() throws { let library = """ """ let main = """ """ let doc = try PureXML.Schema.Document(main, schemaLoader: { $0 == "lib.xsd" ? library : nil }) #expect(try doc.validate("").isEmpty) } @Test("undeclared refs inside an included chameleon schema are rejected at compile time") func test_invalidReferenceInsideIncludedSchema() { let library = """ """ let main = """ """ #expect(throws: Error.self) { _ = try PureXML.Schema.Document(main, schemaLoader: { $0 == "lib.xsd" ? library : nil }) } } }