@testable import PureXML
import Testing
@Suite("XSD all-group in extension (cos-all-limited.1.2 via extension)")
struct SchemaExtensionAllGroupTests {
private let xsd = "xmlns:xs=\"http://www.w3.org/2001/XMLSchema\""
private func compiles(_ body: String) -> Bool {
(try? PureXML.Schema.Document("\(body)")) != nil
}
private func ext(base: String, content: String) -> String {
""
+ "\(content)"
+ ""
}
private let seqBase = ""
+ ""
private let emptyBase = ""
private let allContent = ""
@Test("An all group extending a base with content is rejected")
func test_allExtendingContentRejected() {
#expect(!compiles(seqBase + ext(base: "myType", content: allContent)))
}
@Test("An all group extending an empty base compiles")
func test_allExtendingEmptyAccepted() {
#expect(compiles(emptyBase + ext(base: "emptyType", content: allContent)))
}
@Test("A sequence extension of a content base compiles")
func test_sequenceExtensionAccepted() {
#expect(compiles(seqBase + ext(base: "myType", content: "")))
}
@Test("An all group as the whole content of a complex type compiles")
func test_allAsWholeContentAccepted() {
#expect(compiles("\(allContent)"))
}
/// A base whose content is an explicit but empty model group (``)
/// has effectively empty content, so extending it with an `all` makes the `all`
/// the whole content model, which is valid (W3C Bug 6202).
@Test("An all group extending an explicitly-empty (non-mixed) base compiles")
func test_allExtendingExplicitEmptyAccepted() {
let base = ""
#expect(compiles(base + ext(base: "emptyGroup", content: allContent)))
}
/// A mixed base, even with an empty particle, may not be extended by an `all`
/// (the resolution of W3C Bug 6202 keeps this invalid).
@Test("An all group extending a mixed empty base is rejected")
func test_allExtendingMixedEmptyRejected() {
let base = ""
#expect(!compiles(base + ext(base: "mixedEmpty", content: allContent)))
}
}