import Testing @testable import PureXML @Suite("XSD restriction: content-free and substitution-group order") struct XSDRestrictionContentFreeAndOrderTests { private func compiles(_ source: String) -> Bool { (try? PureXML.Schema.Document(source)) != nil } @Test("A never-occurring (maxOccurs=0) group restricts an emptiable base, but not a required one") func test_contentFreeRestriction() { // particlesW006: a sequence with maxOccurs=0 accepts only the empty sequence, // whatever its members' own occurrences, so it validly restricts a base that // also never occurs (or is otherwise emptiable). let base = "" + "" let restriction = "" + "" + "" + "" #expect(compiles("\(base)\(restriction)")) // But a content-free restriction of a REQUIRED base is invalid: the base // requires content the empty restriction cannot supply. let requiredBase = "" let emptyRestriction = "" + "" + "" #expect(!compiles("\(requiredBase)\(emptyRestriction)")) } @Test("A choice of substitution-group members restricts a reference to the head, in declaration order") func test_substitutionGroupChoiceOrder() { // elemZ027a: a ref to a head expands to choice(head, m1, m2) in declaration // order; a derived choice(m1, m2) maps onto it in order (RecurseLax). let decls = "" + "" let base = "" func derived(_ first: String, _ second: String) -> String { "" + "" + "" } let head = "\(decls)\(base)" #expect(compiles(head + derived("m1", "m2") + "")) } @Test("Reordering a base choice's branches is not a valid restriction (RecurseLax is order-preserving)") func test_choiceReorderRejected() { // particlesT002: choice(c2, c1) is NOT a valid restriction of choice(c1, c2). let base = "" + "" let reordered = "" + "" + "" #expect(!compiles("\(base)\(reordered)")) } } @Suite("XSD restriction: MapAndSum (sequence restricting a choice)") struct XSDRestrictionMapAndSumTests { private func wrap(_ base: String, _ restriction: String) -> String { "" + "\(base)" + "\(restriction)" + "" } private func compiles(_ base: String, _ restriction: String) -> Bool { (try? PureXML.Schema.Document(wrap(base, restriction))) != nil } @Test("A sequence restricts a choice when each member fits a branch and the count-product is in range") func test_mapAndSum() { // particlesV003: derived sequence{2,4}(e1,e2) emits 4..8 elements, within the // base choice{3,9}'s range, each an e1/e2 the choice admits. Valid (MapAndSum). #expect(compiles( "", "", )) // Count-product out of range: derived sequence{2,4}(e1,e2) emits up to 8, the // base choice{3,7} allows at most 7. Invalid. #expect(!compiles( "", "", )) // A multi-member sequence cannot restrict a single-occurrence choice: the base // picks exactly one, the derived requires both (count 2 > max 1). Invalid // (this is the over-acceptance the count-product check closes). #expect(!compiles( "", "", )) // A member that fits no branch is rejected regardless of count. #expect(!compiles( "", "", )) } }