@testable import PureXML
import Testing
@Suite("Schematron diagnostics")
struct SchematronDiagnosticTests {
private func validate(_ schema: String, _ xml: String) throws -> [PureXML.Validation.ValidationError] {
try PureXML.Validation.Schematron(schema: schema).validate(xml)
}
@Test("A referenced diagnostic is appended to the failure message")
func test_diagnostic() throws {
let schema = """
age too high
got
"""
let errors = try validate(schema, "120")
#expect(errors.count == 1)
#expect(errors.first?.reason == "age too high got 120")
}
@Test("Multiple diagnostics are appended in order")
func test_multipleDiagnostics() throws {
let schema = """
bad
first
second
"""
#expect(try validate(schema, "").first?.reason == "bad first second")
}
@Test("An assertion with no diagnostics renders only its message")
func test_noDiagnostics() throws {
let schema = """
plain
"""
#expect(try validate(schema, "").first?.reason == "plain")
}
}