Test that readField reports a held arm with no hold as an internal error

This commit is contained in:
2026-09-29 03:42:33 +02:00
committed by Lillem4n
parent 5ce0ce147e
commit a9ec8b3632
+13 -7
View File
@@ -760,12 +760,18 @@ func TestRepeatedBareTokenOfAHeldNameIsRejected(t *testing.T) {
} }
} }
func TestReadFieldPanicsOnAnUnheldPath(t *testing.T) { func TestReadFieldPanicsOnAPathItCannotHold(t *testing.T) {
tm, ok := compiled(t, `{"format":"{w}","w":{"format":"{x}","x":"1"}}`).(*template) a := arm{spelling: "w.x", key: "w", tail: []string{"x"}, path: "w.x"}
if !ok { for name, format := range map[string]string{
t.Fatal("not a template") "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"})
})
} }