TableTower/tests/test_expr_if.gd
RobinFiredrake d41a6e40aa Tests: 15 s budget, shared Godot workers; a freed Main cancels its roll
tools/run_tests.sh stops every run at 15 s and lists what was not run.
Suites are nodes run by tests/run_suites.gd, several per Godot process;
TestBase no longer compiles the app (AppTestBase does). Audit: fewer
repeats and less setup; 51 suites in about 12 s (was 45 s).

Fix a crash when a roll was still animating as its Main was freed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 16:19:30 -06:00

22 lines
891 B
GDScript

extends TestBase
## if(condition, then, else) in expressions, and the refused inline ternary.
## Run: tools/run_tests.sh expr_if
func run() -> void:
_value("if(1 > 2, 10, 20)", 20)
_value("if(3 > 2, 10, 20)", 10)
_value("if(1 = 1, \"yes\", \"no\")", "yes")
_value("if(0, 1, if(1, 2, 3))", 2)
_value("5 + if(2 >= 2, 1, 0)", 6)
for src in ["10 if 1 > 2 else 20", "1 if true else 2"]:
var r := Expr.evaluate(src, null)
_check(str(r.get("error", "")).contains("if(condition"), "\"%s\" is refused with a hint (got %s)" % [src, r])
_check(Expr.check(src) != "", "Expr.check flags \"%s\"" % src)
_check(Expr.check("if(@str > 8, 1, 0)") == "", "if() with a variable passes the check")
finish()
func _value(src: String, want: Variant) -> void:
var r := Expr.evaluate(src, null)
_check(str(r.get("error", "")) == "" and r.get("value") == want, "%s = %s (got %s)" % [src, want, r])