PureXML/Tests/SchemaElementRefApplicabilityTests.swift
Mihaela Mihaljevic 83e6e27d12 style(format): adopt --importgrouping testable-bottom from canonical rules-swift
Group @testable imports at the bottom, per public/rules-swift's swiftformat. A
behavior-preserving import-ordering reformat across 252 files (mostly tests).
--trailingclosures was deliberately not adopted (cosmetic, and swiftformat flags
it as caution-worthy).
2026-06-18 20:33:07 +02:00

37 lines
1.5 KiB
Swift

import Testing
@testable import PureXML
@Suite("XSD element-ref applicability (src-element.2.2)")
struct SchemaElementRefApplicabilityTests {
private let xsd = "xmlns:xs=\"http://www.w3.org/2001/XMLSchema\""
private func compiles(_ body: String) -> Bool {
(try? PureXML.Schema.Document("<xs:schema \(xsd)>\(body)</xs:schema>")) != nil
}
private func refParticle(_ refAttrs: String, inlineType: String = "") -> String {
"<xs:element name=\"Main\" type=\"xs:string\"/>"
+ "<xs:element name=\"e\"><xs:complexType><xs:sequence>"
+ "<xs:element ref=\"Main\" \(refAttrs)>\(inlineType)</xs:element>"
+ "</xs:sequence></xs:complexType></xs:element>"
}
@Test("An element ref carrying a declaration-only attribute is rejected")
func test_refDeclarationAttributesRejected() {
for attr in ["nillable=\"true\"", "default=\"x\"", "fixed=\"x\"", "form=\"qualified\"", "block=\"#all\""] {
#expect(!compiles(refParticle(attr)), "ref with \(attr) should be rejected")
}
}
@Test("An element ref with an inline type is rejected")
func test_refInlineTypeRejected() {
#expect(!compiles(refParticle("", inlineType: "<xs:complexType><xs:sequence/></xs:complexType>")))
}
@Test("An element ref with only occurrence attributes compiles")
func test_refOccurrenceAccepted() {
#expect(compiles(refParticle("minOccurs=\"0\" maxOccurs=\"3\"")))
#expect(compiles(refParticle("")))
}
}