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

67
test/opcode_test.go Normal file
View File

@@ -0,0 +1,67 @@
package test
import "testing"
func TestNop(t *testing.T) {
state := assembleAndExecute(t, `
functions:
- - [nop]
`)
expectGlobalMemory(t, state, 0, 0)
}
func TestCal(t *testing.T) {
state := assembleAndExecute(t, `
functions:
- - [cal, +1]
- [add, g0, 1]
- - [mov, g0, 5]
`)
expectGlobalMemory(t, state, 0, 6)
}
func TestRet(t *testing.T) {
state := assembleAndExecute(t, `
functions:
- - [cal, +1]
- [add, g0, 1]
- [ret]
- - [mov, g0, 5]
- [ret]
- [add, g0, 2]
`)
expectGlobalMemory(t, state, 0, 6)
}
func TestMov(t *testing.T) {
state := assembleAndExecute(t, `
functions:
- - [mov, g0, 1]
- [mov, g1, g0]
- [mov, f0, 5]
- [mov, g2, f0]
`)
expectGlobalMemory(t, state, 0, 1)
expectGlobalMemory(t, state, 1, 1)
expectGlobalMemory(t, state, 2, 5)
}
func TestAdd(t *testing.T) {
state := assembleAndExecute(t, `
functions:
- - [add, g0, 5]
- [add, g0, 2]
- [add, g0, g0]
- [add, f0, 3]
- [add, f0, -2]
- [add, g0, f0]
`)
expectGlobalMemory(t, state, 0, 15)
}