VM improvements, tests + bugfixes (#61)
* changed vm commands to match more of the standard * fixed Uint16 jmp bug in VM * moved test to vm + fixed numnotequal bug * fixed broken tests * moved compiler tests to vm tests * added basic for support + inc and dec stmts * bumped version
This commit is contained in:
parent
931388b687
commit
69c3e645b6
20 changed files with 521 additions and 159 deletions
|
@ -1,63 +1,57 @@
|
|||
package compiler
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
"text/tabwriter"
|
||||
|
||||
"github.com/CityOfZion/neo-go/pkg/vm"
|
||||
"github.com/CityOfZion/neo-go/pkg/vm/compiler"
|
||||
)
|
||||
|
||||
type testCase struct {
|
||||
name string
|
||||
src string
|
||||
result string
|
||||
result interface{}
|
||||
}
|
||||
|
||||
func TestAllCases(t *testing.T) {
|
||||
testCases := []testCase{}
|
||||
|
||||
// The Go language
|
||||
testCases = append(testCases, builtinTestCases...)
|
||||
testCases = append(testCases, assignTestCases...)
|
||||
testCases = append(testCases, arrayTestCases...)
|
||||
testCases = append(testCases, binaryExprTestCases...)
|
||||
testCases = append(testCases, functionCallTestCases...)
|
||||
testCases = append(testCases, boolTestCases...)
|
||||
testCases = append(testCases, stringTestCases...)
|
||||
testCases = append(testCases, structTestCases...)
|
||||
testCases = append(testCases, ifStatementTestCases...)
|
||||
testCases = append(testCases, customTypeTestCases...)
|
||||
testCases = append(testCases, constantTestCases...)
|
||||
testCases = append(testCases, importTestCases...)
|
||||
//testCases = append(testCases, builtinTestCases...)
|
||||
//testCases = append(testCases, arrayTestCases...)
|
||||
//testCases = append(testCases, binaryExprTestCases...)
|
||||
//testCases = append(testCases, functionCallTestCases...)
|
||||
//testCases = append(testCases, boolTestCases...)
|
||||
//testCases = append(testCases, stringTestCases...)
|
||||
//testCases = append(testCases, structTestCases...)
|
||||
//testCases = append(testCases, ifStatementTestCases...)
|
||||
//testCases = append(testCases, customTypeTestCases...)
|
||||
//testCases = append(testCases, constantTestCases...)
|
||||
//testCases = append(testCases, importTestCases...)
|
||||
//testCases = append(testCases, forTestCases...)
|
||||
|
||||
// Blockchain specific
|
||||
testCases = append(testCases, storageTestCases...)
|
||||
testCases = append(testCases, runtimeTestCases...)
|
||||
//// Blockchain specific
|
||||
//testCases = append(testCases, storageTestCases...)
|
||||
//testCases = append(testCases, runtimeTestCases...)
|
||||
|
||||
for _, tc := range testCases {
|
||||
b, err := compiler.Compile(strings.NewReader(tc.src), &compiler.Options{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
//for _, tc := range testCases {
|
||||
// b, err := compiler.Compile(strings.NewReader(tc.src), &compiler.Options{})
|
||||
// if err != nil {
|
||||
// t.Fatal(err)
|
||||
// }
|
||||
|
||||
expectedResult, err := hex.DecodeString(tc.result)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// expectedResult, err := hex.DecodeString(tc.result)
|
||||
// if err != nil {
|
||||
// t.Fatal(err)
|
||||
// }
|
||||
|
||||
if bytes.Compare(b, expectedResult) != 0 {
|
||||
fmt.Println(tc.src)
|
||||
t.Log(hex.EncodeToString(b))
|
||||
dumpOpCodeSideBySide(b, expectedResult)
|
||||
t.Fatalf("compiling %s failed", tc.name)
|
||||
}
|
||||
}
|
||||
// if bytes.Compare(b, expectedResult) != 0 {
|
||||
// fmt.Println(tc.src)
|
||||
// t.Log(hex.EncodeToString(b))
|
||||
// dumpOpCodeSideBySide(b, expectedResult)
|
||||
// t.Fatalf("compiling %s failed", tc.name)
|
||||
// }
|
||||
//}
|
||||
}
|
||||
|
||||
func dumpOpCodeSideBySide(have, want []byte) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue