mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-05-03 23:02:27 +00:00
compiler: support map literals
This commit is contained in:
parent
2d2a6463e8
commit
058958729d
2 changed files with 61 additions and 0 deletions
46
pkg/compiler/map_test.go
Normal file
46
pkg/compiler/map_test.go
Normal file
|
@ -0,0 +1,46 @@
|
|||
package compiler_test
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var mapTestCases = []testCase{
|
||||
{
|
||||
"map composite literal",
|
||||
`
|
||||
package foo
|
||||
func Main() int {
|
||||
t := map[int]int{
|
||||
1: 6,
|
||||
2: 9,
|
||||
}
|
||||
|
||||
age := t[2]
|
||||
return age
|
||||
}
|
||||
`,
|
||||
big.NewInt(9),
|
||||
},
|
||||
{
|
||||
"nested map",
|
||||
`
|
||||
package foo
|
||||
func Main() int {
|
||||
t := map[int]map[int]int{
|
||||
1: map[int]int{2: 5, 3: 1},
|
||||
2: nil,
|
||||
5: map[int]int{3: 4, 7: 2},
|
||||
}
|
||||
|
||||
x := t[5][3]
|
||||
return x
|
||||
}
|
||||
`,
|
||||
big.NewInt(4),
|
||||
},
|
||||
}
|
||||
|
||||
func TestMaps(t *testing.T) {
|
||||
runTestCases(t, mapTestCases)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue