import Testing
@testable import PureXML
/// A non-self-referencing model group redefined inside `xs:redefine` must be a valid
/// restriction of the group it redefines (XSD 1.0 cos-group-restrict / src-redefine
/// 6.1.2). Adding content the original cannot produce, or dropping a required member
/// so the language widens, is rejected; a genuine restriction is accepted. The
/// order-preserving Recurse rule applies even to `xs:all`, so reordering an `all` is
/// rejected (W3C schL5), while a base with a `maxOccurs=0` member is left unjudged to
/// avoid the contested pointless-particle case (W3C mgO013).
@Suite("redefined model group restriction")
struct SchemaGroupRedefineRestrictionTests {
private func redefine(group body: String, base: String) throws -> PureXML.Schema.Document {
let main = ""
+ "\(body)"
+ ""
+ ""
let baseDoc = ""
+ "\(base)"
+ ""
return try PureXML.Schema.Document(main, schemaLoader: { _ in baseDoc })
}
@Test("adding required content to an empty base group is rejected")
func test_addRequiredToEmptyRejected() throws {
#expect(throws: (any Error).self) {
try redefine(
group: "",
base: "",
)
}
}
@Test("dropping a required member from an all group is rejected")
func test_dropRequiredFromAllRejected() throws {
#expect(throws: (any Error).self) {
try redefine(
group: "",
base: "",
)
}
}
@Test("reordering an all group is rejected (order-preserving Recurse)")
func test_reorderAllRejected() throws {
#expect(throws: (any Error).self) {
try redefine(
group: "",
base: "",
)
}
}
@Test("dropping an optional member is a valid restriction")
func test_dropOptionalAccepted() throws {
_ = try redefine(
group: "",
base: "",
)
}
@Test("re-enabling a maxOccurs=0 base member is left unjudged and accepted")
func test_pointlessParticleBaseAccepted() throws {
_ = try redefine(
group: "",
base: "",
)
}
@Test("an unchanged group redefinition is a valid restriction")
func test_identityAccepted() throws {
_ = try redefine(
group: "",
base: "",
)
}
}