Find a format's bound readers in one ordered scan

This commit is contained in:
M
2026-08-30 22:27:56 +02:00
committed by lilleman-tw
parent c1222eaf72
commit 5a69b02ee0
5 changed files with 76 additions and 28 deletions
+12
View File
@@ -214,6 +214,18 @@ func TestASharedNodeIsWalkedOnce(t *testing.T) {
}
}
func TestTheEarlierReaderIsNamed(t *testing.T) {
// A token and a calc operand can name one level. The one the format writes
// first is the one reported, so the error points at the same place a reader
// looking at the format would start.
_, err := New([]string{writeData(t, map[string]string{
"cat": `{"format":"{calc(p * 1)} {p} {p.first}","p":[{"format":"{first}","first":["1","2"]}]}`,
})})
if err == nil || !strings.Contains(err.Error(), `calc operand "p"`) {
t.Fatalf("New = %v, want the calc operand named, being written first", err)
}
}
func TestReferenceToAMatchingStringIsAccepted(t *testing.T) {
// A literal renders one fixed string, so no draw of it can disagree with a
// held one. Two unrelated literals that merely spell the same text must not