pkg/terminal: Fix starlark map iteration for maps > 64 entries (#1699)
* Fix starlark map iteration for maps > 64 entries * Fix TestMapEvaluation
This commit is contained in:
parent
bd6a8e56d5
commit
36d688bf14
@ -1,6 +1,8 @@
|
|||||||
v = eval(None, "m1").Variable
|
v = eval(None, "m1").Variable
|
||||||
n = 0
|
n = 0
|
||||||
|
d = {}
|
||||||
for k in v.Value:
|
for k in v.Value:
|
||||||
|
if not d.get(k):
|
||||||
n = n + 1
|
n = n + 1
|
||||||
print(k)
|
d[k] = True
|
||||||
print(n)
|
print("values=", n, sep="")
|
||||||
|
@ -173,6 +173,31 @@ func main() {
|
|||||||
"tumblers": astruct{},
|
"tumblers": astruct{},
|
||||||
"horticulturists": astruct{},
|
"horticulturists": astruct{},
|
||||||
"thallium": astruct{},
|
"thallium": astruct{},
|
||||||
|
"capital": astruct{},
|
||||||
|
"paramese": astruct{},
|
||||||
|
"vaccinationist": astruct{},
|
||||||
|
"shadrach": astruct{},
|
||||||
|
"unsincereness": astruct{},
|
||||||
|
"undazzled": astruct{},
|
||||||
|
"heautomorphism": astruct{},
|
||||||
|
"undermeasure": astruct{},
|
||||||
|
"intentionally": astruct{},
|
||||||
|
"glycine": astruct{},
|
||||||
|
"basiliscine": astruct{},
|
||||||
|
"preinvolvement": astruct{},
|
||||||
|
"adversaria": astruct{},
|
||||||
|
"capocchia": astruct{},
|
||||||
|
"annunciable": astruct{},
|
||||||
|
"unguidableness": astruct{},
|
||||||
|
"prankster": astruct{},
|
||||||
|
"jagless": astruct{},
|
||||||
|
"hormonal": astruct{},
|
||||||
|
"crenature": astruct{},
|
||||||
|
"unfluttering": astruct{},
|
||||||
|
"councilmanic": astruct{},
|
||||||
|
"Micraster": astruct{},
|
||||||
|
"raphidiferous": astruct{},
|
||||||
|
"groomer": astruct{},
|
||||||
}
|
}
|
||||||
var mnil map[string]astruct = nil
|
var mnil map[string]astruct = nil
|
||||||
m2 := map[int]*astruct{1: &astruct{10, 11}}
|
m2 := map[int]*astruct{1: &astruct{10, 11}}
|
||||||
|
@ -573,7 +573,7 @@ func (it *mapVariableAsStarlarkValueIterator) Next(p *starlark.Value) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if it.cur >= len(it.v.Children) {
|
if it.cur >= len(it.v.Children) {
|
||||||
v2 := it.env.autoLoad(fmt.Sprintf("%s[%d:]", varAddrExpr(it.v), len(it.v.Children)))
|
v2 := it.env.autoLoad(fmt.Sprintf("%s[%d:]", varAddrExpr(it.v), len(it.v.Children)/2))
|
||||||
it.v.Children = append(it.v.Children, v2.Children...)
|
it.v.Children = append(it.v.Children, v2.Children...)
|
||||||
}
|
}
|
||||||
if it.cur >= len(it.v.Children) {
|
if it.cur >= len(it.v.Children) {
|
||||||
|
@ -15,7 +15,7 @@ func TestStarlarkExamples(t *testing.T) {
|
|||||||
t.Run("linked_list", func(t *testing.T) { testStarlarkExampleLinkedList(t, term) })
|
t.Run("linked_list", func(t *testing.T) { testStarlarkExampleLinkedList(t, term) })
|
||||||
t.Run("echo_expr", func(t *testing.T) { testStarlarkEchoExpr(t, term) })
|
t.Run("echo_expr", func(t *testing.T) { testStarlarkEchoExpr(t, term) })
|
||||||
t.Run("find_array", func(t *testing.T) { testStarlarkFindArray(t, term) })
|
t.Run("find_array", func(t *testing.T) { testStarlarkFindArray(t, term) })
|
||||||
t.Run("map_iteartion", func(t *testing.T) { testStarlarkMapIteration(t, term) })
|
t.Run("map_iteration", func(t *testing.T) { testStarlarkMapIteration(t, term) })
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,6 +112,9 @@ func testStarlarkFindArray(t *testing.T, term *FakeTerminal) {
|
|||||||
|
|
||||||
func testStarlarkMapIteration(t *testing.T, term *FakeTerminal) {
|
func testStarlarkMapIteration(t *testing.T, term *FakeTerminal) {
|
||||||
out := term.MustExec("source " + findStarFile("starlark_map_iteration"))
|
out := term.MustExec("source " + findStarFile("starlark_map_iteration"))
|
||||||
|
if !strings.Contains(out, "values=66") {
|
||||||
|
t.Fatalf("testStarlarkMapIteration example failed")
|
||||||
|
}
|
||||||
t.Logf("%s", out)
|
t.Logf("%s", out)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -689,7 +689,7 @@ func TestEvalExpression(t *testing.T) {
|
|||||||
{"len(ch1)", false, "4", "4", "", nil},
|
{"len(ch1)", false, "4", "4", "", nil},
|
||||||
{"cap(chnil)", false, "0", "0", "", nil},
|
{"cap(chnil)", false, "0", "0", "", nil},
|
||||||
{"len(chnil)", false, "0", "0", "", nil},
|
{"len(chnil)", false, "0", "0", "", nil},
|
||||||
{"len(m1)", false, "41", "41", "", nil},
|
{"len(m1)", false, "66", "66", "", nil},
|
||||||
{"len(mnil)", false, "0", "0", "", nil},
|
{"len(mnil)", false, "0", "0", "", nil},
|
||||||
{"imag(cpx1)", false, "2", "2", "", nil},
|
{"imag(cpx1)", false, "2", "2", "", nil},
|
||||||
{"real(cpx1)", false, "1", "1", "", nil},
|
{"real(cpx1)", false, "1", "1", "", nil},
|
||||||
@ -892,24 +892,31 @@ func TestMapEvaluation(t *testing.T) {
|
|||||||
t.Fatalf("Wrong type: %s", m1.Type)
|
t.Fatalf("Wrong type: %s", m1.Type)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(m1.Children)/2 != 41 {
|
if len(m1.Children)/2 != 64 {
|
||||||
t.Fatalf("Wrong number of children: %d", len(m1.Children)/2)
|
t.Fatalf("Wrong number of children: %d", len(m1.Children)/2)
|
||||||
}
|
}
|
||||||
|
|
||||||
found := false
|
m1sliced, err := evalVariable(p, "m1[64:]", pnormalLoadConfig)
|
||||||
for i := range m1.Children {
|
assertNoError(err, t, "EvalVariable(m1[64:])")
|
||||||
if i%2 == 0 && m1.Children[i].Value == "Malone" {
|
if len(m1sliced.Children)/2 != int(m1.Len-64) {
|
||||||
found = true
|
t.Fatalf("Wrong number of children (after slicing): %d", len(m1sliced.Children)/2)
|
||||||
}
|
|
||||||
}
|
|
||||||
if !found {
|
|
||||||
t.Fatalf("Could not find Malone")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m1sliced, err := evalVariable(p, "m1[10:]", pnormalLoadConfig)
|
countMalone := func(m *api.Variable) int {
|
||||||
assertNoError(err, t, "EvalVariable(m1[10:])")
|
found := 0
|
||||||
if len(m1sliced.Children)/2 != int(m1.Len-10) {
|
for i := range m.Children {
|
||||||
t.Fatalf("Wrong number of children (after slicing): %d", len(m1sliced.Children)/2)
|
if i%2 == 0 && m.Children[i].Value == "Malone" {
|
||||||
|
found++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return found
|
||||||
|
}
|
||||||
|
|
||||||
|
found := countMalone(m1)
|
||||||
|
found += countMalone(api.ConvertVar(m1sliced))
|
||||||
|
|
||||||
|
if found != 1 {
|
||||||
|
t.Fatalf("Could not find Malone exactly 1 time: found %d", found)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user