import Testing
@testable import PureXML
@Suite("XSD ID-typed declarations have no value constraint")
struct SchemaIDValueConstraintTests {
private func compiles(_ body: String) -> Bool {
(try? PureXML.Schema.Document("\(body)")) != nil
}
@Test("An ID-typed attribute or element with a default or fixed value is rejected")
func test_idWithValueConstraintRejected() {
// Attribute of type xs:ID with a fixed value (a-props-correct.3).
#expect(!compiles(""))
// Element of type xs:ID with a default value (e-props-correct.5).
#expect(!compiles(""))
// A named user type derived from xs:ID is recognized (the check runs after
// named types resolve).
#expect(!compiles(""
+ ""))
}
@Test("An ID-typed declaration without a value constraint, or a value constraint on a non-ID type, compiles")
func test_acceptedCases() {
// ID type, no value constraint.
#expect(compiles(""))
#expect(compiles(""))
// A value constraint on a non-ID type is fine.
#expect(compiles(""))
#expect(compiles(""))
}
@Test("A user type named ID (not xs:ID) with a value constraint is allowed")
func test_userTypeNamedIDNotBuiltin() {
// A user simpleType named ID in the target namespace, derived from string, is
// not the built-in xs:ID: a value constraint on it is legal. Resolving by
// local name alone would wrongly reject it.
let schema = ""
+ ""
+ ""
#expect((try? PureXML.Schema.Document(schema)) != nil)
}
}