From a9ec8b3632477f97b1948e8268280aa778a6db69 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Tue, 29 Sep 2026 03:42:33 +0200 Subject: [PATCH] Test that readField reports a held arm with no hold as an internal error --- hold_test.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/hold_test.go b/hold_test.go index a2d4830..5121c13 100644 --- a/hold_test.go +++ b/hold_test.go @@ -760,12 +760,18 @@ func TestRepeatedBareTokenOfAHeldNameIsRejected(t *testing.T) { } } -func TestReadFieldPanicsOnAnUnheldPath(t *testing.T) { - tm, ok := compiled(t, `{"format":"{w}","w":{"format":"{x}","x":"1"}}`).(*template) - if !ok { - t.Fatal("not a template") +func TestReadFieldPanicsOnAPathItCannotHold(t *testing.T) { + a := arm{spelling: "w.x", key: "w", tail: []string{"x"}, path: "w.x"} + for name, format := range map[string]string{ + "unheld arm with a path": `{"format":"{w}","w":{"format":"{x}","x":"1"}}`, + "held arm with no hold": `{"format":"{w.x}","w":{"format":"{x}","x":"1"}}`, + } { + tm, ok := compiled(t, format).(*template) + if !ok { + t.Fatal("not a template") + } + mustPanic(t, name, func() { + readField(engine(1).rand, tm, nil, renderScope{set: &holdSet{}}, a) + }) } - mustPanic(t, "unheld arm with a path", func() { - readField(engine(1).rand, tm, nil, renderScope{set: &holdSet{}}, arm{spelling: "w.x", key: "w", tail: []string{"x"}, path: "w.x"}) - }) }