PureXML/Tests/RelaxNGNameClassTests.swift
Mihaela Mihaljevic 3887b33e4e feat(relaxng): compact name-class subtraction (* - name)
The compact-syntax name class * - nameClass now parses as anyName except
the subtracted class (the model already had anyNameExcept). ns:* - name
would need an nsName-except model case and is left as a refinement.

Part of #79
2026-06-08 16:58:24 +02:00

23 lines
771 B
Swift

@testable import PureXML
import Testing
@Suite("RELAX NG compact name-class subtraction")
struct RelaxNGNameClassTests {
private func valid(_ rnc: String, _ xml: String) throws -> Bool {
try PureXML.Schema.RelaxNG(compact: rnc).validate(xml)
}
@Test("* - name admits any element except the subtracted one")
func test_subtraction() throws {
let rnc = "element root { element * - skip { empty }* }"
#expect(try valid(rnc, "<root><a/><b/></root>"))
#expect(try !valid(rnc, "<root><skip/></root>"))
}
@Test("A plain wildcard still admits everything")
func test_plainWildcard() throws {
let rnc = "element root { element * { empty }* }"
#expect(try valid(rnc, "<root><skip/><a/></root>"))
}
}