941bd7e728
* renamed test folders and fixed bug where wrong jump labels would be exectuted for rewrite. * Added support for Osize (len(string)) and factored out the array tests * Added current instruction number to VM prompt if program is loaded. * added support for unary expressions. * updated README of and sorted the help commands * updated readme of the compiler * bumped version -> 0.39.0
48 lines
1 KiB
Go
48 lines
1 KiB
Go
package vm_test
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/CityOfZion/neo-go/pkg/vm"
|
|
"github.com/CityOfZion/neo-go/pkg/vm/compiler"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
type testCase struct {
|
|
name string
|
|
src string
|
|
result interface{}
|
|
}
|
|
|
|
func eval(t *testing.T, src string, result interface{}) {
|
|
vm := vm.New(nil, vm.ModeMute)
|
|
b, err := compiler.Compile(strings.NewReader(src), &compiler.Options{})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
vm.Load(b)
|
|
vm.Run()
|
|
assert.Equal(t, result, vm.PopResult())
|
|
}
|
|
|
|
func TestVMAndCompilerCases(t *testing.T) {
|
|
vm := vm.New(nil, vm.ModeMute)
|
|
|
|
testCases := []testCase{}
|
|
testCases = append(testCases, numericTestCases...)
|
|
testCases = append(testCases, assignTestCases...)
|
|
testCases = append(testCases, binaryExprTestCases...)
|
|
testCases = append(testCases, structTestCases...)
|
|
|
|
for _, tc := range testCases {
|
|
b, err := compiler.Compile(strings.NewReader(tc.src), &compiler.Options{})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
vm.Load(b)
|
|
vm.Run()
|
|
assert.Equal(t, tc.result, vm.PopResult())
|
|
}
|
|
}
|