@testable import PureXML
import Testing
@Suite("Schematron let variables")
struct SchematronLetTests {
private func validate(_ schema: String, _ xml: String) throws -> [PureXML.Validation.ValidationError] {
try PureXML.Validation.Schematron(schema: schema).validate(xml)
}
@Test("A let binding is available to the rule's test")
func test_letInTest() throws {
let schema = """
order total exceeds 100
"""
#expect(try validate(schema, " ").isEmpty)
#expect(try !validate(schema, " ").isEmpty)
}
@Test("A let binding can be rendered in a message")
func test_letInMessage() throws {
let schema = """
Age reaches the limit
"""
let errors = try validate(schema, "120")
#expect(errors.count == 1)
#expect(errors.first?.reason == "Age 120 reaches the limit 100")
}
@Test("A later let can reference an earlier one")
func test_letChaining() throws {
let schema = """
doubled is not ten
"""
#expect(try validate(schema, "").isEmpty)
#expect(try !validate(schema, "").isEmpty)
}
}