Skip to content

Commit 4f37d7b

Browse files
committed
Refactor token pool and index generation in fuzz test
Expanded the token pool in gen_token_pool() for improved readability and maintainability. Updated idx_for() to use more readable numeric literals and reformatted conditional logic for clarity.
1 parent 994f955 commit 4f37d7b

1 file changed

Lines changed: 49 additions & 12 deletions

File tree

test/str_html_escape_fuzz_test.gleam

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import gleeunit
2-
import str
31
import gleam/list
42
import gleam/string
3+
import gleeunit
4+
import str
55

66
pub fn main() -> Nil {
77
gleeunit.main()
@@ -10,22 +10,59 @@ pub fn main() -> Nil {
1010
// Deterministic, simple generator over a token pool.
1111
fn gen_token_pool() -> List(String) {
1212
[
13-
"a","b","c","1","2","3"," ","\n","<",">","&","\"","'",
14-
"&amp;","&lt;","&gt;","&quot;","&#39;","&#x27;","&#x22;","&notanentity;",
15-
"&","&amp","&#", "&#x",
16-
"\u{00A0}", // NBSP
17-
"Café","naïve","ø","漢","字",
18-
"👩‍👩‍👧‍👦","👨‍👩‍👧","️","✈️","🏳️‍🌈",
19-
"\u{0301}", // combining acute
20-
"&alpha;","&beta;","&gamma;"
13+
"a",
14+
"b",
15+
"c",
16+
"1",
17+
"2",
18+
"3",
19+
" ",
20+
"\n",
21+
"<",
22+
">",
23+
"&",
24+
"\"",
25+
"'",
26+
"&amp;",
27+
"&lt;",
28+
"&gt;",
29+
"&quot;",
30+
"&#39;",
31+
"&#x27;",
32+
"&#x22;",
33+
"&notanentity;",
34+
"&",
35+
"&amp",
36+
"&#",
37+
"&#x",
38+
"\u{00A0}",
39+
// NBSP
40+
"Café",
41+
"naïve",
42+
"ø",
43+
"漢",
44+
"字",
45+
"👩‍👩‍👧‍👦",
46+
"👨‍👩‍👧",
47+
"️",
48+
"✈️",
49+
"🏳️‍🌈",
50+
"\u{0301}",
51+
// combining acute
52+
"&alpha;",
53+
"&beta;",
54+
"&gamma;",
2155
]
2256
}
2357

2458
// Deterministic pseudo-random index using seed and i
2559
fn idx_for(seed: Int, i: Int, len: Int) -> Int {
2660
// simple LCG-ish formula; keep small to avoid large-int overhead
27-
let v = seed * 1103515245 + 12345 + i
28-
let v_pos = case v < 0 { True -> -v False -> v }
61+
let v = seed * 1_103_515_245 + 12_345 + i
62+
let v_pos = case v < 0 {
63+
True -> -v
64+
False -> v
65+
}
2966
v_pos % len
3067
}
3168

0 commit comments

Comments
 (0)