github.com/nspcc-dev/neo-go@v0.105.2-0.20240517133400-6be757af3eba/pkg/compiler/map_test.go (about) 1 package compiler_test 2 3 import ( 4 "math/big" 5 "testing" 6 ) 7 8 var mapTestCases = []testCase{ 9 { 10 "map composite literal", 11 ` 12 package foo 13 func Main() int { 14 t := map[int]int{ 15 1: 6, 16 2: 9, 17 } 18 19 age := t[2] 20 return age 21 } 22 `, 23 big.NewInt(9), 24 }, 25 { 26 "nested map", 27 ` 28 package foo 29 func Main() int { 30 t := map[int]map[int]int{ 31 1: map[int]int{2: 5, 3: 1}, 32 2: nil, 33 5: map[int]int{3: 4, 7: 2}, 34 } 35 36 x := t[5][3] 37 return x 38 } 39 `, 40 big.NewInt(4), 41 }, 42 { 43 "map with string index", 44 ` 45 package foo 46 func Main() string { 47 t := map[string]string{ 48 "name": "Valera", 49 "age": "33", 50 } 51 52 name := t["name"] 53 return name 54 } 55 `, 56 []byte("Valera"), 57 }, 58 { 59 "delete key", 60 `package foo 61 func Main() int { 62 m := map[int]int{1: 2, 3: 4} 63 delete(m, 1) 64 return len(m) 65 }`, 66 big.NewInt(1), 67 }, 68 { 69 "delete missing key", 70 `package foo 71 func Main() int { 72 m := map[int]int{3: 4} 73 delete(m, 1) 74 return len(m) 75 }`, 76 big.NewInt(1), 77 }, 78 } 79 80 func TestMaps(t *testing.T) { 81 runTestCases(t, mapTestCases) 82 }