test: strengthen phase96 next_non_ws fixture

This commit is contained in:
nyash-codex
2025-12-17 01:35:43 +09:00
parent ba87afd35c
commit db4453eb3c
3 changed files with 18 additions and 12 deletions

View File

@ -2,15 +2,14 @@
// Purpose: Trim系の実ループを fixtures/smoke で押さえる。
static box Main {
main() {
// Input mirrors MiniJsonLoader.next_non_ws
local s = "hi"
next_non_ws(s) {
local i = 0
local n = s.length()
loop(i < n) {
local ch = s.substring(i, i + 1)
if ch == " " || ch == "\n" || ch == "\r" || ch == "\t" {
// Treat empty substring as whitespace for robustness
if ch == "" || ch == " " || ch == "\n" || ch == "\r" || ch == "\t" {
i = i + 1
} else {
break
@ -18,10 +17,15 @@ static box Main {
}
if i < n {
print(i)
} else {
print(-1)
return i
}
return -1
}
main() {
// Input mirrors MiniJsonLoader.next_non_ws
print(next_non_ws(" " + " " + "hi")) // expect 2
print(next_non_ws(" " + "\t")) // expect -1
return "OK"
}
}