@testable import PureXML import Testing @Suite("XSD attribute-use restriction (cos-ct-derived-ok)") struct SchemaAttributeRestrictionTests { 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 derive(base: String, restricted: String) -> String { "\(base)" + "" + "\(restricted)" } @Test("A restriction may not relax a required attribute") func test_requiredRelaxationRejected() { let req = "" // required -> optional (explicit) #expect(!compiles(derive(base: req, restricted: ""))) // required -> optional (default use) #expect(!compiles(derive(base: req, restricted: ""))) // required -> prohibited #expect(!compiles(derive(base: req, restricted: ""))) } @Test("A faithful or tightening attribute restriction compiles") func test_validRestrictionsAccepted() { // required kept required let req = "" #expect(compiles(derive(base: req, restricted: req))) // fixed kept identical let fixed = "" #expect(compiles(derive(base: fixed, restricted: ""))) // optional base may be made prohibited or stay optional let opt = "" #expect(compiles(derive(base: opt, restricted: ""))) // an attribute the restriction does not redeclare is inherited unchanged #expect(compiles(derive(base: req, restricted: ""))) // an optional base attribute that is also fixed may be prohibited (the // prohibited use removes it, so the fixed clause does not apply). #expect(compiles(derive(base: fixed, restricted: ""))) } /// The fixed-value clause is a disclosed under-rejection (it needs value-space, /// not lexical, comparison). A list-typed fixed value that differs only in /// whitespace is the same value and must compile; and, for now, even a genuinely /// changed fixed value is accepted rather than risk a lexical false positive. @Test("Fixed-value differences on a restricted attribute are not (yet) rejected") func test_fixedClauseDeferred() { let listBase = "" + "" let derived = "" + "" // Same list value, different whitespace: valid, must compile. #expect(compiles(listBase + derived)) } }