From 16ee379abcb9b5d8e9c31edd5b710aab316b48b6 Mon Sep 17 00:00:00 2001 From: Mihaela Mihaljevic Date: Tue, 9 Jun 2026 09:02:41 +0200 Subject: [PATCH] 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. --- README.md | 2 +- Tests/XSDIdentityTests.swift | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f0ce90f..35ccac4 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/Tests/XSDIdentityTests.swift b/Tests/XSDIdentityTests.swift index c9d4352..9a132f5 100644 --- a/Tests/XSDIdentityTests.swift +++ b/Tests/XSDIdentityTests.swift @@ -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) + + + + + + + + + + + + + + """ + // 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 = "" + 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")) + } }