PureXML/Tests/RelaxNGCompactParamTests.swift
Mihaela Mihaljevic 83e6e27d12 style(format): adopt --importgrouping testable-bottom from canonical rules-swift
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).
2026-06-18 20:33:07 +02:00

39 lines
1.4 KiB
Swift

import Testing
@testable import PureXML
@Suite("RELAX NG compact datatype parameter blocks")
struct RelaxNGCompactParamTests {
private func valid(_ rnc: String, _ xml: String) throws -> Bool {
try PureXML.Schema.RelaxNG(compact: rnc).validate(xml)
}
@Test("A minLength param block constrains a data value")
func test_minLength() throws {
let rnc = "element code { xsd:string { minLength = \"3\" } }"
#expect(try valid(rnc, "<code>abc</code>"))
#expect(try !valid(rnc, "<code>ab</code>"))
}
@Test("A maxInclusive param block constrains a numeric value")
func test_maxInclusive() throws {
let rnc = "element n { xsd:integer { maxInclusive = \"10\" } }"
#expect(try valid(rnc, "<n>5</n>"))
#expect(try !valid(rnc, "<n>20</n>"))
}
@Test("Multiple params in one block all apply")
func test_multipleParams() throws {
let rnc = "element code { xsd:string { minLength = \"2\" maxLength = \"4\" } }"
#expect(try valid(rnc, "<code>abc</code>"))
#expect(try !valid(rnc, "<code>a</code>"))
#expect(try !valid(rnc, "<code>abcde</code>"))
}
@Test("A datatype with no param block still validates against its base")
func test_noParams() throws {
let rnc = "element n { xsd:integer }"
#expect(try valid(rnc, "<n>42</n>"))
#expect(try !valid(rnc, "<n>x</n>"))
}
}