about summary refs log tree commit diff
path: root/pkg/lang/compiler/compiler_test.go
diff options
context:
space:
mode:
authorMel <einebeere@gmail.com>2022-07-05 23:38:17 +0200
committerMel <einebeere@gmail.com>2022-07-06 14:05:23 +0200
commitbb1f61f938be3cc209dacf97b0395336631319bb (patch)
tree2105ae492ea7e897a8ce28c737f9cc6828e5913a /pkg/lang/compiler/compiler_test.go
parent7f8cf65c6e64d28a76ac52849b707dcbcbdcd923 (diff)
downloadjinx-bb1f61f938be3cc209dacf97b0395336631319bb.tar.zst
jinx-bb1f61f938be3cc209dacf97b0395336631319bb.zip
Compile Array literals
Diffstat (limited to 'pkg/lang/compiler/compiler_test.go')
-rw-r--r--pkg/lang/compiler/compiler_test.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/pkg/lang/compiler/compiler_test.go b/pkg/lang/compiler/compiler_test.go
index 1a759f8..4fd4bac 100644
--- a/pkg/lang/compiler/compiler_test.go
+++ b/pkg/lang/compiler/compiler_test.go
@@ -113,6 +113,32 @@ func TestVars(t *testing.T) {
 	mustCompileTo(t, src, expected)
 }
 
+func TestArrayLit(t *testing.T) {
+	src := `var x = [1, 2, 3]`
+
+	expected := `
+	push_array
+
+	get_local 0
+	get_member "push"
+	push_int 1
+	call 1
+
+	get_local 0
+	get_member "push"
+	push_int 2
+	call 1
+
+	get_local 0
+	get_member "push"
+	push_int 3
+	call 1
+	halt
+	`
+
+	mustCompileTo(t, src, expected)
+}
+
 func TestIf(t *testing.T) {
 	src := `
 	":("