the assign operators, '=' and ':=', can set the value of dict items

This commit is contained in:
2026-05-17 07:15:12 +02:00
parent 3ccbeb3978
commit 1bf8015da1
4 changed files with 114 additions and 21 deletions
+28 -3
View File
@@ -36,11 +36,36 @@ func TestDictParser(t *testing.T) {
/* 13 */ {`D={"a":1, "b":2}; D."a"`, int64(1), nil},
/* 14 */ {`D={"a":1, "b":2}; D.a`, int64(1), nil},
/* 15 */ {`D={1:"a", 2:"b", 3:"c"}; D.(1+2)`, "c", nil},
/* 16 */ {`D={"a":1, "b":2}; D.a`, int64(1), nil},
/* 16 */ {`D={1:"a"}; D.2`, nil, `[1:15] key 2 not found`},
/* 17 */ {`D={1:"a"}; D."2"`, nil, `[1:17] key "2" not found`},
/* 18 */ {`D={"a":1, "b":2}; D.a = 10; D.a`, int64(10), nil},
// /* 19 */ {`D={"a": {"one": 1}}; D.a."one" = 10; D["a"]["one"]`, int64(10), nil},
}
runTestSuiteSpec(t, section, inputs, 16)
// runTestSuite(t, section, inputs)
// runTestSuiteSpec(t, section, inputs, 16)
runTestSuite(t, section, inputs)
}
func _TestPoc(t *testing.T) {
section := "Dict-Assign-Item"
ctx := NewSimpleStore()
ctx.UnsafeSetVar(
"D",
kern.NewDict(map[any]any{
"a": kern.NewDict(map[any]any{
"uno": int64(10),
},
),
}),
) // D={"a": {"uno":1}}
inputs := []inputType{
/* 1 */ {`D.a.uno`, int64(10), nil},
/* 2 */ {`D.a.uno = 111; D.a."uno"`, int64(111), nil},
/* 3 */ {`D["a"]["uno"]`, int64(111), nil},
}
runCtxTestSuiteSpec(t, ctx, section, inputs, 3)
// runCtxTestSuite(t, ctx, section, inputs)
}
func TestDictToStringMultiLine(t *testing.T) {