@testable import PureXML
import Testing
/// Length facets on the built-in list datatypes (`NMTOKENS`, `IDREFS`,
/// `ENTITIES`) count list items, not characters (#146). A restriction of one of
/// these built-ins had collapsed to an atomic string, so `length` measured
/// characters and rejected valid instances across the XSTS NIST list sets.
@Suite("List datatype length facets")
struct SchemaListFacetTests {
private func schema(_ base: String, _ facet: String) throws -> PureXML.Schema.Document {
try PureXML.Schema.Document("""
\(facet)
""")
}
@Test("length on NMTOKENS counts items, not characters")
func test_nmtokensLength() throws {
let doc = try schema("xs:NMTOKENS", #""#)
#expect(try doc.validate("alpha beta gamma").isEmpty) // 3 items: valid
#expect(try !doc.validate("alpha beta").isEmpty) // 2 items: invalid
#expect(try !doc.validate("alpha beta gamma delta").isEmpty) // 4 items: invalid
}
/// ENTITIES would drag in entity declarations and IDREFS in document-scoped
/// reference resolution; NMTOKENS isolates the list length facet itself.
@Test("minLength and maxLength on a built-in list count items")
func test_listMinMax() throws {
let doc = try schema("xs:NMTOKENS", #""#)
#expect(try doc.validate("a b").isEmpty) // 2 items: valid
#expect(try doc.validate("a b c").isEmpty) // 3 items: valid
#expect(try !doc.validate("a").isEmpty) // 1 item: invalid
#expect(try !doc.validate("a b c d").isEmpty) // 4 items: invalid
}
}