From 4a1073f018029627a4b6e717d00e086d32d684a9 Mon Sep 17 00:00:00 2001 From: M Date: Sun, 30 Aug 2026 22:09:54 +0200 Subject: [PATCH] Test that a path reaches every variant it might draw --- bound_test.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/bound_test.go b/bound_test.go index aa14532..4cd2294 100644 --- a/bound_test.go +++ b/bound_test.go @@ -142,6 +142,30 @@ func TestALevelRenderedOnlyByAPathTokenIsHeld(t *testing.T) { } } +func TestAPathReachesEveryVariantItMightDraw(t *testing.T) { + // A path through a choice may land in any variant, so both walks have to see + // all of them. Reaching only the first leaves whatever hides in a later + // variant to be found at render — a cycle there is fatal, and a second route + // to a held level disagrees silently. + rejected := map[string]struct{ file, want string }{ + "a cycle in a later variant": { + `{"format":"{p.x}","p":[{"format":"h","x":"safe"},{"format":"h","x":{"format":"{..cat}"}}]}`, + "reference cycle", + }, + "a second route in a later variant": { + `{"format":"{p.x} {q.y}","p":[{"format":"h","x":"safe"},{"format":"h","x":{"format":"{..cat.q}"}}],` + + `"q":{"format":"{y}","y":["1","2"]}}`, + "reads a path into", + }, + } + for name, c := range rejected { + _, err := New([]string{writeData(t, map[string]string{"cat": c.file})}) + if err == nil || !strings.Contains(err.Error(), c.want) { + t.Errorf("%s: New = %v, want it to mention %q", name, err, c.want) + } + } +} + func TestALevelAPathNeverRendersIsAccepted(t *testing.T) { // A path token does not expand its head's format, so a reference sitting in // that format is not a second route to anything: it is never rendered by the