mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 03:05:28 -05:00
add tests for utf8string
This commit is contained in:
parent
3918ed1155
commit
e16926fa5f
1 changed files with 38 additions and 0 deletions
|
|
@ -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 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 =
|
||||
try
|
||||
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
|
||||
not (is_valid "\192\181")
|
||||
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)
|
||||
)
|
||||
*)
|
||||
|
||||
(*$R
|
||||
for i = 0 to 127 do
|
||||
let c = Uchar.of_int i in
|
||||
assert_equal 1 (n_bytes (of_list [c]))
|
||||
done
|
||||
*)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue