about summary refs log tree commit diff
path: root/pkg/lang/vm/vm_test.go
diff options
context:
space:
mode:
authorMel <einebeere@gmail.com>2022-08-16 20:33:41 +0000
committerMel <einebeere@gmail.com>2022-08-16 20:33:41 +0000
commitd84c0f36afcde4e5af2907d70931de75957d5277 (patch)
tree9eb056ca70c6bedf0ee6456baa4c1f7251384463 /pkg/lang/vm/vm_test.go
parent51eb7626b788dc031c53016f203a54a2af762d9e (diff)
downloadjinx-d84c0f36afcde4e5af2907d70931de75957d5277.tar.zst
jinx-d84c0f36afcde4e5af2907d70931de75957d5277.zip
Implement setting values at index in an array
Diffstat (limited to 'pkg/lang/vm/vm_test.go')
-rw-r--r--pkg/lang/vm/vm_test.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/pkg/lang/vm/vm_test.go b/pkg/lang/vm/vm_test.go
index 178d756..8f961ef 100644
--- a/pkg/lang/vm/vm_test.go
+++ b/pkg/lang/vm/vm_test.go
@@ -510,6 +510,33 @@ func TestCoreSay(t *testing.T) {
 	require.Equal(t, "\"Meow!!\"", string(result))
 }
 
+func TestSetAtArray(t *testing.T) {
+	src := `
+	push_array
+
+	get_local 0
+	get_member "push"
+	push_int 1
+	call 1
+	drop 1
+
+	get_local 0
+	get_member "push"
+	push_int 2
+	call 1
+	drop 1
+
+	get_local 0
+	push_int 0
+	push_int 2
+	set_at_index
+
+	get_local 0
+	`
+
+	test(t, src, "[2, 2]")
+}
+
 func test(t *testing.T, src string, expected string) {
 	bc := compile(t, src)
 	vm := vm.New(modules.NewUnknownModule(&bc))