diff options
| author | Mel <einebeere@gmail.com> | 2022-05-20 20:28:17 +0200 |
|---|---|---|
| committer | Mel <einebeere@gmail.com> | 2022-05-20 20:28:17 +0200 |
| commit | 6fe6e6546c4801f850d943c699fccdd5dc6ea723 (patch) | |
| tree | 560aab21c9e76047730773ac4bd694e570ffc06e /pkg/lang/vm/vm_test.go | |
| parent | 20d84ae7ffd8a8e4c9397470e5b0459fec9a86ba (diff) | |
| download | jinx-6fe6e6546c4801f850d943c699fccdd5dc6ea723.tar.zst jinx-6fe6e6546c4801f850d943c699fccdd5dc6ea723.zip | |
Continuous VM stack implementation
Diffstat (limited to 'pkg/lang/vm/vm_test.go')
| -rw-r--r-- | pkg/lang/vm/vm_test.go | 30 |
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 { |
