aboutsummaryrefslogtreecommitdiff
path: root/eval_test.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2017-06-04 01:01:31 +0200
committerDimitri Sokolyuk <demon@dim13.org>2017-06-04 01:01:31 +0200
commit6960f8870fd6a65955db7f9f5ee04aa6848d56ac (patch)
tree46bcfb6e4b63df04f29177e23fde789b0c361c3a /eval_test.go
parente5580c6bd2cee66c2bf8e10f6ebc4301e8d0f86b (diff)
Add tests
Diffstat (limited to 'eval_test.go')
-rw-r--r--eval_test.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/eval_test.go b/eval_test.go
new file mode 100644
index 0000000..d60f7ab
--- /dev/null
+++ b/eval_test.go
@@ -0,0 +1,35 @@
+package j1
+
+import (
+ "fmt"
+ "testing"
+)
+
+func TestEval(t *testing.T) {
+ testCases := []struct {
+ before J1
+ after J1
+ ins Instruction
+ }{
+ {ins: ALU{}, before: J1{}, after: J1{pc: 1}},
+ {ins: Jump(0xff), before: J1{}, after: J1{pc: 0xff}},
+ {ins: Cond(0xff), before: J1{st0: 1, dsp: 1}, after: J1{pc: 1}},
+ {ins: Cond(0xff), before: J1{st0: 0, dsp: 1}, after: J1{pc: 0xff}},
+ {ins: Call(0xff), before: J1{}, after: J1{pc: 0xff, rstack: [32]uint16{1}, rsp: 1}},
+ {ins: Lit(0xff), before: J1{}, after: J1{pc: 1, st0: 0xff, dstack: [32]uint16{0xff}, dsp: 1}},
+ {ins: Lit(0xfe),
+ before: J1{pc: 1, st0: 0xff, dstack: [32]uint16{0xff}, dsp: 1},
+ after: J1{pc: 2, st0: 0xfe, dstack: [32]uint16{0xff, 0xfe}, dsp: 2}},
+ // to be continued
+ }
+
+ for _, tc := range testCases {
+ t.Run(fmt.Sprint(tc.ins), func(t *testing.T) {
+ state := &tc.before
+ state.eval(tc.ins)
+ if *state != tc.after {
+ t.Errorf("got %v, want %v", state, &tc.after)
+ }
+ })
+ }
+}