diff --git a/apps/tests/macro/match/guard_literal_or.nyash b/apps/tests/macro/match/guard_literal_or.nyash new file mode 100644 index 00000000..af3b16c2 --- /dev/null +++ b/apps/tests/macro/match/guard_literal_or.nyash @@ -0,0 +1,8 @@ +local d = 2 +local r = match d { + 1 if (1 < 2) => 10 + 2 if (2 < 3) => 20 + _ => 30 +} +print(r) + diff --git a/tools/test/smoke/macro/match_guard_literal_or_smoke.sh b/tools/test/smoke/macro/match_guard_literal_or_smoke.sh new file mode 100644 index 00000000..97d2c666 --- /dev/null +++ b/tools/test/smoke/macro/match_guard_literal_or_smoke.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +set -u + +root=$(cd "$(dirname "$0")"/../../../.. && pwd) +bin="$root/target/release/nyash" +src="apps/tests/macro/match/guard_literal_or.nyash" + +if [ ! -x "$bin" ]; then + echo "nyash binary not found at $bin; build first (cargo build --release)" >&2 + exit 1 +fi + +export NYASH_MACRO_ENABLE=1 + +# 1) AST expanded (no PeekExpr) +out_ast=$("$bin" --dump-expanded-ast-json "$src") +if [[ "$out_ast" == *'"kind":"PeekExpr"'* ]]; then + echo "[FAIL] Expanded AST still contains PeekExpr for guard-literal-or" >&2 + exit 2 +fi + +# 2) Runtime output check via VM +export NYASH_VM_USE_PY=1 +out_run=$("$bin" --backend vm "$src" | tr -d '\r') +# allow trailing newline to be trimmed by command substitution +if [ "$out_run" != "20" ] && [ "$out_run" != $'20\n' ]; then + echo "[FAIL] VM run unexpected output. Got:" >&2 + printf '%s\n' "$out_run" >&2 + exit 2 +fi + +echo "[OK] match guard literal OR smoke passed"