diff --git a/src/core/CCUtf8_string.ml b/src/core/CCUtf8_string.ml index c462fda6..cd6a8589 100644 --- a/src/core/CCUtf8_string.ml +++ b/src/core/CCUtf8_string.ml @@ -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.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 +*)