neoneo-go/pkg/compiler/slice_test.go
Roman Khimov 094c8474b7 compiler: move tests from vm/tests
These don't belong to VM as they compile some Go code and run it in a VM. One
may call them integration tests, but I prefer to attribute them to
compiler. Moving these tests into pkg/compiler also allows to properly count
the compiler coverage they add:

-ok     github.com/CityOfZion/neo-go/pkg/compiler       (cached)        coverage: 69.7% of statements
+ok     github.com/CityOfZion/neo-go/pkg/compiler       (cached)        coverage: 84.2% of statements

This change also fixes `contant` typo and removes fake packages exposed to the
public by moving foo/bar/foobar into the testdata directory.
2019-12-23 17:05:34 +03:00

53 lines
642 B
Go

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)
}