about summary refs log tree commit diff
path: root/pkg/lang/vm/vm_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/lang/vm/vm_test.go')
-rw-r--r--pkg/lang/vm/vm_test.go30
1 files changed, 28 insertions, 2 deletions
diff --git a/pkg/lang/vm/vm_test.go b/pkg/lang/vm/vm_test.go
index 3622e0b..f87182f 100644
--- a/pkg/lang/vm/vm_test.go
+++ b/pkg/lang/vm/vm_test.go
@@ -10,6 +10,28 @@ import (
 	"github.com/stretchr/testify/require"
 )
 
+func TestSimpleSub(t *testing.T) {
+	src := `
+	push_int 1
+	push_int 2
+	sub
+	`
+
+	test(t, src, "1")
+}
+
+func TestGetLocal(t *testing.T) {
+	src := `
+	push_int 404
+	push_int 1
+	push_int 2
+	add
+	get_local 1
+	`
+
+	test(t, src, "3")
+}
+
 func TestFibonacci(t *testing.T) {
 	src := `
 	# Array stored in local 0
@@ -65,8 +87,12 @@ func TestFibonacci(t *testing.T) {
 	jt @fib_loop
 	`
 
-	bc := compile(t, src)
+	test(t, src, "[1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]")
+}
 
+
+func test(t *testing.T, src string, expected string) {
+	bc := compile(t, src)
 	vm := vm.New(&bc)
 	err := vm.Run()
 	require.NoError(t, err)
@@ -74,7 +100,7 @@ func TestFibonacci(t *testing.T) {
 	res, err := vm.GetResult()
 	require.NoError(t, err)
 
-	require.Equal(t, "[1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]", res)
+	require.Equal(t, expected, res)
 }
 
 func compile(t *testing.T, src string) code.Code {