diff --git a/Tests/SchemaRestrictionMixedTests.swift b/Tests/SchemaRestrictionMixedTests.swift new file mode 100644 index 0000000..ce39cbb --- /dev/null +++ b/Tests/SchemaRestrictionMixedTests.swift @@ -0,0 +1,55 @@ +import Testing +@testable import PureXML + +/// XSD 1.0 `cos-ct-restricts`: complexContent restriction mixedness is +/// one-directional. A restriction may keep mixedness or narrow mixed to +/// element-only, but must not add mixed content to an element-only base. This pins +/// the asymmetry the #184 guard schemas (addB064, addB150, ctZ010h, particlesL012) +/// depend on: a bidirectional "derived mixed must equal base mixed" rule would +/// wrongly reject the legal narrowing direction (it regressed four valid schemas +/// when tried). The targets ctZ010d (extension) and ctZ010e (restriction) are +/// already rejected by `extensionMixedAgreementErrors` and `ParticleRestriction` +/// respectively; this guards the restriction half from regressing. +@Suite("XSD restriction mixed-content asymmetry (#184)") +struct SchemaRestrictionMixedTests { + private func document(baseMixed: Bool, derivedMixed: Bool?) -> String { + let baseAttr = baseMixed ? " mixed=\"true\"" : "" + let derivedAttr = derivedMixed.map { " mixed=\"\($0)\"" } ?? "" + return """ + + + + + + + + + + + + + + """ + } + + private func compiles(baseMixed: Bool, derivedMixed: Bool?) -> Bool { + (try? PureXML.Schema.Document(document(baseMixed: baseMixed, derivedMixed: derivedMixed))) != nil + } + + @Test("ctZ010e: a mixed restriction of an element-only base adds mixedness and is rejected") + func test_addingMixedRejected() { + #expect(!compiles(baseMixed: false, derivedMixed: true)) + } + + @Test("ctZ010h: a non-mixed or omitted restriction of a mixed base narrows mixedness and is valid") + func test_narrowingMixedValid() { + #expect(compiles(baseMixed: true, derivedMixed: false)) + #expect(compiles(baseMixed: true, derivedMixed: nil)) + } + + @Test("Keeping the base mixedness in either state is valid") + func test_keepingMixedValid() { + #expect(compiles(baseMixed: true, derivedMixed: true)) + #expect(compiles(baseMixed: false, derivedMixed: false)) + } +}