From 1a3e6474c38ecf66cc76d4c421829a39aa6286a0 Mon Sep 17 00:00:00 2001 From: nyash-codex Date: Wed, 17 Dec 2025 01:01:07 +0900 Subject: [PATCH] test: add phase95 json_loader escape fixture --- .../tests/phase95_json_loader_escape_min.hako | 34 +++++++++++ .../apps/phase95_json_loader_escape_vm.sh | 58 +++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 apps/tests/phase95_json_loader_escape_min.hako create mode 100644 tools/smokes/v2/profiles/integration/apps/phase95_json_loader_escape_vm.sh diff --git a/apps/tests/phase95_json_loader_escape_min.hako b/apps/tests/phase95_json_loader_escape_min.hako new file mode 100644 index 00000000..e2184beb --- /dev/null +++ b/apps/tests/phase95_json_loader_escape_min.hako @@ -0,0 +1,34 @@ +// Phase 95: json_loader escape loop (minimal) +// Purpose: Fixture extracted from MiniJsonLoader.read_quoted_from to exercise +// Phase 94 derived body-local + conditional skip in JoinIR. + +static box Main { + main() { + // Input mirrors the json_loader escape case + local s = "\"hello\\\" world\"" + local pos = 0 + local i = pos + if s.substring(i, i + 1) != "\"" { return "NG" } + i = i + 1 + local out = "" + local n = s.length() + + loop(i < n) { + local ch = s.substring(i, i + 1) + if ch == "\"" { break } + + if ch == "\\" { + i = i + 1 + if i < n { + ch = s.substring(i, i + 1) + } + } + + out = out + ch + i = i + 1 + } + + print(out) + return "OK" + } +} diff --git a/tools/smokes/v2/profiles/integration/apps/phase95_json_loader_escape_vm.sh b/tools/smokes/v2/profiles/integration/apps/phase95_json_loader_escape_vm.sh new file mode 100644 index 00000000..412503cd --- /dev/null +++ b/tools/smokes/v2/profiles/integration/apps/phase95_json_loader_escape_vm.sh @@ -0,0 +1,58 @@ +#!/bin/bash +# Phase 95: json_loader escape loop (VM) +# +# Verifies: +# - Phase 94 derived body-local + conditional skip works on the MiniJsonLoader.escape loop shape +# - Output matches hello" world (escape removed) +# +# Scope: integration only (keep quick lean) + +source "$(dirname "$0")/../../../lib/test_runner.sh" +export SMOKES_USE_PYVM=0 +require_env || exit 2 + +PASS_COUNT=0 +FAIL_COUNT=0 +RUN_TIMEOUT_SECS=${RUN_TIMEOUT_SECS:-10} + +INPUT="$NYASH_ROOT/apps/tests/phase95_json_loader_escape_min.hako" + +echo "[INFO] Phase 95: json_loader escape loop (VM) - $INPUT" + +set +e +OUTPUT=$(timeout "$RUN_TIMEOUT_SECS" env \ + NYASH_DISABLE_PLUGINS=1 \ + HAKO_JOINIR_STRICT=1 \ + "$NYASH_BIN" --backend vm "$INPUT" 2>&1) +EXIT_CODE=$? +set -e + +if [ "$EXIT_CODE" -eq 124 ]; then + echo "[FAIL] hakorune timed out (>${RUN_TIMEOUT_SECS}s)" + FAIL_COUNT=$((FAIL_COUNT + 1)) +elif [ "$EXIT_CODE" -eq 0 ]; then + if echo "$OUTPUT" | grep -q '^hello" world$'; then + echo "[PASS] Output verified: hello\" world" + PASS_COUNT=$((PASS_COUNT + 1)) + else + echo "[FAIL] Unexpected output (expected line: hello\" world)" + echo "[INFO] output (tail):" + echo "$OUTPUT" | tail -n 50 || true + FAIL_COUNT=$((FAIL_COUNT + 1)) + fi +else + echo "[FAIL] hakorune failed with exit code $EXIT_CODE" + echo "[INFO] output (tail):" + echo "$OUTPUT" | tail -n 50 || true + FAIL_COUNT=$((FAIL_COUNT + 1)) +fi + +echo "[INFO] PASS: $PASS_COUNT, FAIL: $FAIL_COUNT" + +if [ "$FAIL_COUNT" -eq 0 ]; then + test_pass "phase95_json_loader_escape_vm: All tests passed" + exit 0 +else + test_fail "phase95_json_loader_escape_vm: $FAIL_COUNT test(s) failed" + exit 1 +fi