import Testing @testable import PureXML @Suite("Schematron dynamic messages and phases") struct SchematronDynamicTests { private func validate(_ schema: String, _ xml: String, phase: String? = nil) throws -> [PureXML.Validation.ValidationError] { try PureXML.Validation.Schematron(schema: schema).validate(xml, phase: phase) } @Test("value-of renders the actual value in an assertion message") func test_valueOf() throws { let schema = """ Age must be under 100 """ let errors = try validate(schema, "120") #expect(errors.count == 1) #expect(errors.first?.reason == "Age 120 must be under 100") } @Test("name renders the context element's name") func test_name() throws { let schema = """ Element needs an id """ let errors = try validate(schema, "") #expect(errors.count == 1) #expect(errors.first?.reason == "Element item needs an id") } @Test("A phase activates only its listed patterns") func test_phase() throws { let schema = """ a is bad b is bad """ let xml = "" // The basic phase runs only p1, so only the a-rule fires. let basic = try validate(schema, xml, phase: "basic") #expect(basic.count == 1) #expect(basic.first?.reason == "a is bad") // With no phase, every pattern runs. #expect(try validate(schema, xml).count == 2) // #ALL runs every pattern. #expect(try validate(schema, xml, phase: "#ALL").count == 2) } @Test("defaultPhase scopes patterns when no phase is requested") func test_defaultPhase() throws { let schema = """ a is bad b is bad """ let errors = try validate(schema, "") #expect(errors.count == 1) #expect(errors.first?.reason == "a is bad") } }