Skip to content

Commit 16201bc

Browse files
committed
Add tests for string search configuration
Introduces tests for smart search defaults and strategy selection in the string module, including cases for minimum pattern length and small patterns.
1 parent 932ca75 commit 16201bc

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

test/str_config_test.gleam

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import str
2+
import gleam/list
3+
// removed unused import
4+
5+
pub fn smart_search_default_test() {
6+
assert str.smart_search_enabled() == False
7+
}
8+
9+
fn make_repeat(s: String, n: Int) -> String {
10+
list.fold(list.range(1, n), "", fn(acc, _) { acc <> s })
11+
}
12+
13+
pub fn choose_strategy_min_pattern_test() {
14+
let min = str.kmp_min_pattern_len()
15+
// pattern of length `min` should prefer KMP
16+
let pat = make_repeat("a", min)
17+
let strategy = str.choose_search_strategy("some text", pat)
18+
assert strategy == str.Kmp
19+
}
20+
21+
pub fn choose_strategy_small_pattern_test() {
22+
let pat = "a"
23+
let strategy = str.choose_search_strategy("short", pat)
24+
assert strategy == str.Sliding
25+
}

0 commit comments

Comments
 (0)