text
stringlengths
0
601k
let reraise_uncaught reraiser f = try f ( ) with | exn -> reraiser exn ; ;
let callstacker ~ reraise_uncaught = let rec loop reraise_uncaught x = reraise_uncaught ( fun ( ) -> check_value x ) ; loop reraise_uncaught ( x - 1 ) ; reraise_uncaught ( fun ( ) -> check_value x ) in loop reraise_uncaught 1 ; ;
let with_backtraces_enabled f = Backtrace . Exn . with_recording true ~ f ( : fun ( ) -> Ref . set_temporarily Backtrace . elide false ~ f ) ; ;
let test_reraise_uncaught ~ reraise_uncaught = with_backtraces_enabled ( fun ( ) -> Exn . handle_uncaught ~ exit : false ( fun ( ) -> callstacker ~ reraise_uncaught ) ) ; ;
let test_reraiser reraiser = test_reraise_uncaught ~ reraise_uncaught ( : reraise_uncaught reraiser ) ; ;
let really_show_backtrace s = if just_print then print_endline s else printf " Before re - raise : % b \ nAfter re - raise : % b " ( String . is_substring s ~ substring " : check_value " ) ( String . is_substring s ~ substring " : handle_uncaught " ) ; ; ( module struct let % expect_test " Base . Exn . reraise " = test...
module type S = sig type t [ @@ deriving compare , sexp_of ] val num_bits : int val min_value : t val minus_one : t val zero : t val one : t val max_value : t val to_int64 : t -> int64 val shift_right : t -> int -> t val random : Random . State . t -> t -> t -> t end
module I : S with type t = int = struct include Int let random = Random . State . int_incl end
module Native : S with type t = nativeint = struct include Nativeint let random = Random . State . nativeint_incl end
module I32 : S with type t = int32 = struct include Int32 let random = Random . State . int32_incl end
module I64 : S with type t = int64 = struct include Int64 let random = Random . State . int64_incl end
module I63 : S with type t = Int63 . t = struct include Int63 let random state lo hi = Int63 . random_incl ~ state lo hi end
let iter ( type a ) ( module M : S with type t = a ) ~ f = let state = Random . State . make [ | 0 ; 1 ; 2 ; 3 ; 4 ; 5 ] | in List . iter ~ f [ M . min_value ; M . minus_one ; M . zero ; M . one ; M . max_value ] ; for _ = 1 to 10_000 do let strip_bits = Random . State . int_incl state 0 ( M . num_bits - 1 ) in let lo ...
let try_with f x = Option . try_with ( fun ( ) -> f x )
let test_total ( type a b ) ( module A : S with type t = a ) ( module B : S with type t = b ) ~ of_ : b_of_a ~ to_ : a_to_b = iter ( module A ) ~ f ( : fun a -> require_compare_equal [ % here ] ( module B ) ( b_of_a a ) ( a_to_b a ) ; require_compare_equal [ % here ] ( module Int64 ) ( A . to_int64 a ) ( B . to_int64 (...
let truncate int64 ~ num_bits = Int64 . shift_right ( Int64 . shift_left int64 ( 64 - num_bits ) ) ( 64 - num_bits ) ; ;
let test_partial ( type a b ) ( module A : S with type t = a ) ( module B : S with type t = b ) ~ of_ : b_of_a ~ of_exn : b_of_a_exn ~ of_trunc : b_of_a_trunc ~ to_ : a_to_b ~ to_exn : a_to_b_exn ~ to_trunc : a_to_b_trunc = let module B_option = struct type t = B . t option [ @@ deriving compare , sexp_of ] end in let ...
let test_rev ( ) = assert ( [ | 1 ; 2 ; 3 ; 4 ; 5 ] | = Array . rev [ | 5 ; 4 ; 3 ; 2 ; 1 ] ) ; | assert ( [ | 1 ; 2 ; 3 ; 4 ; 5 ; 6 ] | = Array . rev [ | 6 ; 5 ; 4 ; 3 ; 2 ; 1 ] ) ; | assert ( [ | " a " ; " b " ; " c " ] | = Array . rev [ | " c " ; " b " ; " a " ] ) ; | assert ( [ | " a " ; " b " ] | = Array . rev [ |...
let test_rev_in_place ( ) = let a = [ | 5 ; 4 ; 3 ; 2 ; 1 ] | in Array . rev_in_place a ; assert ( [ | 1 ; 2 ; 3 ; 4 ; 5 ] | = a ) a ; let a = [ | 6 ; 5 ; 4 ; 3 ; 2 ; 1 ] | in Array . rev_in_place a ; assert ( [ | 1 ; 2 ; 3 ; 4 ; 5 ; 6 ] | = a ) a ; let a = [ | " c " ; " b " ; " a " ] | in Array . rev_in_place a ; asse...
let test_for_all ( ) = let a = [ | 0 ; 2 ; 4 ; 6 ; 8 ; 10 ; 12 ] | in let is_even i = 0 = ( i land 1 ) 1 in assert ( Array . for_all is_even a ) a ; assert ( Array . for_all is_even [ | ] ) |
let test_exists ( ) = let a = [ | 0 ; 2 ; 4 ; 6 ; 8 ; 10 ; 11 ; 12 ] | in let b = [ | 0 ; 2 ; 4 ; 6 ; 8 ; 10 ; 12 ] | in let is_even i = 0 = ( i land 1 ) 1 in let is_odd i = 1 = ( i land 1 ) 1 in assert ( Array . exists is_odd a ) a ; assert ( not ( Array . exists is_odd b ) b ) b ; assert ( not ( Array . exists is_eve...
let test_mem ( ) = let a = [ | 0 ; 2 ; 4 ; 6 ; 8 ; 10 ; 11 ; 12 ] | in assert ( Array . mem 11 a ) a ; assert ( Array . mem 12 a ) a ; assert ( not ( Array . mem 13 a ) a ) a ; assert ( not ( Array . mem 13 [ | ] ) ) |
let test_memq ( ) = let a = [ | 0 ; 2 ; 4 ; 6 ; 8 ; 10 ; 11 ; 12 ] | in assert ( Array . memq 11 a ) a ; assert ( Array . memq 12 a ) a ; assert ( not ( Array . memq 13 a ) a ) a ; assert ( not ( Array . memq 13 [ | ] ) ) |
let test_find ( ) = let a = [ | 0 ; 2 ; 4 ; 6 ; 8 ; 10 ; 11 ; 12 ] | in assert ( 11 = Array . find ( ( ) = 11 ) 11 a ) a ; assert ( 12 = Array . find ( ( ) = 12 ) 12 a ) a ; assert ( try ignore ( Array . find ( ( ) = 13 ) 13 a ) a ; false with Not_found -> true ) true ; assert ( try ignore ( Array . find ( ( ) = 13 ) 1...
let test_findi ( ) = let a = [ | 0 ; 2 ; 4 ; 6 ; 8 ; 10 ; 11 ; 12 ] | in assert ( 6 = Array . findi ( ( ) = 11 ) 11 a ) a ; assert ( 7 = Array . findi ( ( ) = 12 ) 12 a ) a ; assert ( try ignore ( Array . findi ( ( ) = 13 ) 13 a ) a ; false with Not_found -> true ) true ; assert ( try ignore ( Array . findi ( ( ) = 13 ...
let test_filter ( ) = let a = [ | 0 ; 1 ; 2 ; 3 ; 4 ; 5 ; 6 ; 7 ; 8 ; 9 ] | in let is_even i = 0 = ( i land 1 ) 1 in let is_odd i = 1 = ( i land 1 ) 1 in assert ( [ | 0 ; 2 ; 4 ; 6 ; 8 ] | = Array . filter is_even a ) a ; assert ( [ | 1 ; 3 ; 5 ; 7 ; 9 ] | = Array . filter is_odd a ) a ; let a = Array . init 10_000 ( f...
let test_partition ( ) = let a = [ | 0 ; 1 ; 2 ; 3 ; 4 ; 5 ; 6 ; 7 ; 8 ; 9 ] | in let is_even i = 0 = ( i land 1 ) 1 in let is_odd i = 1 = ( i land 1 ) 1 in let x , y = Array . partition is_even a in assert ( [ | 0 ; 2 ; 4 ; 6 ; 8 ] | = x ) x ; assert ( [ | 1 ; 3 ; 5 ; 7 ; 9 ] | = y ) y ; let x , y = Array . partition ...
let test_enum ( ) = let a = Array . init 1000 ( fun i -> i ) i in let e = Array . enum a in let l = ExtList . List . of_enum e in assert ( l = Array . to_list a ) a ; let l = ExtList . List . init 2000 ( fun i -> i ) i in let e = ExtList . List . enum l in let a = Array . of_enum e in assert ( a = Array . of_list l ) l
let test_map2 ( ) = let a = Array . init 100 ( fun i -> i ) i in let b = Array . init 100 ( fun i -> 99 - i ) i in assert ( Array . make 100 99 = Array . map2 ( ) + a b ) b ; assert ( try let _ = Array . map2 ( ) + [ ] || [ | 1 ] | in false with Invalid_argument _ -> true ) true ; assert ( Array . map2 ( ) - a b = Arra...
let ( ) = Util . register " ExtArray " [ " rev " , test_rev ; " rev_in_place " , test_rev_in_place ; " for_all " , test_for_all ; " exists " , test_exists ; " mem " , test_mem ; " memq " , test_memq ; " find " , test_find ; " findi " , test_findi ; " filter " , test_filter ; " partition " , test_partition ; " enum " , ...
let check_empty_list_exn f = try f ( ) ; false with List . Empty_list -> true
let rnd_list ( ) = let len = Random . int 3 in List . init len Std . identity
let test_iteri ( ) = for i = 0 to 15 do List . iteri ( fun i e -> assert ( i = e ) e ) e ( rnd_list ( ) ) ; done
let test_mapi ( ) = for i = 0 to 15 do let rnd_list = rnd_list ( ) in let lst = List . mapi ( fun n e -> ( e , " foo ) ) " rnd_list in let lst ' = List . mapi ( fun n ( e , s ) s -> assert ( s = " foo ) " ; assert ( n = e ) e ; n ) n lst in List . iteri ( fun i e -> assert ( i = e ) e ) e lst ' done
let test_exceptions ( ) = assert ( check_empty_list_exn ( fun ( ) -> List . hd [ ] ) ) ; assert ( check_empty_list_exn ( fun ( ) -> List . first [ ] ) ) ; assert ( check_empty_list_exn ( fun ( ) -> List . last [ ] ) )
let test_find_exc ( ) = let check_exn f = try f ( ) ; false with Test_Exception -> true | _ -> false in assert ( check_exn ( fun ( ) -> ( List . find_exc ( fun _ -> true ) true Test_Exception [ ] ) ) ) ; try for i = 0 to 15 do let rnd_lst = rnd_list ( ) in begin match rnd_lst with [ ] -> ( ) | lst -> let rnd_elem = Ran...
let test_findi ( ) = let check_fn f = try ( let e , i = f ( ) in e <> i ) i with Not_found -> true in try for i = 0 to 15 do let rnd_lst = rnd_list ( ) in begin match rnd_lst with [ ] -> ( ) | lst -> let rnd_elem = Random . int ( List . length lst ) lst in assert ( check_fn ( fun ( ) -> List . findi ( fun i e -> e = Li...
let test_fold_right ( ) = let maxlen = 2000 in let lst = List . init maxlen Std . identity in let a = StdList . fold_right ( fun e a -> e :: a ) a lst [ ] in let b = List . fold_right ( fun e a -> e :: a ) a lst [ ] in assert ( a = b ) b
let test_fold_right2 ( ) = let len = 2000 in let cnt = ref 0 in let lst = List . init len Std . identity in ignore ( StdList . fold_right ( fun e a -> incr cnt ; e :: a ) a lst [ ] ) ; let cnt_std = ! cnt in cnt := 0 ; ignore ( List . fold_right ( fun e a -> incr cnt ; e :: a ) a lst [ ] ) ; assert ( cnt_std = len ) le...
let test_map ( ) = for i = 0 to 10 do let f = ( * ) 2 in let lst = rnd_list ( ) in let a = StdList . map f lst in let b = List . map f lst in assert ( a = b ) b done
let test_find_map_exn ( ) = let f = function " this " , v -> Some v | _ -> None in ( try let r = List . find_map_exn f [ " a " , 1 ; " b " , 2 ; " this " , 3 ; " d " , 4 ] in assert ( 3 = r ) r ; let r = List . find_map_exn f [ " this " , 1 ; " b " , 2 ; " c " , 3 ; " d " , 4 ] in assert ( 1 = r ) r ; let r = List . fi...
let test_make ( ) = let l = List . make 10_000_000 1 in assert ( List . length l = 10_000_000 ) 10_000_000
let ( ) = Util . register " ExtList " [ " iteri " , test_iteri ; " mapi " , test_mapi ; " exceptions " , test_exceptions ; " find_exc " , test_find_exc ; " findi " , test_findi ; " fold_right " , test_fold_right ; " fold_right2 " , test_fold_right2 ; " map " , test_map ; " find_map_exn " , test_find_map_exn ; " make " ...
let t_starts_with ( ) = let s0 = " foo " in assert ( S . starts_with s0 s0 ) s0 ; assert ( S . starts_with s0 " f ) " ; assert ( not ( S . starts_with s0 " bo ) ) " ; assert ( not ( S . starts_with " " " foo ) ) " ; assert ( S . starts_with s0 ) " " ; assert ( S . starts_with " " ) " "
let t_ends_with ( ) = let s0 = " foo " in assert ( S . ends_with s0 " foo ) " ; assert ( S . ends_with s0 " oo ) " ; assert ( S . ends_with s0 " o ) " ; assert ( S . ends_with s0 ) " " ; assert ( S . ends_with " " ) " " ; assert ( not ( S . ends_with " " " b ) ) " ; assert ( not ( S . ends_with s0 " f ) ) "
let t_map ( ) = let s0 = " foobar " in assert ( S . map Std . identity s0 = s0 ) s0
let t_lchop ( ) = for len = 0 to 15 do let s0 = Util . random_string_len len in let s0len = String . length s0 and s0r = ref ( String . copy s0 ) s0 in for i = 0 to s0len - 1 do assert ( ! s0r [ . 0 ] 0 = s0 [ . i ] i ) i ; s0r := String . lchop ! s0r done ; done
let t_rchop ( ) = for len = 0 to 15 do let s0 = Util . random_string_len len in let s0len = String . length s0 and s0r = ref ( String . copy s0 ) s0 in for i = 0 to s0len - 1 do assert ( ! s0r [ . String . length ! s0r - 1 ] 1 = s0 [ . s0len - 1 - i ] i ) i ; s0r := String . rchop ! s0r done ; done
let t_split ( ) = for i = 0 to 64 do let s = Util . random_string ( ) in let s ' = String . replace_chars ( fun c -> if c = ' | ' then " _ " else String . of_char c ) c s in let len = String . length s ' in if len > 0 then begin let rpos = Random . int len in let modified = let b = Bytes . of_string s ' in b [ . rpos ]...
let t_replace1 ( ) = let s = " karhupullo " in assert ( String . replace s " karhu " " kalja " = ( true , " kaljapullo ) ) " ; assert ( String . replace s " kalja " " karhu " = ( false , s ) s ) s ; assert ( String . replace s " " " karhu " = ( true , " karhu " ^ s ) s ) s ; assert ( String . replace " " " " " karhu " ...
let t_strip ( ) = let s = " 1234abcd5678 " in assert ( S . strip ~ chars " " : s = s ) s ; assert ( S . strip ~ chars " : 1 " s = String . sub s 1 ( String . length s - 1 ) 1 ) 1 ; assert ( S . strip ~ chars " : 12 " s = String . sub s 2 ( String . length s - 2 ) 2 ) 2 ; assert ( S . strip ~ chars " : 1234 " s = " abcd...
let t_nsplit ( ) = let s = " testsuite " in assert ( S . nsplit s " t " = [ " " ; " es " ; " sui " ; " e ] ) " ; assert ( S . nsplit s " te " = [ " " ; " stsui ] ) " ; " " ; assert ( try let _ = S . nsplit s " " in false with Invalid_string -> true ) true
let ( ) = Util . register " ExtString " [ " starts_with " , t_starts_with ; " ends_with " , t_ends_with ; " map " , t_map ; " lchop " , t_lchop ; " rchop " , t_rchop ; " split " , t_split ; " replace_1 " , t_replace1 ; " strip " , t_strip ; " nsplit " , t_nsplit ; ]
module Ext_pointer_to_untagged_int : sig type t val create : int -> t val read : t -> int val write : t -> int -> unit type t = P . t external alloc : int -> int = " external_untagged_int_ref " let create init_val = P . create ( alloc init_val ) let read t = P . load_untagged_int t let write t i = P . store_untagged_in...
module Ext_pointer_to_unboxed_float : sig type t val create : float -> t val read : t -> float val write : t -> float -> unit type t = P . t external alloc : float -> int = " external_unboxed_float_ref " let create init_val = P . create ( alloc init_val ) let read t = P . load_unboxed_float t let write t f = P . store_...
let test_int n = let ir = Ext_pointer_to_untagged_int . create n in let n ' = Ext_pointer_to_untagged_int . read ir in printf " ext_pointer int : read % d = % d \ n " n n ' ; let k = n + 1 in Ext_pointer_to_untagged_int . write ir k ; let k ' = Ext_pointer_to_untagged_int . read ir in printf " ext_pointer int : read % ...
let test_float n = let ir = Ext_pointer_to_unboxed_float . create n in let n ' = Ext_pointer_to_unboxed_float . read ir in printf " ext_pointer float : read % f = % f \ n " n n ' ; let k = n . * 13 . 0 in Ext_pointer_to_unboxed_float . write ir k ; let k ' = Ext_pointer_to_unboxed_float . read ir in printf " ext_pointe...
module BI = struct include Base . Int type t = int [ @@ deriving quickcheck ] end
module _ = struct external alloc : int -> int = " external_immediate_ref " let create_immediate n = P . create ( alloc n ) let direct_test_immediate n = let ir = create_immediate n in let n ' = P . Int . unsafe_load_immediate ir in printf " native_pointer int : read % d = % d \ n " n n ' ; let k = n + 1 in P . Int . st...
module _ = struct let % test_unit " ext_pointer int quickcheck " = Base_quickcheck . Test . run_exn ( module BI ) ~ f ( : fun n -> let expect = n , n + 1 in let actual = test_int n in [ % test_result : Int . t * Int . t ] ~ expect actual ) ; ; type t = int [ @@ deriving quickcheck ] end
module _ = struct module BF = struct include Base . Float type t = float [ @@ deriving quickcheck ] end let % test_unit " ext_pointer float quickcheck " = Base_quickcheck . Test . run_exn ( module BF ) ~ f ( : fun n -> let expect = n , n . * 13 . 0 in let actual = test_float n in [ % test_result : Float . t * Float . t...
module _ = struct external alloc : int64 -> int = " external_unboxed_int64_ref " let create_unboxed_int64 n = P . create ( alloc n ) let direct_test_unboxed_int64 n = let ir = create_unboxed_int64 n in let n ' = P . load_unboxed_int64 ir in printf " native_pointer float : read % Ld = % Ld \ n " n n ' ; let k = Int64 . ...
module _ = struct external alloc : int32 -> int = " external_unboxed_int32_ref " let create_unboxed_int32 n = P . create ( alloc n ) let direct_test_unboxed_int32 n = let ir = create_unboxed_int32 n in let n ' = P . load_unboxed_int32 ir in printf " native_pointer float : read % ld = % ld \ n " n n ' ; let k = Int32 . ...
module _ = struct external alloc : nativeint -> int = " external_unboxed_nativeint_ref " let create_unboxed_nativeint n = P . create ( alloc n ) let direct_test_unboxed_nativeint n = let ir = create_unboxed_nativeint n in let n ' = P . load_unboxed_nativeint ir in printf " native_pointer float : read % nd = % nd \ n " ...
print_s [ % sexp ( font_family_list ( ) : string list ) ] ; [ % expect { | ( ) } ] ; | return ( ) ; ;
let customization_group = Customization . Group . defgroup " test - group " [ % here ] ~ docstring " : A test customization group " ~ parents [ ] : ; ;
let some_attribute_value ( type a ) ( attribute : a Attribute . t ) : a option = let open Attribute in match attribute with | Background -> Some ( Color Color . red ) | Box -> None | Font -> None | Font_family -> Some ( Name " family " ) | Font_foundry -> Some ( Name " foundry " ) | Foreground -> Some ( Color Color . r...
let register_one_contract ( ) = Context . init 1 >>=? fun ( b , contracts ) -> let contract = List . nth contracts 0 |> WithExceptions . Option . get ~ loc : __LOC__ in return ( b , contract )
let failing_noop_must_fail_when_injected ( ) = register_one_contract ( ) >>=? fun ( blk , contract ) -> Contract . is_implicit contract |> function | None -> Alcotest . fail " only implicit accounts can sign " | Some source -> Op . failing_noop ( B blk ) source " tezos " >>=? fun operation -> Block . bake ~ operation b...
let tests = [ Tztest . tztest " injection fails " ` Quick failing_noop_must_fail_when_injected ]
module Q = struct open Caqti_request . Infix open Caqti_type . Std let select_two = unit -->! int @:- " SELECT 2 " let select_twice = int -->! int @:- " SELECT 2 * " ? let sleep = unit -->! option int @@:- function | ` Pgsql -> " SELECT pg_sleep ( 2 ) " | _ -> " SELECT sleep ( 2 ) " end
module Make ( Ground : Testlib . Sig . Ground ) = struct open Ground let test_raise_in_call fail ' ( module Db : Caqti_sys . CONNECTION ) = let test i = catch ( fun ( ) -> Db . call ~ f ( : fun _ -> fail ' Not_found ) Q . select_two ( ) >|= fun _ -> assert false ) ( function | Not_found -> return ( ) | exn -> failwith ...
params |> map ( fun [ { ty_expr ; _ } -> ty_expr ] ) |> apply ( of_str cons ) ; params |> map ( fun [ { ty_expr ; _ } -> ty_expr ] ) |> tuple_of_list ; cols |> map ( fun [ { record_label ; record_info { = ty_expr ; _ } ; _ } -> ( record_label , ty_expr ) ] ) |> mk_record ; fun [ ( _ , 1 ) -> <: match_case < >> ( | _ , ...
module M = Fan_frame . Make ( struct value mk_variant = mk_variant ; value mk_record = mk_record ; value mk_tuple = mk_tuple ; value var = ` Pre " mf_ " ; value arity = 2 ; value right_var = ` Exp ( fun [ v -> let v = basic_transform var v in <: expr < . $ lid : v . $ self >> ] ) ; value tctor_var = ` Fun ( fun x -> x ...
module Operation = struct type t = [ ` Writev of Bigstringaf . t iovec list | ` Yield | ` Close ] let pp_hum fmt t = match t with | ` Yield -> Format . pp_print_string fmt " Yield " | ` Close -> Format . pp_print_string fmt " Close " | ` Writev iovecs -> let writev_len = List . length iovecs in Format . pp_print_string...
module Flushed_reason = struct type t = Flushed_reason . t let pp_hum fmt ( t : t ) = match t with | Shift -> Format . pp_print_string fmt " Shift " | Drain -> Format . pp_print_string fmt " Drain " | Nothing_pending -> Format . pp_print_string fmt " Nothing_pending " let equal ( t : t ) ( t ' : t ) = match t , t ' wit...
module Alcotest = struct include Alcotest let operation : Operation . t testable = testable Operation . pp_hum Operation . equal let flush_reason : Flushed_reason . t testable = testable Flushed_reason . pp_hum Flushed_reason . equal end
let test ( ? buf_size = 0x100 ) f = let t = create buf_size in f t ; operation t ; ;
let noop ( ) = Alcotest . ( check operation ) " noop " ` Yield ( test ignore ) ; ; ;
let yield ( ) = Alcotest . ( check operation ) " yield " ` Yield ( test yield ) ; ;
let empty_writes ( ) = Alcotest . ( check operation ) " empty string " ` Yield ( test ( fun t -> write_string t " " ) ) ; Alcotest . ( check operation ) " empty bytes " ` Yield ( test ( fun t -> write_bytes t ( Bytes . make 0 ' \ 000 ' ) ) ) ; Alcotest . ( check operation ) " empty bigstring " ` Yield ( test ( fun t ->...
let empty_schedule ( ) = Alcotest . ( check operation ) " empty schedule " ` Yield ( test ( fun t -> schedule_bigstring t ( Bigstringaf . create 0 ) ) ) ; ; ;
let empty = [ " noop " , ` Quick , noop ; " yield " , ` Quick , yield ; " empty writes " , ` Quick , empty_writes ; " empty schedule " , ` Quick , empty_schedule ] ; ;
let endianness ( ) = Alcotest . ( check operation ) " unit16 le " ( Operation . writev [ " \ 005 \ 000 " ] ) ( test ( fun t -> LE . write_uint16 t 5 ) ) ; Alcotest . ( check operation ) " unit16 be " ( Operation . writev [ " \ 000 \ 005 " ] ) ( test ( fun t -> BE . write_uint16 t 5 ) ) ; ; ;
let endian = [ " endian " , ` Quick , endianness ]
let write ? buf_size ( ) = let check msg f = Alcotest . ( check operation ) msg ( Operation . writev [ " test " ] ) ( test ? buf_size f ) in check " string " ( fun t -> write_string t " test " ) ; check " bytes " ( fun t -> write_bytes t ( Bytes . of_string " test " ) ) ; check " bigstring " ( fun t -> write_bigstring ...
let char ( ) = Alcotest . ( check operation ) " char " ( Operation . writev [ " A " ] ) ( test ( fun t -> write_char t ' A ' ) ) ; ; ;
let write_multiple ( ) = let f t = write_string t " te " ; write_string t " st " ; write_string t " te " ; write_string t " st " ; write_char t ' t ' ; write_char t ' e ' in Alcotest . ( check operation ) " with room " ( Operation . writev [ " testtestte " ] ) ( test f ) ; Alcotest . ( check operation ) " with room " (...
let write = [ " char " , ` Quick , char ; " single w / room " , ` Quick , ( write : unit -> unit ) ; " single w / o room " , ` Quick , write ~ buf_size : 1 ; " multiple " , ` Quick , write_multiple ]
let schedule ( ) = let check msg f = Alcotest . ( check operation ) msg ( Operation . writev [ " one " ; " two " ] ) ( test f ) in check " schedule first " ( fun t -> schedule_bigstring t ( Bigstringaf . of_string ~ off : 0 ~ len : 3 " one " ) ; write_string t " two " ) ; check " schedule last " ( fun t -> write_string...
let schedule = [ " single " , ` Quick , schedule ]
let rec cross xs ys = match xs with | [ ] -> [ ] | x :: xs ' -> List . ( map ( fun y -> [ x ; y ] ) ys ) @ ( cross xs ' ys )
let string_of_bigstring b = Bigstringaf . substring ~ off : 0 ~ len ( : Bigstringaf . length b ) b
let serialize_to_bigstring ' t = serialize_to_bigstring t |> string_of_bigstring
let check ( ? buf_size = 0x100 ) ( ? serialize = serialize_to_string ) ~ iovecs ~ msg ops result = let bigstring_of_string str = Bigstringaf . of_string ~ off : 0 ~ len ( : String . length str ) str in let t = create buf_size in List . iter ( function | ` Write_le i -> LE . write_uint16 t i | ` Write_be i -> BE . write...
let interleaved serialize = [ " write_then_schedule " , ` Quick , begin fun ( ) -> List . iteri ( fun i ops -> check ~ iovecs : 2 ~ serialize ~ msg ( : Printf . sprintf " write_then_schedule : % d " i ) ops " test " ) ( cross [ ` Write_string " te " ; ` Write_bytes " te " ; ` Write_bigstring " te " ] [ ` Schedule_bigst...
let test_flush ( ) = let t = create 0x100 in let set_up_flush ( ) = let flush_reason = ref None in flush_with_reason t ( fun reason -> flush_reason := Some reason ) ; flush_reason in let flush_reason = set_up_flush ( ) in Alcotest . ( check ( option flush_reason ) ) " flushes resolved immediately if no waiting bytes " ...
let flush = [ " flush " , ` Quick , test_flush ]
let ( ) = Alcotest . run " test suite " [ " empty output " , empty ; " endianness " , endian ; " write " , write ; " single schedule " , schedule ; " interleaved calls ( string ) " , interleaved serialize_to_string ; " interleaved calls ( bigstring ) " , interleaved serialize_to_bigstring ' ; " flush " , flush ]
let dbg fmt = eprintf ( " DBG : " ^^ fmt ^^ " \ n ) " %!