text
stringlengths
0
601k
let int = Observer . int test_observer Observer . int ( m_int ( module Int ) ) ; [ % expect { | ( observer transparent ) } ] | ; ;
let int32 = Observer . int32 test_observer Observer . int32 ( m_int ( module Int32 ) ) ; [ % expect { | ( observer transparent ) } ] | ; ;
let int63 = Observer . int63 test_observer Observer . int63 ( m_int ( module Int63 ) ) ; [ % expect { | ( observer transparent ) } ] | ; ;
let int64 = Observer . int64 test_observer Observer . int64 ( m_int ( module Int64 ) ) ; [ % expect { | ( observer transparent ) } ] | ; ;
let nativeint = Observer . nativeint test_observer Observer . nativeint ( m_int ( module Nativeint ) ) ; [ % expect { | ( observer transparent ) } ] | ; ;
let float = Observer . float test_observer Observer . float m_float ; [ % expect { | ( observer transparent ) } ] | ; ;
let sexp = Observer . sexp test_observer Observer . sexp m_sexp ; [ % expect { | ( observer transparent ) } ] | ; ;
let option = Observer . option [ % expect { | } ] ; | test_observer ( Observer . option Observer . bool ) ( m_option m_bool ) ; [ % expect { | ( observer transparent ) } ] | ; ;
let list = Observer . list test_observer ( Observer . list Observer . bool ) ( m_list m_bool ) ; [ % expect { | ( observer transparent ) } ] | ; ;
let either = Observer . either test_observer ( Observer . either Observer . bool Observer . bool ) ( m_either m_bool m_bool ) ; [ % expect { | ( observer transparent ) } ] | ; ;
let result = Observer . result test_observer ( Observer . result Observer . bool Observer . bool ) ( m_result m_bool m_bool ) ; [ % expect { | ( observer transparent ) } ] | ; ;
let map_tree = Observer . map_tree test_observer ( Observer . map_t Observer . bool Observer . bool ) ( m_map ( module Bool ) m_bool m_bool ) ; [ % expect { | ( observer transparent ) } ] | ; ;
let set_tree = Observer . set_tree test_observer ( Observer . set_t Observer . bool ) ( m_set ( module Bool ) m_bool ) ; [ % expect { | ( observer transparent ) } ] | ; ;
let of_lazy = Observer . of_lazy test_observer ( Observer . of_lazy ( lazy Observer . string ) ) m_string ; [ % expect { | ( observer transparent ) } ] | ; ; test_observer ( Observer . either Observer . string ( Observer . of_lazy ( lazy ( assert false ) ) ) ) ( m_biject m_string ~ f ( : fun string -> Either . First st...
let bigstring = Observer . bigstring test_observer Observer . bigstring ( m_biject m_string ~ f : Base_bigstring . of_string ~ f_inverse : Base_bigstring . to_string ) ; [ % expect { | ( observer transparent ) } ] | ; ;
let float64_vec = Observer . float64_vec let test observer kind = ( module struct include ( val m_float ) let examples = [ 1 . ; - 1 . ; Float . nan ] end ) |> m_list |> m_biject ~ f : Array . of_list ~ f_inverse : Array . to_list |> m_biject ~ f ( : Bigarray . Array1 . of_array kind Fortran_layout ) ~ f_inverse : Priv...
let float64_mat = Observer . float64_mat let test observer kind = ( module struct type t = float array array [ @@ deriving compare , sexp_of ] let examples = [ [ ] ; || [ | [ | 0 . ] | ] ; | [ | [ | 0 . ; 1 . ] | ] ; | [ | [ | 0 . ] ; | [ | 1 . ] | ] | ] ; ; end ) |> m_biject ~ f ( : Bigarray . Array2 . of_array kind F...
let report symbol ( ) = print_s [ % message " Called " ( symbol : Symbol . t ) ]
let alias_of = let symbol = " current - function " |> Symbol . intern in defun_nullary_nil symbol [ % here ] ~ docstring " :< docstring " > ( report symbol ) ; symbol ; ; let obsolete = " foobar - 2 " |> Symbol . intern in defun_nullary_nil obsolete [ % here ] ~ docstring " : _ " ~ interactive : No_arg ( report obsolet...
module Common_tests ( S : Cstubs . FOREIGN with type ' a result = ' a and type ' a return = ' a ) = struct module M = Functions . Stubs ( S ) open M let test_oo_hierarchy _ = let module M = struct let camel_vtable_singleton = make camel_methods let idfn = ( fun animal -> let n = call_humps ( cast camel animal ) in Prin...
let suite = " OO - style tests " >::: [ " OO style ( foreign ) " >:: Foreign_tests . test_oo_hierarchy ; " OO style ( stubs ) " >:: Stub_tests . test_oo_hierarchy ; ]
let _ = run_test_tt_main suite
let gpu_to_gray = kern v -> let open Std in let tid = thread_idx_x + block_dim_x * block_idx_x in let tab = make_local 32 in let tab2 = make_shared 32 in tab2 . ( 0 ) <- tab . ( 0 ) + v . [ < 0 ] ; > if tid <= ( 512 * 512 ) then ( let i = ( tid * 4 ) in let res = int_of_float ( ( 0 . 21 . * ( float ( v . [ < i ] ) ) ) ...
let append_text e s = Dom . appendChild e ( document ## createTextNode ( Js . string s ) )
let button name action = let b = createInput ~ _type ( : Js . string " button " ) document in b ## value <- ( Js . string name ) ; b ## onclick <- handler action ; b ## style ## margin <- Js . string " 10px " ; b
let measure_time s f = let t0 = Unix . gettimeofday ( ) in let a = f ( ) in let t1 = Unix . gettimeofday ( ) in Printf . printf " Time % s : % Fs \ n " %! s ( t1 . - t0 ) ; a ; ;
let compute devid devs data imageData c tf = let dev = devs . ( devid ) in Printf . printf " Will use device : % s " ! ( dev ) . Spoc . Devices . general_info . Spoc . Devices . name ; let gpu_vect = Spoc . Vector . create Vector . int32 ( 512 * 512 * 4 ) in let s = Printf . sprintf " % s " ( Js . to_string tf ## value...
let f select_devices devs data imageData c tf = ( fun _ -> let select = select_devices ## selectedIndex + 0 in compute select devs data imageData c tf ; Js . _false ) ; ;
let newLine _ = Dom_html . createBr document
let nodeJsText t = let sp = Dom_html . createSpan document in Dom . appendChild sp ( document ## createTextNode ( t ) ) ; sp
let nodeText t = nodeJsText ( Js . string t )
let go _ = let body = Js . Opt . get ( document ## getElementById ( Js . string " section1 " ) ) ( fun ( ) -> assert false ) in Dom . appendChild body ( newLine ( ) ) ; let select_devices = createSelect document in Dom . appendChild body ( nodeText " Choose a computing device : " ) ; Dom . appendChild body select_devic...
let _ = window ## onload <- handler go
module Test_operation_repr = struct open Operation_repr let test_of_list_single_case ( ) = Environment . wrap_tzresult @@ of_list [ Contents ( Manager_operation { fee = Obj . magic 0 ; operation = Obj . magic 0 ; gas_limit = Obj . magic 0 ; storage_limit = Obj . magic 0 ; counter = Obj . magic 0 ; source = Obj . magic ...
let tests = [ tztest " of_list : single element input list " ` Quick Test_operation_repr . test_of_list_single_case ; tztest " of_list : multiple element input list " ` Quick Test_operation_repr . test_of_list_multiple_case ; tztest " of_list : empty input list " ` Quick Test_operation_repr . test_of_list_empty_case ; ...
type assoc = | Left | Right
type info = { precedence : int ; associativity : assoc ; }
let left ( p : int ) : info = assert ( 0 <= p ) ; { precedence = p ; associativity = Left ; }
let right ( p : int ) : info = assert ( 0 <= p ) ; { precedence = p ; associativity = Right ; }
module Map = struct include Btree . Map ( Char ) let find c map = match find_opt c map with | None -> assert false | Some r -> r end
let operators : string = " " +-*/^!&|
let map : ' info Map . t = let open Map in empty |> add ' ' | ( left 10 ) |> add ' ' & ( left 20 ) |> add ' ' ! ( left 30 ) |> add ' ' + ( left 40 ) |> add ' ' - ( left 40 ) |> add ' ' * ( left 50 ) |> add ' ' / ( left 50 ) |> add ' ' ^ ( right 60 )
let is_left0 ( o1 : char ) ( o2 : char ) : bool = let i1 = Map . find o1 map and i2 = Map . find o2 map in i1 . precedence > i2 . precedence || ( i1 . precedence = i2 . precedence && i1 . associativity = Left )
module CP = Character . Make ( Unit ) ( String ) ( String )
let is_left ( a : char ) ( b : char ) : bool t = return ( is_left0 a b )
let operator : char t = one_of_chars operators ( " one of " " \ ^ operators ^ " " " ) \
let make_unary ( u : char ) ( a : string ) : string t = return ( " ( " ^ String . one u ^ a ^ " ) " )
let make_binary ( a : string ) ( o : char ) ( b : string ) : string t = return ( " ( " ^ a ^ String . one o ^ b ^ " ) " )
let primary : string t = map String . one letter
let lpar : char t = ( let * _ = char ' ( ' in return ' ) ' ) </> ( let * _ = char ' [ ' in return ' ] ' ) </> ( let * _ = char ' { ' in return ' } ' )
let rpar ( p : char ) : char t = charp ( fun c -> c = p ) ( " ' " ^ String . one p ^ " ' " )
let rec exp ( ) : string t = let prim ( ) = parenthesized ( fun _ a _ -> return a ) lpar exp rpar </> primary in operator_expression ( prim ( ) ) ( Some operator ) operator is_left make_unary make_binary
let parse : Parser . t = make ( ) ( exp ( ) ) let p = Parser . run_on_string " a " parse in Parser . ( has_succeeded p && column p = 1 && final p = " a " ) let p = Parser . run_on_string " a +- b + c " parse in Parser . ( has_succeeded p && final p = " ( ( a ( +- b ) ) + c ) " ) let p = Parser . run_on_string " a + b *...
( module struct open For_testing . Unsafe_cheap_option let roundtrip_via_cheap_option ( type a ) ( x : a ) = let opt : a t = some x in assert ( is_some opt ) ; assert ( phys_equal ( value_exn opt ) x ) ; ; let % test_unit _ = roundtrip_via_cheap_option 0 let % test_unit _ = roundtrip_via_cheap_option 1 let % test_unit ...
module Sequence = struct let length = length let get = get let set = set end ( struct include Option let equal a b = Option . equal Bool . equal a b let of_bool b = Some b end ) ( struct type nonrec ' a t = ' a t [ @@ deriving sexp ] type ' a z = ' a include Sequence let create_bool ~ len = init_some len ~ f ( : fun _ ...
module X = struct type t = [ ` x6e8ee3478e1d7449 | ` some_other_value ] [ @@ deriving sexp_of ] let magic_value : t = ` x6e8ee3478e1d7449 let some_other_value : t = ` some_other_value let % expect_test _ = assert ( phys_equal magic_value ( Caml . Obj . magic For_testing . Unsafe_cheap_option . none : t ) ) ; ; end let ...
let print_expr expr = Pprintast . string_of_structure [ % str let ( ) = [ % e expr ] ] |> print_string ; ; Ppx_let_expander . expand ~ modul : None Mapn [ % expr let MY_PAT = MY_EXPR in MY_BODY ] |> print_expr ; [ % expect { | let ( ) = Let_syntax . map MY_EXPR ~ f ( : fun ( MY_PAT ) -> MY_BODY ) } ] | ; ; Ppx_let_expa...
let random_action ( ) = match Random . int 8 with | 0 -> ` Before | 1 -> ` After | 2 -> ` Forget | 3 -> ` Replace_before | 4 -> ` Replace_after | 5 | 6 | 7 -> ` None | _ -> assert false
module type S = module type of Order_indir
module Test ( M : S ) = struct let apply gc acc x = function | ` None -> x :: acc | ` Before -> x :: M . before x :: acc | ` After -> M . after x :: x :: acc | ` Replace_before -> if gc then M . before x :: acc else begin let result = M . before x in M . forget x ; result :: acc end | ` Replace_after -> if gc then M . ...
let t ( ) = ( Unix . times ( ) ) . Unix . tms_utime
let once ? gc ? check ~ pass state name ( module M : S ) = let module M = Test ( M ) in Random . set_state state ; Gc . major ( ) ; Gc . major ( ) ; let t0 = t ( ) in M . test ? gc ? check name pass ; let dt = t ( ) . - t0 in Printf . printf " % s check time : . % 02f \ n " name dt
let ( ) = let ( ) = Random . self_init ( ) in let state = Random . get_state ( ) in let pass = try int_of_string ( Sys . argv . ( 1 ) ) with _ -> 80 in once state " Order_list " ( module Order_list ) ~ pass ~ check : false ~ gc : false ; once state " Order_managed_list " ( module Order_managed ) ~ pass ~ check : false ...
let n_vals = [ 0 ; 1 ; 2 ; 10 ; 100 ; ( Int . max_value / 2 ) - 2 ; ( Int . max_value / 2 ) - 1 ; Int . max_value / 2 ; Int . max_value - 2 ; Int . max_value - 1 ; Int . max_value ] in let z_vals = [ Int . min_value ; Int . min_value + 1 ; Int . min_value + 2 ; Int . min_value / 2 ; ( Int . min_value / 2 ) + 1 ; ( Int ...
let test = function | Sexp . Private . Raw_grammar . Ref ( _ , group ) -> print_endline group . origin | Inline _ -> print_cr [ % here ] ( Atom " Unexpected [ Inline ] " ) ; ;
type t = unit [ @@ deriving sexp_grammar ]
let extension_node = [ % sexp_grammar : int ] test t_sexp_grammar ; [ % expect { | test_origin . ml } ] ; | test extension_node ; [ % expect { | test_origin . ml } ] | ; ;
module Foo = struct type t = unit [ @@ deriving sexp_grammar ] let extension_node = [ % sexp_grammar : unit ] end test Foo . t_sexp_grammar ; [ % expect { | test_origin . ml . Foo } ] ; | test Foo . extension_node ; [ % expect { | test_origin . ml . Foo } ] | ; ;
module F ( M : sig type t [ @@ deriving sexp_grammar ] end ) = struct type t = M . t [ @@ deriving sexp_grammar ] let extension_node = [ % sexp_grammar : M . t ] end
module F_foo = F ( Foo ) test F_foo . t_sexp_grammar ; [ % expect { | test_origin . ml . F } ] ; | test F_foo . extension_node ; [ % expect { | test_origin . ml . F } ] | ; ;
let m__t_sexp_grammar , m__extension_node = let module M = struct type t = unit [ @@ deriving sexp_grammar ] let extension_node = [ % sexp_grammar : unit ] end in M . t_sexp_grammar , M . extension_node ; ; test m__t_sexp_grammar ; [ % expect { | test_origin . ml } ] ; | test m__extension_node ; [ % expect { | test_ori...
let ten_tez = of_int 10
let total_fees_for_origination ( ? fee = Tez . zero ) ( ? credit = Tez . zero ) b = Context . get_constants ( B b ) >>=? fun { parametric = { origination_size ; cost_per_byte ; _ } ; _ } -> cost_per_byte *? Int64 . of_int origination_size >>?= fun origination_burn -> credit +? fee >>? ( +? ) origination_burn >>? ( +? )...
let test_origination_balances ~ loc : _ ( ? fee = Tez . zero ) ( ? credit = Tez . zero ) ( ) = Context . init 2 >>=? fun ( b , contracts ) -> let source = WithExceptions . Option . get ~ loc : __LOC__ @@ List . hd contracts in let contract_for_bake = WithExceptions . Option . get ~ loc : __LOC__ @@ List . nth contracts...
let register_origination ( ? fee = Tez . zero ) ( ? credit = Tez . zero ) ( ) = Context . init 2 >>=? fun ( b , contracts ) -> let source = WithExceptions . Option . get ~ loc : __LOC__ @@ List . hd contracts in let contract_for_bake = WithExceptions . Option . get ~ loc : __LOC__ @@ List . nth contracts 1 in Context ....
let test_balances_simple ( ) = test_origination_balances ~ loc : __LOC__ ( )
let test_balances_credit ( ) = test_origination_balances ~ loc : __LOC__ ~ credit : ten_tez ( )
let test_balances_credit_fee ( ) = test_origination_balances ~ loc : __LOC__ ~ credit ( : of_int 2 ) ~ fee : ten_tez ( )
let test_pay_fee ( ) = register_origination ~ credit ( : of_int 2 ) ~ fee : ten_tez ( ) >>=? fun ( _b , _contract , _new_contract ) -> return_unit
let test_not_tez_in_contract_to_pay_fee ( ) = Context . init 2 >>=? fun ( b , contracts ) -> let contract_1 = WithExceptions . Option . get ~ loc : __LOC__ @@ List . nth contracts 0 in let contract_2 = WithExceptions . Option . get ~ loc : __LOC__ @@ List . nth contracts 1 in Incremental . begin_construction b >>=? fun...
let register_contract_get_endorser ( ) = Context . init 1 >>=? fun ( b , contracts ) -> let contract = WithExceptions . Option . get ~ loc : __LOC__ @@ List . hd contracts in Incremental . begin_construction b >>=? fun inc -> Context . get_endorser ( I inc ) >|=? fun ( account_endorser , _slots ) -> ( inc , contract , ...
let n_originations n ? credit ? fee ( ) = List . fold_left_es ( fun new_contracts _ -> register_origination ? fee ? credit ( ) >|=? fun ( _b , _source , new_contract ) -> new_contract :: new_contracts ) [ ] ( 1 -- n )
let test_multiple_originations ( ) = n_originations 100 ~ credit ( : of_int 2 ) ~ fee : ten_tez ( ) >>=? fun contracts -> Assert . equal_int ~ loc : __LOC__ ( List . length contracts ) 100
let test_counter ( ) = Context . init 1 >>=? fun ( b , contracts ) -> let contract = WithExceptions . Option . get ~ loc : __LOC__ @@ List . hd contracts in Incremental . begin_construction b >>=? fun inc -> Op . contract_origination ( I inc ) ~ credit : Tez . one contract ~ script : Op . dummy_script >>=? fun ( op1 , ...
let tests = [ Tztest . tztest " balances_simple " ` Quick test_balances_simple ; Tztest . tztest " balances_credit " ` Quick test_balances_credit ; Tztest . tztest " balances_credit_fee " ` Quick test_balances_credit_fee ; Tztest . tztest " pay_fee " ` Quick test_pay_fee ; Tztest . tztest " not enough tez in contract t...
let eqb = eq_result_msg ~ eq_ok ( ) := ~ pp_ok : pp_bool
let eqs = eq_result_msg ~ eq_ok ( ) := ~ pp_ok : pp_str
let equ = eq_result_msg ~ eq_ok ( ) := ~ pp_ok : pp_unit
let eql = eq_result_msg ~ eq_ok ( ) := ~ pp_ok ( : pp_list pp_str )
let cat = Cmd . ( v " cat " )
let cat_stdin = Cmd . ( cat % " " ) -
let unlikely = Cmd . v " 6AC0E501 - 4E30 - 4CBC - AD03 - F880F885BC18 "
let exists = test " OS . Cmd . exists " @@ fun ( ) -> eqb ( OS . Cmd . exists cat ) ( Ok true ) ; eqb ( OS . Cmd . exists unlikely ) ( Ok false ) ; ( )
let must_exist = test " OS . Cmd . must_exist " @@ fun ( ) -> begin match ( OS . Cmd . must_exist cat ) with | Error ( ` Msg err ) -> fail " % s " err | Ok _ -> ( ) end ; begin match ( OS . Cmd . must_exist unlikely ) with | Ok _ -> fail " % a exists " Cmd . dump unlikely | Error _ -> ( ) end ; ( )
let run_io = test " OS . Cmd . run_io " @@ fun ( ) -> let in_hey = OS . Cmd . in_string " hey " in let tmp ( ) = OS . File . tmp " bos_test_ % s " in eqs OS . Cmd . ( in_hey |> run_io cat_stdin |> to_string ) ( Ok " hey " ) ; eql OS . Cmd . ( in_string " hey \ nho \ n " |> run_io cat_stdin |> to_lines ) ( Ok [ " hey " ...
let suite = suite " OS command run functions " [ exists ; run_io ; ]
let with_buffer f = let buffer = Buffer . create ~ name " : test - buffer " in Current_buffer . set_temporarily Sync buffer ~ f ( : fun ( ) -> Point . insert { | Lorem ipsum dolor sit amet , consectetur adipiscing elit , sed doeiusmod tempor incididunt ut labore et dolore magna aliqua . } ; | f buffer ) ; ;
let count_at s position = print_s [ % message " at " s ~ _ ( : List . length ( at position ) : int ) ]
let count_in s ~ start ~ end_ = print_s [ % message " in " s ~ _ ( : List . length ( in_ ~ start ~ end_ ) : int ) ] ; ;
let num_overlays_in_buffer ( ) = print_s [ % sexp ( List . length ( in_ ~ start ( : Point . min ( ) ) ~ end_ ( : Point . max ( ) ) ) : int ) ] ; ; with_buffer ( fun buffer -> let count_overlays ( ) = count_at " point min " ( Point . min ( ) ) ; count_in " buffer " ~ start ( : Point . min ( ) ) ~ end_ ( : Point . max ( ...