import Testing @testable import PureXML /// Per-rule isolation tests (Validation rules XSD): the schema-consistency layer /// (`PureXML.Validation.XSDSchema`), unrelated to instance validation. @Suite("Validation rules XSD") struct ValidationRuleXSDTests { // MARK: XSDSchema (unchanged, schema-consistency layer) @Test("XSDSchema.finalRespected rejects a derivation forbidden by final") func test_xsdFinalRespected() throws { let xsd = """ """ let compiled = try PureXML.Schema.XSDParser.parse(xsd) let facts = PureXML.Schema.CompiledSchemaFacts(types: compiled.types, typeDerivation: compiled.typeDerivation, typeFinal: compiled.typeFinal) let fact = PureXML.Schema.SchemaTypeFact(name: "CircleT", derivation: compiled.typeDerivation["CircleT"]) let errors = PureXML.Validation.BuiltinValidation.xsdFinalRespected.apply(to: fact, at: [.element("CircleT")], in: facts) #expect(errors.count == 1) } @Test("XSDSchema.finalRespected accepts a derivation the base permits") func test_xsdFinalRespected_succeeds() throws { let xsd = """ """ let compiled = try PureXML.Schema.XSDParser.parse(xsd) let facts = PureXML.Schema.CompiledSchemaFacts(types: compiled.types, typeDerivation: compiled.typeDerivation, typeFinal: compiled.typeFinal) let fact = PureXML.Schema.SchemaTypeFact(name: "ShapeT", derivation: nil) #expect(PureXML.Validation.BuiltinValidation.xsdFinalRespected.apply(to: fact, at: [.element("ShapeT")], in: facts).isEmpty) } @Test("XSDSchema.restrictionsAreSubsets rejects an unfaithful restriction") func test_xsdRestrictionsAreSubsets() throws { let xsd = """ """ let compiled = try PureXML.Schema.XSDParser.parse(xsd) let facts = PureXML.Schema.CompiledSchemaFacts(types: compiled.types, typeDerivation: compiled.typeDerivation, typeFinal: compiled.typeFinal) let fact = PureXML.Schema.SchemaTypeFact(name: "R", derivation: compiled.typeDerivation["R"]) #expect(!PureXML.Validation.BuiltinValidation.xsdRestrictionsAreSubsets.apply(to: fact, at: [.element("R")], in: facts).isEmpty) } @Test("XSDSchema.restrictionsAreSubsets accepts a faithful restriction") func test_xsdRestrictionsAreSubsets_succeeds() throws { let xsd = """ """ let compiled = try PureXML.Schema.XSDParser.parse(xsd) let facts = PureXML.Schema.CompiledSchemaFacts(types: compiled.types, typeDerivation: compiled.typeDerivation, typeFinal: compiled.typeFinal) let fact = PureXML.Schema.SchemaTypeFact(name: "R", derivation: compiled.typeDerivation["R"]) #expect(PureXML.Validation.BuiltinValidation.xsdRestrictionsAreSubsets.apply(to: fact, at: [.element("R")], in: facts).isEmpty) } }