import Testing
@testable import PureXML
/// Value-space validity of the `final`/`block` derivation-control attributes
/// (XSD 1.0): `#all` or a whitespace list of method tokens, with the admitted
/// tokens depending on the component (element/complexType/simpleType) and on
/// whether it is `final` or `block`. The elemF / st_final families.
@Suite("Derivation control (final/block) value space")
struct SchemaDerivationControlTests {
private func rejects(_ body: String) -> Bool {
do {
_ = try PureXML.Schema.Document("""
\(body)
""")
return false
} catch {
return true
}
}
@Test("element final admits only extension/restriction; block also substitution")
func test_element() {
// substitution is a block token, not a final token.
#expect(rejects(#""#))
#expect(rejects(#""#))
// unknown token and wrong case.
#expect(rejects(#""#))
#expect(rejects(##""##))
#expect(rejects(#""#))
// valid finals and a valid block with substitution.
#expect(!rejects(##""##))
#expect(!rejects(#""#))
#expect(!rejects(#""#))
}
@Test("simpleType final admits list/union/restriction, not extension")
func test_simpleType() {
#expect(rejects(#""#))
#expect(!rejects(#""#))
#expect(!rejects(##""##))
}
@Test("complexType block/final admit only extension/restriction")
func test_complexType() {
#expect(rejects(#""#))
#expect(!rejects(#""#))
}
}