2018-02-24 09:06:48 +00:00
|
|
|
package compiler
|
2018-02-15 15:35:49 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
"text/tabwriter"
|
|
|
|
|
|
|
|
"github.com/CityOfZion/neo-go/pkg/vm"
|
|
|
|
)
|
|
|
|
|
|
|
|
type testCase struct {
|
|
|
|
name string
|
|
|
|
src string
|
2018-04-02 15:04:42 +00:00
|
|
|
result interface{}
|
2018-02-15 15:35:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestAllCases(t *testing.T) {
|
2018-02-24 09:06:48 +00:00
|
|
|
// The Go language
|
2018-04-02 15:04:42 +00:00
|
|
|
//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...)
|
2018-02-24 09:06:48 +00:00
|
|
|
|
2018-04-02 15:04:42 +00:00
|
|
|
//// Blockchain specific
|
|
|
|
//testCases = append(testCases, storageTestCases...)
|
|
|
|
//testCases = append(testCases, runtimeTestCases...)
|
2018-02-15 15:35:49 +00:00
|
|
|
|
2018-04-02 15:04:42 +00:00
|
|
|
//for _, tc := range testCases {
|
|
|
|
// b, err := compiler.Compile(strings.NewReader(tc.src), &compiler.Options{})
|
|
|
|
// if err != nil {
|
|
|
|
// t.Fatal(err)
|
|
|
|
// }
|
2018-02-15 15:35:49 +00:00
|
|
|
|
2018-04-02 15:04:42 +00:00
|
|
|
// expectedResult, err := hex.DecodeString(tc.result)
|
|
|
|
// if err != nil {
|
|
|
|
// t.Fatal(err)
|
|
|
|
// }
|
2018-02-15 15:35:49 +00:00
|
|
|
|
2018-04-02 15:04:42 +00:00
|
|
|
// 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)
|
|
|
|
// }
|
|
|
|
//}
|
2018-02-15 15:35:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func dumpOpCodeSideBySide(have, want []byte) {
|
|
|
|
w := tabwriter.NewWriter(os.Stdout, 0, 0, 4, ' ', 0)
|
|
|
|
fmt.Fprintln(w, "INDEX\tHAVE OPCODE\tDESC\tWANT OPCODE\tDESC\tDIFF")
|
|
|
|
|
2018-02-24 09:06:48 +00:00
|
|
|
var b byte
|
2018-02-15 15:35:49 +00:00
|
|
|
for i := 0; i < len(have); i++ {
|
|
|
|
if len(want) <= i {
|
2018-02-24 09:06:48 +00:00
|
|
|
b = 0x00
|
|
|
|
} else {
|
|
|
|
b = want[i]
|
2018-02-15 15:35:49 +00:00
|
|
|
}
|
|
|
|
diff := ""
|
2018-02-24 09:06:48 +00:00
|
|
|
if have[i] != b {
|
2018-02-15 15:35:49 +00:00
|
|
|
diff = "<<"
|
|
|
|
}
|
|
|
|
fmt.Fprintf(w, "%d\t0x%2x\t%s\t0x%2x\t%s\t%s\n",
|
2018-02-24 09:06:48 +00:00
|
|
|
i, have[i], vm.Opcode(have[i]), b, vm.Opcode(b), diff)
|
2018-02-15 15:35:49 +00:00
|
|
|
}
|
|
|
|
w.Flush()
|
|
|
|
}
|