Test that readField reports a held arm with no hold as an internal error
This commit is contained in:
+13
-7
@@ -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"})
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user