Split test utils, add opcode tests

This commit is contained in:
Ian Gulliver
2021-11-18 20:12:35 -10:00
parent 4332632c77
commit b0ee500304
3 changed files with 101 additions and 20 deletions

View File

@@ -2,11 +2,8 @@ package test
import "testing"
import "github.com/firestuff/subcoding/asm"
import "github.com/firestuff/subcoding/vm"
func TestLoop(t *testing.T) {
prog, err := asm.AssembleString(`
state := assembleAndExecute(t, `
functions:
- - [add, f0, 1]
- [call, +1]
@@ -15,21 +12,6 @@ functions:
- - [add, g0, 1]
`)
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)
}
if state.GlobalMemory().MustReadUnsigned(0) != 3 {
t.Fatalf("Expected 3, found %d\n", state.GlobalMemory().MustReadUnsigned(0))
}
expectGlobalMemory(t, state, 0, 3)
}