Split test utils, add opcode tests
This commit is contained in:
32
test/util.go
Normal file
32
test/util.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package test
|
||||
|
||||
import "testing"
|
||||
|
||||
import "github.com/firestuff/subcoding/asm"
|
||||
import "github.com/firestuff/subcoding/vm"
|
||||
|
||||
func assembleAndExecute(t *testing.T, src string) *vm.State {
|
||||
prog, err := asm.AssembleString(src)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
state, err := vm.NewState(prog)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = state.Execute()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
return state
|
||||
}
|
||||
|
||||
func expectGlobalMemory(t *testing.T, state *vm.State, i uint64, expected uint64) {
|
||||
actual := state.GlobalMemory().MustReadUnsigned(i)
|
||||
if actual != expected {
|
||||
t.Fatalf("Global memory index %d: expected=%d actual=%d\n", i, expected, actual)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user