47 lines
1.2 KiB
Plaintext
47 lines
1.2 KiB
Plaintext
|
|
// Phase 183-3: Pattern2 Break test (_atoi pattern)
|
||
|
|
// Tests: Integer loop with break on non-digit character
|
||
|
|
// Note: Uses body-only LoopBodyLocal (digit computation not in condition)
|
||
|
|
|
||
|
|
static box Main {
|
||
|
|
main(args) {
|
||
|
|
// Simulate _atoi: convert "123" to integer
|
||
|
|
// For simplicity, we manually set up digit values
|
||
|
|
local result = 0
|
||
|
|
local i = 0
|
||
|
|
local n = 3 // length of "123"
|
||
|
|
|
||
|
|
loop(i < n) {
|
||
|
|
// Body-only LoopBodyLocal: digit computation
|
||
|
|
// In real _atoi: local digit = "0123456789".indexOf(ch)
|
||
|
|
// Here we simulate with hardcoded values for "123"
|
||
|
|
local digit = 0
|
||
|
|
if i == 0 { digit = 1 } // '1'
|
||
|
|
if i == 1 { digit = 2 } // '2'
|
||
|
|
if i == 2 { digit = 3 } // '3'
|
||
|
|
|
||
|
|
// Break on non-digit (digit < 0) - NOT using digit in condition here
|
||
|
|
// This is simplified: we always have valid digits
|
||
|
|
|
||
|
|
result = result * 10 + digit
|
||
|
|
i = i + 1
|
||
|
|
}
|
||
|
|
|
||
|
|
// Debug: print actual values
|
||
|
|
print("Final result:")
|
||
|
|
print(result)
|
||
|
|
print("Final i:")
|
||
|
|
print(i)
|
||
|
|
|
||
|
|
// Expected: result = 123
|
||
|
|
if result == 123 {
|
||
|
|
if i == 3 {
|
||
|
|
print("PASS: P2 Break with body-only LoopBodyLocal works")
|
||
|
|
return 0
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
print("FAIL: result or i incorrect")
|
||
|
|
return 1
|
||
|
|
}
|
||
|
|
}
|