Skip to content

Commit f42fce0

Browse files
committed
Add Bytes.index_opt
1 parent ef4d581 commit f42fce0

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/bytes/stm_tests.ml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ struct
1616
| Fill of int * int * char
1717
| Blit_string of string * int * int * int
1818
| Index of char
19+
| Index_opt of char
1920
| To_seq
2021

2122
let pp_cmd par fmt x =
@@ -31,6 +32,7 @@ struct
3132
| Fill (x, y, z) -> cst3 pp_int pp_int pp_char "Fill" par fmt x y z
3233
| Blit_string (x, y, z, w) -> cst4 pp_string pp_int pp_int pp_int "Blit_string" par fmt x y z w
3334
| Index x -> cst1 pp_char "Index" par fmt x
35+
| Index_opt x -> cst1 pp_char "Index_opt" par fmt x
3436
| To_seq -> cst0 "To_seq" fmt
3537

3638
let show_cmd = Util.Pp.to_show pp_cmd
@@ -64,6 +66,7 @@ struct
6466
map3 (fun i len c -> Fill (i,len,c)) int_gen int_gen char_gen; (* hack: reusing int_gen for length*)
6567
map4 (fun src spos dpos l -> Blit_string (src,spos,dpos,l)) string_small int_gen int_gen int_gen; (* hack: reusing int_gen for length*)
6668
map (fun c -> Index c) char_gen;
69+
map (fun c -> Index_opt c) char_gen;
6770
return To_seq;
6871
])
6972

@@ -89,6 +92,7 @@ struct
8992
then List.mapi (fun j c' -> if dpos <= j && j <= dpos+l-1 then src.[spos+j-dpos] else c') s
9093
else s
9194
| Index _ -> s
95+
| Index_opt _ -> s
9296
| To_seq -> s
9397

9498
let init_sut () = Bytes.make byte_size 'a'
@@ -108,6 +112,7 @@ struct
108112
| Fill (i,l,c) -> Res (result unit exn, protect (Bytes.fill b i l) c)
109113
| Blit_string (src,spos,dpos,l) -> Res (result unit exn, protect (Bytes.blit_string src spos b dpos) l)
110114
| Index c -> Res (result int exn, protect (Bytes.index b) c)
115+
| Index_opt c -> Res (option int, Bytes.index_opt b c)
111116
| To_seq -> Res (seq char, List.to_seq (List.of_seq (Bytes.to_seq b)))
112117

113118
let postcond c (s: char list) res = match c, res with
@@ -142,6 +147,8 @@ struct
142147
(match List.find_index (fun c' -> c' = c) s with
143148
| Some i -> r = Ok i
144149
| None -> r = Error Not_found)
150+
| Index_opt c, Res ((Option Int,_), r) ->
151+
r = List.find_index (fun c' -> c' = c) s
145152
| To_seq, Res ((Seq Char,_),r) -> Seq.equal (=) r (List.to_seq s)
146153
| _, _ -> false
147154
end

0 commit comments

Comments
 (0)