@testable import PureXML
import Testing
/// Ordering facets on `xs:duration` (#147). Duration is a partial order (a month
/// is 28 to 31 days), compared by adding to four reference dateTimes. The bounds
/// had not been enforced at all; a value incomparable to the bound (such as
/// `P1M` against `P30D`) is outside the range and must be rejected.
@Suite("Duration ordering facets")
struct SchemaDurationFacetTests {
private func schema(_ facet: String) throws -> PureXML.Schema.Document {
try PureXML.Schema.Document("""
\(facet)
""")
}
@Test("minInclusive enforces the lower bound")
func test_minInclusive() throws {
let doc = try schema(#""#)
#expect(try doc.validate("P1Y").isEmpty) // equal
#expect(try doc.validate("P2Y").isEmpty) // greater
#expect(try !doc.validate("P6M").isEmpty) // less
}
@Test("minExclusive rejects the bound itself")
func test_minExclusive() throws {
let doc = try schema(#""#)
#expect(try !doc.validate("P1Y").isEmpty) // equal: rejected
#expect(try doc.validate("P2Y").isEmpty) // greater
}
@Test("maxInclusive enforces the upper bound and rejects incomparable values")
func test_maxInclusivePartialOrder() throws {
let doc = try schema(#""#)
#expect(try doc.validate("P20D").isEmpty) // less
#expect(try !doc.validate("P40D").isEmpty) // greater
// P1M is incomparable to P30D (28..31 days) so it is not <= P30D.
#expect(try !doc.validate("P1M").isEmpty)
}
}