vm unit tests

This commit is contained in:
2026-02-05 10:21:16 -06:00
parent f71f6a296b
commit b86cd042fc
35 changed files with 3542 additions and 0 deletions

1
vm_test/arrow_block.txt Normal file
View File

@@ -0,0 +1 @@
var f = x => { return x }; f(1)

1
vm_test/arrow_expr.txt Normal file
View File

@@ -0,0 +1 @@
var f = x => x * 2; f(5)

1
vm_test/arrow_multi.txt Normal file
View File

@@ -0,0 +1 @@
var f = (a, b) => a + b; f(2, 3)

View File

@@ -0,0 +1 @@
var f = function(x) { return function() { return x } }; f(5)()

View File

@@ -0,0 +1,11 @@
var counter = function() {
var n = 0
return function() {
n = n + 1
return n
}
}
var c = counter()
c()
c()
c()

1
vm_test/def_basic.txt Normal file
View File

@@ -0,0 +1 @@
def x = 5; x

1
vm_test/for_basic.txt Normal file
View File

@@ -0,0 +1 @@
var s = 0; for (var i = 0; i < 3; i++) s = s + i; s

2
vm_test/go_basic.txt Normal file
View File

@@ -0,0 +1,2 @@
function a() { go b() }
function b() { 1 }

2
vm_test/go_method.txt Normal file
View File

@@ -0,0 +1,2 @@
var o = {m: function() { 1 }}
function f() { go o.m() }

1
vm_test/if_basic.txt Normal file
View File

@@ -0,0 +1 @@
var x = 0; if (true) x = 1; x

1
vm_test/if_else.txt Normal file
View File

@@ -0,0 +1 @@
if (false) 1 else 2

1
vm_test/op_arith.txt Normal file
View File

@@ -0,0 +1 @@
1 + 2 * 3

1
vm_test/op_bitwise.txt Normal file
View File

@@ -0,0 +1 @@
5 & 3

1
vm_test/op_compare.txt Normal file
View File

@@ -0,0 +1 @@
5 > 3

1
vm_test/op_logical.txt Normal file
View File

@@ -0,0 +1 @@
true && false

1
vm_test/op_ternary.txt Normal file
View File

@@ -0,0 +1 @@
true ? 1 : 2

View File

@@ -0,0 +1 @@
var a = {x: 1}; a["x"]

View File

@@ -0,0 +1 @@
var k = "x"; var a = {x: 1}; a[k]

1
vm_test/record_dot.txt Normal file
View File

@@ -0,0 +1 @@
var a = {x: 1}; a.x

View File

@@ -0,0 +1 @@
var k = {}; var a = {}; a[k] = 1; a[k]

1
vm_test/record_this.txt Normal file
View File

@@ -0,0 +1 @@
var o = {v: 1, f: function() { return this.v }}; o.f()

1
vm_test/regex_flags.txt Normal file
View File

@@ -0,0 +1 @@
/hello/i

View File

@@ -0,0 +1 @@
/hello/

View File

@@ -0,0 +1 @@
{double(x) { return x + x }}

View File

@@ -0,0 +1 @@
var x = 1; var y = 2; {x, y}

1
vm_test/switch_basic.txt Normal file
View File

@@ -0,0 +1 @@
var r; switch(2) { case 1: r = 1; break; case 2: r = 2; break }; r

View File

@@ -0,0 +1 @@
var x = 5; `value: ${x}`

1
vm_test/try_catch.txt Normal file
View File

@@ -0,0 +1 @@
try { 1 } catch(e) { 2 }

1
vm_test/try_throw.txt Normal file
View File

@@ -0,0 +1 @@
try { throw "err" } catch(e) { e }

1
vm_test/var_basic.txt Normal file
View File

@@ -0,0 +1 @@
var x = 5; x

1
vm_test/var_block.txt Normal file
View File

@@ -0,0 +1 @@
var x = 1; { var x = 2 }; x

1
vm_test/var_reassign.txt Normal file
View File

@@ -0,0 +1 @@
var x = 5; x = 10; x

1
vm_test/while_basic.txt Normal file
View File

@@ -0,0 +1 @@
var i = 0; while (i < 3) i = i + 1; i