add tests for utf8string

This commit is contained in:
Simon Cruanes 2020-12-07 23:32:00 -05:00
parent 3918ed1155
commit e16926fa5f

View file

@ -306,6 +306,17 @@ let of_string s = if is_valid s then Some s else None
let printer s = String.escaped (to_string s) let printer s = String.escaped (to_string s)
let pp_uchar (c:Uchar.t) = Printf.sprintf "0x%x" (Uchar.to_int c) let pp_uchar (c:Uchar.t) = Printf.sprintf "0x%x" (Uchar.to_int c)
let arb_uchar =
let rec gen = lazy (
let open Q.Gen in
Q.Gen.int_range Uchar.(to_int min) Uchar.(to_int max) >>= fun n ->
try return (Uchar.of_int n)
with _ -> Lazy.force gen
) in
Q.make
~print:(fun c -> Printf.sprintf "<uchar '%d'>" (Uchar.to_int c))
(Lazy.force gen)
let uutf_is_valid s = let uutf_is_valid s =
try try
Uutf.String.fold_utf_8 Uutf.String.fold_utf_8
@ -351,6 +362,26 @@ let of_string s = if is_valid s then Some s else None
) )
*) *)
(*$QR & ~long_factor:10
Q.(small_list arb_uchar) (fun l ->
let s = of_list l in
l = to_list s)
*)
(*$QR & ~long_factor:10
Q.(small_list arb_uchar) (fun l ->
let s = of_list l in
l = (to_list @@ of_gen @@ to_gen s)
)
*)
(*$QR & ~long_factor:10
Q.(small_list arb_uchar) (fun l ->
let s = of_list l in
l = (to_list @@ of_iter @@ to_iter s)
)
*)
(*$T (*$T
not (is_valid "\192\181") not (is_valid "\192\181")
not (is_valid "\193\143") not (is_valid "\193\143")
@ -401,3 +432,10 @@ let of_string s = if is_valid s then Some s else None
(pp l_uutf) (pp l_co) (is_valid s) (uutf_is_valid s) (pp l_uutf) (pp l_co) (is_valid s) (uutf_is_valid s)
) )
*) *)
(*$R
for i = 0 to 127 do
let c = Uchar.of_int i in
assert_equal 1 (n_bytes (of_list [c]))
done
*)