@testable import PureXML
import Testing
/// A redefinition of an attribute group restricts the original (src-redefine), so
/// it may neither eliminate a required attribute nor re-introduce a prohibited one
/// as usable. Keeping a required attribute, and re-declaring a prohibited attribute
/// as prohibited, are both valid (W3C attgZ002/attgZ003, schT3).
@Suite("redefined attribute group restriction")
struct SchemaRedefineAttributeGroupTests {
private func redefine(group body: String, base: String) throws -> PureXML.Schema.Document {
let main = ""
+ "\(body)"
+ ""
let baseDoc = ""
+ "\(base)"
return try PureXML.Schema.Document(main, schemaLoader: { _ in baseDoc })
}
@Test("eliminating a required attribute is rejected")
func test_dropRequiredRejected() throws {
#expect(throws: (any Error).self) {
try redefine(
group: "",
base: "",
)
}
}
@Test("re-introducing a prohibited attribute as usable is rejected")
func test_reintroduceProhibitedRejected() throws {
#expect(throws: (any Error).self) {
try redefine(
group: "",
base: "",
)
}
}
@Test("keeping a required attribute and re-prohibiting a prohibited one is valid")
func test_validRedefinitionAccepted() throws {
_ = try redefine(
group: "",
base: "",
)
}
@Test("relaxing a fixed value in the redefinition is rejected")
func test_relaxFixedRejected() throws {
#expect(throws: (any Error).self) {
try redefine(
group: "",
base: "",
)
}
}
@Test("keeping the same fixed value in the redefinition is valid")
func test_keepFixedAccepted() throws {
_ = try redefine(
group: "",
base: "",
)
}
@Test("adding an attribute not in the original is rejected (superset)")
func test_addAttributeRejected() throws {
#expect(throws: (any Error).self) {
try redefine(
group: "",
base: "",
)
}
}
@Test("declaring a prohibited attribute the base lacks is valid (not a superset)")
func test_addProhibitedAccepted() throws {
_ = try redefine(
group: "",
base: "",
)
}
@Test("adding an attribute alongside a self-reference is valid")
func test_addWithSelfReferenceAccepted() throws {
_ = try redefine(
group: "",
base: "",
)
}
@Test("re-declaring an attribute the base inherits via a reference is valid")
func test_redeclareInheritedAccepted() throws {
let main = ""
+ ""
+ ""
+ ""
let baseDoc = ""
+ ""
+ ""
_ = try PureXML.Schema.Document(main, schemaLoader: { _ in baseDoc })
}
}