extends SceneTree ## if(condition, then, else) in expressions, and the refused inline ternary. ## Run: godot --headless --path . -s res://tests/test_expr_if.gd -- --sample var _failures := 0 func _init() -> 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") print("%s: %d failure(s)" % ["PASS" if _failures == 0 else "FAIL", _failures]) quit(1 if _failures else 0) 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]) func _check(ok: bool, what: String) -> void: if not ok: _failures += 1 print(" ✗ ", what)