import Testing
@testable import PureXML
@Suite("XSD top-level attribute applicability (topLevelAttribute)")
struct SchemaTopLevelAttributeTests {
private let xsd = "xmlns:xs=\"http://www.w3.org/2001/XMLSchema\""
private func compiles(_ body: String) -> Bool {
(try? PureXML.Schema.Document("\(body)")) != nil
}
@Test("A top-level attribute with use is rejected")
func test_topLevelUseRejected() {
#expect(!compiles(""))
#expect(!compiles(""))
#expect(!compiles(""))
}
@Test("A top-level attribute with form is rejected")
func test_topLevelFormRejected() {
#expect(!compiles(""))
}
@Test("A plain top-level attribute declaration compiles")
func test_plainTopLevelAccepted() {
#expect(compiles(""))
#expect(compiles(""))
}
/// `use`, `form`, and a `ref` are legitimate on a LOCAL attribute use inside a
/// complex type; the rule applies only to top-level declarations.
@Test("A local attribute use with use/form compiles")
func test_localUseAccepted() {
#expect(compiles(
""
+ ""
+ "",
))
// A local ref with use is fine.
#expect(compiles(
""
+ ""
+ ""
+ "",
))
}
/// au-props-correct: an attribute's type must be a simple type. A complex type
/// (here one with simple content) is rejected; a built-in or user simple type,
/// an inline simpleType, or no type (anySimpleType) is valid.
@Test("an attribute's type must be a simple type")
func test_attributeTypeMustBeSimple() {
let complexT = ""
#expect(!compiles(complexT + ""))
#expect(!compiles(""))
let simpleT = ""
#expect(compiles(simpleT + ""))
#expect(compiles(""))
#expect(compiles(""))
}
}