@testable import PureXML
import Testing
@Suite("XSD whiteSpace facet valid restriction (Part 2 ยง4.3.6)")
struct SchemaWhiteSpaceRestrictionTests {
private let xsd = "xmlns:xs=\"http://www.w3.org/2001/XMLSchema\""
private func compiles(_ body: String) -> Bool {
(try? PureXML.Schema.Document("\(body)")) != nil
}
private func chain(_ baseWS: String, _ derivedWS: String) -> String {
""
+ ""
+ ""
+ ""
}
@Test("Relaxing the base whiteSpace is rejected")
func test_relaxRejected() {
#expect(!compiles(chain("collapse", "replace")))
#expect(!compiles(chain("collapse", "preserve")))
#expect(!compiles(chain("replace", "preserve")))
}
@Test("Keeping or strengthening the base whiteSpace compiles")
func test_strengthenAccepted() {
#expect(compiles(chain("collapse", "collapse")))
#expect(compiles(chain("replace", "collapse")))
#expect(compiles(chain("preserve", "collapse")))
#expect(compiles(chain("preserve", "replace")))
}
@Test("Relaxing a built-in's intrinsic whiteSpace is rejected")
func test_builtinIntrinsicRespected() {
// xs:token has intrinsic whiteSpace=collapse; a restriction may not relax it.
#expect(!compiles(
""
+ "",
))
// Restating collapse on a token is fine.
#expect(compiles(
""
+ "",
))
// Strengthening xs:string (preserve) to collapse is fine.
#expect(compiles(
""
+ "",
))
}
}