about summary refs log tree commit diff
path: root/pkg/lang/vm/vm_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/lang/vm/vm_test.go')
-rw-r--r--pkg/lang/vm/vm_test.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/pkg/lang/vm/vm_test.go b/pkg/lang/vm/vm_test.go
index 7e749a4..ae0b8e6 100644
--- a/pkg/lang/vm/vm_test.go
+++ b/pkg/lang/vm/vm_test.go
@@ -184,6 +184,45 @@ func TestEscapedEnv(t *testing.T) {
 	test(t, src, "[1, 2, 3]")
 }
 
+func TestEnvNotEscaped(t *testing.T) {
+	/*
+		var x = 1
+
+		fn f() {
+		    x = x + 1
+		    return
+		}
+
+		f()
+		var result = x
+	*/
+
+	src := `
+	push_int 1
+
+	push_function @f
+	add_to_env 0
+	get_local 1
+
+	call 0
+	drop 1
+
+	get_local 0
+	halt
+
+	@f:
+	get_env 0
+	push_int 1
+	add
+	set_env 0
+
+	push_null
+	ret
+	`
+
+	test(t, src, "2")
+}
+
 func TestMember(t *testing.T) {
 	src := `
 	push_array