test(xsd): prove identity-error location at full selector depth

The identity-constraint location walk handles arbitrary selector depth, but
the existing assertions only exercised a single relative step. Add a nested
selector (group/item) whose duplicate sits in the second group, so the
offender is a grandchild and an intermediate level needs a sibling index:
list/group[2]/item. Locks the multi-level path construction.
This commit is contained in:
Mihaela Mihaljevic 2026-06-09 09:02:41 +02:00
parent 36a40eec08
commit 16ee379abc
2 changed files with 27 additions and 1 deletions

View File

@ -88,7 +88,7 @@ flowchart TB
PureXML is a working, dependency-free XML library today: parse, emit, validate,
query, and stream documents on macOS, Linux, Windows, and WASM. The test suite
currently runs **766 tests in 117 suites** (`swift test`).
currently runs **767 tests in 117 suites** (`swift test`).
### Shipped (libxml2-aligned surface)

View File

@ -104,4 +104,30 @@ struct XSDIdentityTests {
#expect(failure.codingPath.map(\.stringValue) == ["list", "item"])
#expect(String(describing: failure).hasSuffix("at path: list/item[2]"))
}
@Test("A nested selector locates the offender at full depth with an intermediate index")
func test_identityErrorDeepPath() throws {
let xsd = """
\(head)
<xs:element name="list">
<xs:complexType>
<xs:sequence>
<xs:element name="group" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence><xs:element name="item" type="xs:string" maxOccurs="unbounded"/></xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:key name="k"><xs:selector xpath="group/item"/><xs:field xpath="@id"/></xs:key>
</xs:element>
</xs:schema>
"""
// The duplicate id "1" appears in the second group, so the offender is
// list/group[2]/item: a grandchild, with the index on the intermediate group.
let xml = "<list><group><item id=\"1\"/></group><group><item id=\"1\"/></group></list>"
let failure = try #require(validate(xsd, xml).first)
#expect(failure.codingPath.map(\.stringValue) == ["list", "group", "item"])
#expect(String(describing: failure).hasSuffix("at path: list/group[2]/item"))
}
}