PureXML/Tests/ModelTests.swift
Mihaela Mihaljevic 363a88070a docs(model): TreeNode ownership and concurrency contracts
Document the weak-parent ownership trap at the public entry points: parseTree
and readTree now state that a tree (or ownerDocument) must be held while using
any node inside it, that TreeNode has no internal synchronization (confine to
one thread or actor), and that the immutable Sendable Node projection is the
way across concurrency boundaries; the TreeNode class doc carries the same
contract. QualifiedName's malformed-colon fallback (':local', 'prefix:', '::'
stay whole and unprefixed), already implemented, is now documented on init
and locked by a test.

Closes #114
2026-06-10 03:46:44 +02:00

40 lines
1.3 KiB
Swift

@testable import PureXML
import Testing
@Suite("Model")
struct ModelTests {
@Test("Qualified name splits a prefixed name")
func test_qualifiedNameSplitsPrefix() {
let name = PureXML.Model.QualifiedName("xs:element")
#expect(name.prefix == "xs")
#expect(name.localName == "element")
#expect(name.description == "xs:element")
}
@Test("Qualified name keeps a bare name whole")
func test_qualifiedNameKeepsBareName() {
let name = PureXML.Model.QualifiedName("element")
#expect(name.prefix == nil)
#expect(name.localName == "element")
}
@Test("A malformed colon placement does not split; the name stays unprefixed")
func test_qualifiedNameMalformedColons() {
for raw in [":local", "prefix:", "::"] {
let name = PureXML.Model.QualifiedName(raw)
#expect(name.prefix == nil, "'\(raw)' must not yield a prefix")
#expect(name.localName == raw, "'\(raw)' is kept whole")
#expect(name.description == raw)
}
}
@Test("Element text concatenates text and CDATA children")
func test_elementTextConcatenates() {
let element = PureXML.Model.Element(
"p",
children: [.text("Hello "), .cdata("<world>")],
)
#expect(element.text == "Hello <world>")
}
}