import Testing
@testable import PureXML
/// The QName datatype's dual-context value space (#131): the schema side
/// resolves the literal against the schema's xmlns/ns scope at compile, and
/// the instance side resolves the text against the instance element's
/// in-scope namespaces at validation, in both tree and streaming modes.
@Suite("RELAX NG QName values")
struct RelaxNGQNameTests {
private let schema = """
xyzzy
"""
@Test("Prefixed and default-namespace instance QNames resolve; unbound ones fail")
func test_dualContextResolution() throws {
let compiled = try PureXML.Schema.RelaxNG(schema)
let prefixed = "e2:xyzzy"
#expect(try compiled.validate(prefixed))
let viaDefault = "xyzzy"
#expect(try compiled.validate(viaDefault))
let unbound = "xyzzy"
#expect(try !compiled.validate(unbound))
let wrongNamespace = "xyzzy"
#expect(try !compiled.validate(wrongNamespace))
// Streaming agrees with the tree walk.
#expect(try compiled.validate(streaming: prefixed))
#expect(try !compiled.validate(streaming: unbound))
}
@Test("A schema-side prefixed literal resolves against schema declarations")
func test_schemaSidePrefix() throws {
let prefixedLiteral = """
e3:xyzzy
"""
let compiled = try PureXML.Schema.RelaxNG(prefixedLiteral)
#expect(try compiled.validate("q:xyzzy"))
#expect(try !compiled.validate("xyzzy"))
}
}