Index resolution coverage and document reads

This commit is contained in:
2026-10-09 03:32:30 +00:00
parent db2d8ed217
commit aa3b4a5881
5 changed files with 186 additions and 19 deletions

View File

@@ -31,6 +31,10 @@ func indexDocument(node *document.Node, path Path, index map[string]*document.No
}
func documentAtPath(root *document.Node, path Path) (*document.Node, bool) {
return documentAtPathWithLookup(root, path, nil)
}
func documentAtPathWithLookup(root *document.Node, path Path, lookup *documentLookup) (*document.Node, bool) {
if root == nil || !path.valid() {
return nil, false
}
@@ -41,17 +45,21 @@ func documentAtPath(root *document.Node, path Path) (*document.Node, bool) {
if segment.kind == pathSegmentIndex {
return nil, false
}
found := false
for _, entry := range current.Mapping {
if entry.Key == segment.key {
current = entry.Value
found = true
break
entryIndex := -1
if lookup != nil {
entryIndex = lookup.find(current, segment.key)
} else {
for index, entry := range current.Mapping {
if entry.Key == segment.key {
entryIndex = index
break
}
}
}
if !found {
if entryIndex < 0 || entryIndex >= len(current.Mapping) {
return nil, false
}
current = current.Mapping[entryIndex].Value
case document.Sequence:
index, ok := schemaIndex(segment)
if !ok || index >= len(current.Sequence) {