Group @testable imports at the bottom, per public/rules-swift's swiftformat. A behavior-preserving import-ordering reformat across 252 files (mostly tests). --trailingclosures was deliberately not adopted (cosmetic, and swiftformat flags it as caution-worthy).
59 lines
2.0 KiB
Swift
59 lines
2.0 KiB
Swift
import Testing
|
|
@testable import PureXML
|
|
|
|
@Suite("Schematron schema- and pattern-level let")
|
|
struct SchematronScopedLetTests {
|
|
private func validate(_ schema: String, _ xml: String) throws -> [PureXML.Validation.ValidationError] {
|
|
try PureXML.Validation.Schematron(schema: schema).validate(xml)
|
|
}
|
|
|
|
@Test("A schema-level let is available to every rule")
|
|
func test_schemaLet() throws {
|
|
let schema = """
|
|
<schema xmlns="http://purl.oclc.org/dsdl/schematron">
|
|
<let name="limit" value="10"/>
|
|
<pattern>
|
|
<rule context="n">
|
|
<assert test="number(.) < $limit">over the schema limit</assert>
|
|
</rule>
|
|
</pattern>
|
|
</schema>
|
|
"""
|
|
#expect(try validate(schema, "<n>5</n>").isEmpty)
|
|
#expect(try !validate(schema, "<n>50</n>").isEmpty)
|
|
}
|
|
|
|
@Test("A pattern-level let is available to the pattern's rules")
|
|
func test_patternLet() throws {
|
|
let schema = """
|
|
<schema xmlns="http://purl.oclc.org/dsdl/schematron">
|
|
<pattern>
|
|
<let name="want" value="'yes'"/>
|
|
<rule context="flag">
|
|
<assert test=". = $want">flag must be yes</assert>
|
|
</rule>
|
|
</pattern>
|
|
</schema>
|
|
"""
|
|
#expect(try validate(schema, "<flag>yes</flag>").isEmpty)
|
|
#expect(try !validate(schema, "<flag>no</flag>").isEmpty)
|
|
}
|
|
|
|
@Test("A rule-level let overrides a wider-scope let of the same name")
|
|
func test_ruleOverridesSchema() throws {
|
|
let schema = """
|
|
<schema xmlns="http://purl.oclc.org/dsdl/schematron">
|
|
<let name="limit" value="100"/>
|
|
<pattern>
|
|
<rule context="n">
|
|
<let name="limit" value="10"/>
|
|
<assert test="number(.) < $limit">over the rule limit</assert>
|
|
</rule>
|
|
</pattern>
|
|
</schema>
|
|
"""
|
|
// The rule's limit (10) wins over the schema's (100).
|
|
#expect(try !validate(schema, "<n>50</n>").isEmpty)
|
|
}
|
|
}
|