diff options
Diffstat (limited to 'pkg/lang/compiler/compiler_test.go')
| -rw-r--r-- | pkg/lang/compiler/compiler_test.go | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/pkg/lang/compiler/compiler_test.go b/pkg/lang/compiler/compiler_test.go index 7741ca9..b8a6264 100644 --- a/pkg/lang/compiler/compiler_test.go +++ b/pkg/lang/compiler/compiler_test.go @@ -21,6 +21,7 @@ func TestSimpleAddExpr(t *testing.T) { push_int 1 push_int 2 add + drop 1 halt ` @@ -44,6 +45,7 @@ func TestOperationOrder(t *testing.T) { sub push_int 4 add + drop 1 halt ` @@ -78,6 +80,8 @@ func TestNestedExpr(t *testing.T) { add sub + drop 1 + halt ` @@ -141,15 +145,12 @@ func TestArrayLit(t *testing.T) { func TestIf(t *testing.T) { src := ` - ":(" if 1 <= 5 { "hello " + "world" } ` expected := ` - push_string ":(" - push_int 1 push_int 5 lte @@ -160,6 +161,8 @@ func TestIf(t *testing.T) { push_string "world" add + drop 1 + @end: halt ` @@ -183,16 +186,19 @@ func TestIfElifElse(t *testing.T) { jf @elif push_int 1 + drop 1 jmp @end @elif: push_true jf @else push_int 2 + drop 1 jmp @end @else: push_int 3 + drop 1 @end: halt @@ -215,12 +221,14 @@ func TestIfNoElse(t *testing.T) { jf @elif push_int 1 + drop 1 jmp @end @elif: push_true jf @end push_int 2 + drop 1 @end: halt @@ -248,10 +256,12 @@ func TestNestedIfs(t *testing.T) { jf @else push_int 1 + drop 1 jmp @end @else: push_int 2 + drop 1 @end: halt @@ -279,6 +289,7 @@ func TestForCond(t *testing.T) { jf @inner_end push_int 1 + drop 1 jmp @inner_start @inner_end: @@ -410,9 +421,11 @@ func TestForIn(t *testing.T) { push_string "say" get_local 2 call 1 + drop 1 jmp @check @end: + drop 3 halt ` @@ -456,6 +469,7 @@ func TestFunctionArgs(t *testing.T) { push_int 4 push_int 5 call 2 + drop 1 halt @add: |
