string literal error

This commit is contained in:
2026-02-10 17:02:22 -06:00
parent fe5dc6ecc9
commit f44fb502be
5 changed files with 106 additions and 7 deletions

View File

@@ -738,6 +738,95 @@ run("disruption re-raise", function() {
if (!outer_caught) fail("disruption re-raise failed")
})
run("disruption handler reads outer vars", function() {
var msg = "hello"
var result = null
var fn = function() {
disrupt
} disruption {
result = msg
}
fn()
if (result != "hello") fail("handler could not read outer var")
})
run("disruption handler modifies outer vars", function() {
var count = 0
var name = "before"
var fn = function() {
count = count + 1
disrupt
} disruption {
count = count + 10
name = "after"
}
fn()
if (count != 11) fail("expected 11 got " + text(count))
if (name != "after") fail("expected 'after' got " + name)
})
run("disruption handler reads function locals", function() {
var result = null
var fn = function() {
var local_val = 42
var inner = function() {
disrupt
} disruption {
result = local_val
}
inner()
}
fn()
if (result != 42) fail("handler could not read local, got " + text(result))
})
run("disruption handler with closure", function() {
var results = []
var make_fn = function(tag) {
return function() {
disrupt
} disruption {
results[] = tag
}
}
var fn_a = make_fn("a")
var fn_b = make_fn("b")
fn_a()
fn_b()
if (length(results) != 2) fail("expected 2 results")
if (results[0] != "a") fail("first closure tag wrong")
if (results[1] != "b") fail("second closure tag wrong")
})
run("disruption handler modifies loop state", function() {
var total = 0
var i = 0
var fn = null
while (i < 3) {
fn = function() {
disrupt
} disruption {
total = total + i
}
fn()
i = i + 1
}
if (total != 3) fail("expected 3 got " + text(total))
})
run("disruption handler accesses object from outer scope", function() {
var obj = {x: 1, y: 2}
var fn = function() {
obj.x = 10
disrupt
} disruption {
obj.y = 20
}
fn()
if (obj.x != 10) fail("body mutation lost, x=" + text(obj.x))
if (obj.y != 20) fail("handler mutation lost, y=" + text(obj.y))
})
// ============================================================================
// TYPE CHECKING WITH is_* FUNCTIONS
// ============================================================================