import Testing
@testable import PureXML
@Suite("SimpleType variety constraints")
struct SchemaSimpleTypeVarietyTests {
private func compile(_ body: String) throws {
_ = try PureXML.Schema.Document("""
\(body)
""")
}
private func rejects(_ body: String) -> Bool {
do {
try compile(body)
return false
} catch {
return true
}
}
@Test("itemType cannot be a list or union containing list")
func test_listItemTypeVariety() {
// base atomic type is valid
#expect(throws: Never.self) {
try compile(#"""
"""#)
}
// list of lists is invalid
#expect(rejects(#"""
"""#))
// list of union of lists is invalid
#expect(rejects(#"""
"""#))
// list of anySimpleType is invalid
#expect(rejects(#"""
"""#))
}
@Test("inline simpleType child of list cannot be a list or union containing list")
func test_inlineListVariety() {
// inline atomic is valid
#expect(throws: Never.self) {
try compile(#"""
"""#)
}
// inline list is invalid
#expect(rejects(#"""
"""#))
}
@Test("nested union of atomic types as list itemType is accepted")
func test_nestedUnionAtomicListAccepted() throws {
try compile("""
""")
}
@Test("nested union containing a list as list itemType is rejected")
func test_nestedUnionListRejected() {
#expect(rejects("""
"""))
}
@Test("foreign itemType reference does not conflate with local list of same name")
func test_listItemTypeForeignStandDown() throws {
try compile("""
""")
}
}