From e6afd089e25033e880f154a93f7f7608a821b6dc Mon Sep 17 00:00:00 2001 From: lilleman Date: Thu, 27 Aug 2026 23:24:44 +0200 Subject: [PATCH] Test that a load error names the canonical node path --- reference_test.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/reference_test.go b/reference_test.go index 19c700a..10088d7 100644 --- a/reference_test.go +++ b/reference_test.go @@ -142,3 +142,35 @@ func TestNewErrorIsDeterministic(t *testing.T) { } } } + +// TestNewErrorPathIsCanonical pins the node path a load error names: a choice arm +// adds no segment, and a bound {..path} reference is not a containment segment at +// all, so a bad reference is reported against the node that holds it. +func TestNewErrorPathIsCanonical(t *testing.T) { + cases := []struct { + name string + files map[string]string + want string + }{ + { + "cycle inside a choice arm", + map[string]string{"cat": `[{"format":"hi","x":{"format":"{..cat.x}"}}]`}, + "fakes: reference cycle: cat.x -> ..cat.x", + }, + { + "bad reference reached through another reference", + map[string]string{"a": `{"format":"{..b}"}`, "b": `{"format":"{..nope}"}`}, + `fakes: b: reference {..nope}: no entry "nope"`, + }, + } + for _, c := range cases { + _, err := New([]string{writeData(t, c.files)}) + if err == nil { + t.Errorf("%s: New = nil error", c.name) + continue + } + if err.Error() != c.want { + t.Errorf("%s:\n got %s\n want %s", c.name, err, c.want) + } + } +}