diff options
Diffstat (limited to 'pkg/lang/compiler/compiler_test.go')
| -rw-r--r-- | pkg/lang/compiler/compiler_test.go | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/pkg/lang/compiler/compiler_test.go b/pkg/lang/compiler/compiler_test.go index e40d98e..2e4e6e7 100644 --- a/pkg/lang/compiler/compiler_test.go +++ b/pkg/lang/compiler/compiler_test.go @@ -629,6 +629,46 @@ func TestGlobals(t *testing.T) { mustCompileTo(t, src, expected) } +func TestLvalueAssign(t *testing.T) { + src := ` + var v = 1 + var obj = null + var arr = [1] + + v = 2 + obj.x = 2 + arr[0] = 2 + ` + + expected := ` + push_int 1 + + push_null + + push_array + get_local 2 + get_member "push" + push_int 1 + call 1 + drop 1 + + push_int 2 + set_local 0 + + get_local 1 + push_int 2 + set_member "x" + + get_local 2 + push_int 0 + push_int 2 + set_at_index + halt + ` + + mustCompileTo(t, src, expected) +} + func mustCompileTo(t *testing.T, src, expected string) { scanner := scanner.New(strings.NewReader(src)) tokens, err := scanner.Scan() |
