PureXML/Tests/SchemaValueConstraintExclusionTests.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

33 lines
1.3 KiB
Swift

import Testing
@testable import PureXML
@Suite("XSD default/fixed value-constraint mutual exclusion (src-element.1 / src-attribute.1)")
struct SchemaValueConstraintExclusionTests {
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
}
@Test("An element with both default and fixed is rejected")
func test_elementBothRejected() {
#expect(!compiles("<xs:element name=\"e\" type=\"xs:string\" default=\"0\" fixed=\"0\"/>"))
}
@Test("An attribute with both default and fixed is rejected")
func test_attributeBothRejected() {
#expect(!compiles(
"<xs:element name=\"e\"><xs:complexType>"
+ "<xs:attribute name=\"a\" type=\"xs:string\" default=\"x\" fixed=\"x\"/>"
+ "</xs:complexType></xs:element>",
))
}
@Test("An element or attribute with only one of default/fixed compiles")
func test_onlyOneAccepted() {
#expect(compiles("<xs:element name=\"e\" type=\"xs:string\" default=\"0\"/>"))
#expect(compiles("<xs:element name=\"e\" type=\"xs:string\" fixed=\"0\"/>"))
#expect(compiles("<xs:element name=\"e\" type=\"xs:string\"/>"))
}
}