import Testing
@testable import PureXML
/// Content-model order and cardinality for the derivation contexts whose model
/// the set-membership table cannot express: a `simpleContent` derivation (facets
/// and attributes, never a model group). Complements the complexContent and
/// shorthand-complexType order tests in `SchemaStructureTests` (the ctD family).
@Suite("Schema content order")
struct SchemaContentOrderTests {
private func rejects(_ body: String) -> Bool {
do {
_ = try PureXML.Schema.Document("""
\(body)
""")
return false
} catch {
return true
}
}
private func simpleContent(_ body: String) -> String {
#"\#(body)"#
}
@Test("a simpleContent derivation may not contain a model group")
func test_noModelGroup() {
#expect(rejects(simpleContent(#""#)))
#expect(rejects(simpleContent(#""#)))
}
@Test("a simpleContent extension may not carry facets or a simpleType")
func test_extensionNoFacets() {
#expect(rejects(simpleContent(#""#)))
}
@Test("a simpleContent derivation's attributes and anyAttribute must be ordered")
func test_attributeOrder() {
#expect(rejects(simpleContent(#""#)))
#expect(rejects(simpleContent(#""#)))
}
@Test("well-formed simpleContent derivations compile")
func test_valid() {
#expect(!rejects(simpleContent(#""#)))
// A simpleContent restriction's base must be a complex type (src-ct.2), so it
// restricts a complexType with simple content, not xs:string directly.
#expect(!rejects(#"""
"""#))
}
}