@testable import PureXML
import Testing
@Suite("XSD wildcards and list builtins")
struct XSDWildcardTests {
private func validate(_ xsd: String, _ xml: String) throws -> [PureXML.Validation.ValidationError] {
try PureXML.Schema.Document(xsd).validate(xml)
}
@Test("xs:any with processContents=skip admits any element without validating it")
func test_anySkip() throws {
let xsd = """
"""
#expect(try validate(xsd, "x").isEmpty)
}
@Test("xs:any with processContents=strict requires a global declaration")
func test_anyStrict() throws {
let xsd = """
"""
// A declared element validates against its declaration through the wildcard.
#expect(try validate(xsd, "1").isEmpty)
#expect(try !validate(xsd, "x").isEmpty)
// An undeclared element is rejected under strict.
#expect(try !validate(xsd, "").isEmpty)
}
@Test("xs:anyAttribute admits undeclared attributes")
func test_anyAttribute() throws {
let xsd = """
"""
#expect(try validate(xsd, "- ").isEmpty)
}
@Test("Undeclared attributes are still rejected without a wildcard")
func test_noWildcardRejects() throws {
let xsd = """
"""
#expect(try !validate(xsd, "
- ").isEmpty)
}
@Test("List built-in datatypes validate each item")
func test_listBuiltins() throws {
let xsd = """
"""
#expect(try validate(xsd, "a b c").isEmpty)
// A space is not a valid NMTOKEN item, but spaces separate items, so this
// tests that an item with an illegal character is rejected.
#expect(try !validate(xsd, "a b@d").isEmpty)
}
}