neoneo-go/pkg/compiler/slice_test.go

54 lines
642 B
Go
Raw Normal View History

package compiler_test
import (
"math/big"
"testing"
)
var sliceTestCases = []testCase{
{
"constant index",
`
package foo
func Main() int {
a := []int{0,0}
a[1] = 42
return a[1]+0
}
`,
big.NewInt(42),
},
{
"variable index",
`
package foo
func Main() int {
a := []int{0,0}
i := 1
a[i] = 42
return a[1]+0
}
`,
big.NewInt(42),
},
{
"complex test",
`
package foo
func Main() int {
a := []int{1,2,3}
x := a[0]
a[x] = a[x] + 4
a[x] = a[x] + a[2]
return a[1]
}
`,
big.NewInt(9),
},
}
func TestSliceOperations(t *testing.T) {
runTestCases(t, sliceTestCases)
}