phase29ab(p8): add pattern6/7 ok fixtures and smokes
This commit is contained in:
19
apps/tests/phase29ab_pattern6_scan_with_init_ok_min.hako
Normal file
19
apps/tests/phase29ab_pattern6_scan_with_init_ok_min.hako
Normal 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")
|
||||
}
|
||||
}
|
||||
37
apps/tests/phase29ab_pattern7_splitscan_ok_min.hako
Normal file
37
apps/tests/phase29ab_pattern7_splitscan_ok_min.hako
Normal 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()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user