phase29ab(p8): add pattern6/7 ok fixtures and smokes

This commit is contained in:
2025-12-28 16:00:19 +09:00
parent 5edda8a0c2
commit 720468c3a5
4 changed files with 123 additions and 0 deletions

View File

@ -0,0 +1,19 @@
// Phase 29ab P8: Pattern6 scan_with_init OK minimal
// Expect: return index of "b" -> 1
static box Main {
find_ok(s, ch) {
local i = 0
loop(i < s.length()) {
if s.substring(i, i + 1) == ch {
return i
}
i = i + 1
}
return -1
}
main() {
return Main.find_ok("abc", "b")
}
}

View File

@ -0,0 +1,37 @@
// Phase 29ab P8: Pattern7 split scan OK minimal
// Expect: split("a,b,c", ",") -> length 3
static box StringUtils {
split_ok(s, separator) {
local result = new ArrayBox()
if separator.length() == 0 {
result.push(s)
return result
}
local start = 0
local i = 0
loop(i <= s.length() - separator.length()) {
if s.substring(i, i + separator.length()) == separator {
result.push(s.substring(start, i))
start = i + separator.length()
i = start
} else {
i = i + 1
}
}
if start <= s.length() {
result.push(s.substring(start, s.length()))
}
return result
}
}
static box Main {
main() {
local result = StringUtils.split_ok("a,b,c", ",")
return result.length()
}
}

View File

@ -0,0 +1,37 @@
#!/bin/bash
# Phase 29ab P8: Pattern6 scan_with_init OK minimal (VM backend)
# Tests: return index 1
source "$(dirname "$0")/../../../lib/test_runner.sh"
export SMOKES_USE_PYVM=0
require_env || exit 2
INPUT="$NYASH_ROOT/apps/tests/phase29ab_pattern6_scan_with_init_ok_min.hako"
RUN_TIMEOUT_SECS=${RUN_TIMEOUT_SECS:-10}
set +e
OUTPUT=$(timeout "$RUN_TIMEOUT_SECS" env NYASH_DISABLE_PLUGINS=1 HAKO_JOINIR_STRICT=1 "$NYASH_BIN" "$INPUT" 2>&1)
EXIT_CODE=$?
set -e
if [ "$EXIT_CODE" -eq 124 ]; then
test_fail "phase29ab_pattern6_scan_with_init_ok_min_vm: hakorune timed out (>${RUN_TIMEOUT_SECS}s)"
exit 1
fi
if [ "$EXIT_CODE" -eq 1 ]; then
test_pass "phase29ab_pattern6_scan_with_init_ok_min_vm: RC=1 (expected)"
exit 0
fi
if [ "$EXIT_CODE" -eq 0 ]; then
echo "[FAIL] Expected exit 1, got 0"
echo "$OUTPUT" | tail -n 40 || true
test_fail "phase29ab_pattern6_scan_with_init_ok_min_vm: Unexpected success"
exit 1
fi
echo "[FAIL] Expected exit 1, got $EXIT_CODE"
echo "$OUTPUT" | tail -n 40 || true
test_fail "phase29ab_pattern6_scan_with_init_ok_min_vm: Unexpected RC"
exit 1

View File

@ -0,0 +1,30 @@
#!/bin/bash
# Phase 29ab P8: Pattern7 split scan OK minimal (VM backend)
# Tests: split length -> 3
source "$(dirname "$0")/../../../lib/test_runner.sh"
export SMOKES_USE_PYVM=0
require_env || exit 2
INPUT="$NYASH_ROOT/apps/tests/phase29ab_pattern7_splitscan_ok_min.hako"
RUN_TIMEOUT_SECS=${RUN_TIMEOUT_SECS:-10}
set +e
OUTPUT=$(timeout "$RUN_TIMEOUT_SECS" env NYASH_DISABLE_PLUGINS=1 HAKO_JOINIR_STRICT=1 "$NYASH_BIN" "$INPUT" 2>&1)
EXIT_CODE=$?
set -e
if [ "$EXIT_CODE" -eq 124 ]; then
test_fail "phase29ab_pattern7_splitscan_ok_min_vm: hakorune timed out (>${RUN_TIMEOUT_SECS}s)"
exit 1
fi
if [ "$EXIT_CODE" -eq 3 ]; then
test_pass "phase29ab_pattern7_splitscan_ok_min_vm: RC=3 (expected)"
exit 0
fi
echo "[FAIL] Expected exit 3, got $EXIT_CODE"
echo "$OUTPUT" | tail -n 40 || true
test_fail "phase29ab_pattern7_splitscan_ok_min_vm: Unexpected RC"
exit 1