@testable import PureXML import Testing /// Facet applicability to a simple type's variety (XSD 1.0 Part 2, 4.3): a `list` /// admits only the length-family, `pattern`, `enumeration`, `whiteSpace`; a `union` /// only `pattern`/`enumeration`. A value-bound facet on a list or union is invalid /// (the stF families). An atomic, unresolvable, or external base is left alone. @Suite("Facet applicability to variety") struct SchemaFacetApplicabilityTests { private func compile(_ body: String) throws { _ = try PureXML.Schema.Document(""" \(body) """) } private func rejects(_ body: String) -> Bool { do { try compile(body) return false } catch { return true } } @Test("a value-bound facet on a list-derived type is rejected") func test_listValueBoundFacet() { for facet in ["maxInclusive", "maxExclusive", "minInclusive", "minExclusive", "totalDigits", "fractionDigits"] { #expect(rejects(#""" """#), "expected rejection of \(facet) on a list") } // A built-in list datatype (xs:NMTOKENS) is also a list. #expect(rejects(#""#)) } @Test("length-family, pattern, enumeration, whiteSpace apply to a list") func test_listAllowedFacets() throws { try compile(#""" """#) } @Test("only pattern and enumeration apply to a union") func test_unionFacets() throws { #expect(rejects(#""" """#)) try compile(#""" """#) } @Test("a value-bound facet on an atomic type is left alone") func test_atomicUnaffected() throws { try compile(#""#) } @Test("variety resolution is namespace-aware: a same-named user type does not shadow a built-in") func test_namespaceAwareResolution() throws { // A user `simpleType` named `integer` (a list) must not be mistaken for the // built-in `xs:integer` when it is the restriction base; the value-bound // facet on the atomic built-in is valid. try compile(#""" """#) } }