@testable import PureXML
import Testing
@Suite("XSD list, union, groups, and references")
struct XSDCompositionTests {
private func validate(_ xsd: String, _ xml: String) throws -> [PureXML.Validation.ValidationError] {
try PureXML.Schema.Document(xsd).validate(xml)
}
@Test("A list simple type validates each whitespace-separated item")
func test_listType() throws {
let xsd = """
"""
#expect(try validate(xsd, "1 2 3").isEmpty)
#expect(try !validate(xsd, "1 x 3").isEmpty)
}
@Test("A restricted list bounds its item count")
func test_listLength() throws {
let xsd = """
"""
#expect(try validate(xsd, "
a b
").isEmpty)
#expect(try !validate(xsd, "a b c
").isEmpty)
}
@Test("A union admits a value valid for any member type")
func test_unionType() throws {
let xsd = """
"""
#expect(try validate(xsd, "10").isEmpty)
#expect(try validate(xsd, "auto").isEmpty)
#expect(try !validate(xsd, "-1").isEmpty)
#expect(try !validate(xsd, "tiny").isEmpty)
}
@Test("An attribute group is expanded into the referencing type")
func test_attributeGroup() throws {
let xsd = """
"""
#expect(try validate(xsd, "").isEmpty)
#expect(try !validate(xsd, "").isEmpty)
#expect(try !validate(xsd, "").isEmpty)
}
@Test("A named model group is expanded at its reference")
func test_groupReference() throws {
let xsd = """
"""
#expect(try validate(xsd, "AB").isEmpty)
#expect(try !validate(xsd, "B").isEmpty)
}
@Test("An element reference resolves to the global declaration's type")
func test_elementReference() throws {
let xsd = """
"""
#expect(try validate(xsd, "12").isEmpty)
#expect(try !validate(xsd, "-1").isEmpty)
#expect(try !validate(xsd, "1").isEmpty)
}
}