@testable import PureXML
import Testing
/// Component-name uniqueness (XSD 1.0 symbol-space constraints): within a schema,
/// global type names (simpleType and complexType share one space), global element
/// names, global attribute names, named model-group names, and named
/// attribute-group names must each be unique, and identity-constraint names must
/// be unique across the document. A duplicate was previously accepted, with the
/// later definition silently overwriting the earlier one.
@Suite("Schema component-name uniqueness")
struct SchemaNameUniquenessTests {
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("distinct global names compile")
func test_valid() throws {
try compile(#"""
"""#)
// A name shared across different symbol spaces (a type and an element) is
// allowed.
try compile(#"""
"""#)
}
@Test("a duplicate global type name is rejected (one symbol space)")
func test_duplicateType() {
#expect(rejects(#""#))
// simpleType and complexType share the type symbol space.
#expect(rejects(#""#))
}
@Test("a duplicate global element or attribute name is rejected")
func test_duplicateElementAttribute() {
#expect(rejects(#""#))
#expect(rejects(#""#))
}
@Test("a keyref refer must name a key or unique")
func test_keyrefRefer() throws {
// refer to a defined key resolves.
try compile(#"""
"""#)
// refer to a name that is not a key/unique is rejected.
#expect(rejects(#"""
"""#))
}
@Test("a duplicate identity-constraint name is rejected")
func test_duplicateIdentityConstraint() {
#expect(rejects(#"""
"""#))
}
}