Skip to content

Commit a4812c6

Browse files
Merge pull request #13 from francoisthire/codex/find-and-fix-important-codebase-bug
Fix char generator root handling
2 parents 56927d7 + 879542d commit a4812c6

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

lib_bam/std.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ let bool ?(shrinker = Shrinker.Default) () =
138138
let char ?root ?(shrinker = Shrinker.Default) ?(printable = true) () =
139139
let base = if printable then Char.code 'a' else 0 in
140140
let max = if printable then 26 else 256 in
141-
let root = root |> Option.map (fun root -> Char.code root - Char.code 'a') in
141+
let root = root |> Option.map (fun root -> Char.code root - base) in
142142
match shrinker with
143143
| Manual shrinker ->
144144
let*! root = int ?root ~min:0 ~max () in

test/std.ml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@ let std_oneof () =
3333
let str = values |> List.map string_of_int |> String.concat " " in
3434
Regression.capture str ; Lwt.return_unit
3535

36+
let std_char_custom_root () =
37+
Test.register ~__FILE__ ~title:"std char custom root"
38+
~tags:["std"; "char"; "root"]
39+
@@ fun () ->
40+
let gen = Bam.Std.char ~printable:false ~root:(Char.chr 5) () in
41+
let v =
42+
Bam.Gen.run gen (Bam.Gen.Random.make [|0|]) |> Bam.Tree.root |> Char.code
43+
in
44+
if v = 5 then Lwt.return_unit
45+
else Test.failf "expected 5 got %d" v
46+
3647
let register () =
3748
std_int_range_inclusive_bounds () ;
38-
std_oneof ()
49+
std_oneof () ;
50+
std_char_custom_root ()

0 commit comments

Comments
 (0)