import Testing
@testable import PureXML
/// Schema-correctness validation (#131): a RELAX NG schema document must
/// itself match the RELAX NG grammar (section 3) and the restrictions of
/// 4.16-4.19 and 7.1-7.4 before any pattern interpretation.
@Suite("RELAX NG schema correctness")
struct RelaxNGSchemaCorrectnessTests {
private func rejects(_ rng: String) -> Bool {
(try? PureXML.Schema.RelaxNG(rng)) == nil
}
private let rngNS = "xmlns=\"http://relaxng.org/ns/structure/1.0\""
@Test("Junk, misplaced elements, and illegal attributes are schema errors")
func test_grammarLevel() {
#expect(rejects(""))
#expect(rejects(""))
#expect(rejects(""))
#expect(rejects(""))
#expect(rejects(""))
#expect(!rejects(""))
}
@Test("4.16: except restrictions and the xmlns prohibition")
func test_section416() {
#expect(rejects(""))
#expect(rejects(""))
#expect(rejects(""))
}
@Test("4.17/4.19: combine conflicts and unguarded recursion")
func test_grammarSemantics() {
let conflict = """
"""
#expect(rejects(conflict))
let recursion = """
"""
#expect(rejects(recursion))
#expect(rejects(""))
}
@Test("7.1-7.4: prohibited paths, content types, attributes, interleave")
func test_section7() {
#expect(rejects(""))
#expect(rejects(""))
#expect(rejects(""))
#expect(rejects(""))
#expect(rejects(""))
#expect(rejects(""))
// The same shapes inside a notAllowed branch are normalized away (4.20).
let normalized = """
"""
#expect(!rejects(normalized))
}
@Test("Datatype and URI checks")
func test_datatypes() {
#expect(rejects(""))
#expect(rejects(""))
#expect(rejects(""))
}
}