text stringlengths 12 786k |
|---|
let test_read_int8 ( ) = let res str = match get_data ( Test . StringMonad . getdata ( enum_1chunk str read_int8 ) ) with | Some x -> x | None -> 0 in assert_equal 97 ( res " a " ) ; assert_equal 65 ( res " A " ) ; assert_equal 125 ( res " } " ) |
let test_peek ( ) = let res str = match get_data ( Test . StringMonad . getdata ( enum_1chunk str peek ) ) with | Some x -> ( match x with Some c -> c | None -> ' g ' ) | None -> ' g ' in assert_equal ' a ' ( res " abc " ) ; assert_equal ' x ' ( res " xyz " )... |
let test_head ( ) = let res str = match get_data ( Test . StringMonad . getdata ( enum_1chunk str head ) ) with | Some x -> ( match x with Some c -> c | None -> ' g ' ) | None -> ' g ' in assert_equal ' a ' ( res " abc " ) ; assert_equal ' x ' ( res " xyz " )... |
let test_break ( ) = let alter = function ' \ n ' -> true | _ -> false in let res str = match get_data ( Test . StringMonad . getdata ( enum_1chunk str ( break alter ) ) ) with | Some x -> x | None -> " xxxxx " in assert_equal " " ( res " \ ntest " ) ; assert_equal... |
let test = " test_iteratees " >::: [ " test_heads " >:: test_heads ; " test_drop " >:: test_drop ; " test_readn " >:: test_readn ; " test_read_int8 " >:: test_read_int8 ; " test_peek " >:: test_peek ; " test_head " >:: test_head ; " test_break " >:: test_break ] |
let simple_iterator_test ( ) = Utils . with_tmp_dir begin fun name -> open_db ~ config : Options . default ~ name >>= fun db -> let write_options = Options . Write_options . create ( ) in let kvs = Utils . get_random_kvalues 1000 in List . fold_left begin fun r ( key , value ) -> r ... |
let simple_iterator_test_two_prefixes ( ) = Utils . with_tmp_dir begin fun name -> open_db ~ config : Options . default ~ name >>= fun db -> let write_options = Options . Write_options . create ( ) in let kvs = Utils . get_random_kvalues 1000 in List . fold_left begin fun r ( key , val... |
let tests = [ " simple_iterator_test " , simple_iterator_test ; " simple_iterator_test_two_prefixes " , simple_iterator_test_two_prefixes ; ] |
type op = | Output of string | Check of string | Submit |
let name = ref None |
let worker = ref None |
let pipe = ref [ ] |
let inputs = ref [ ] |
let op = ref None |
let save = ref false |
let parse_args ( ) = let options = Arg . align [ ( " - n " , Arg . String ( fun n -> name := Some n ) , " job name ( will be prefix of actual job ) " ) ; ( " - w " , Arg . String ( fun w -> worker := Some w ) , " path to executable to run " ) ; ( " ... |
let print_exception e = let msg = match e with | J . Jobpack_error je -> Printf . sprintf " bad jobpack : % s " ( J . string_of_error je ) | L . Pipeline_error pe -> Printf . sprintf " bad pipeline : % s " ( L . string_of_pipeline_error pe ) | J . Job_input_error ie -> Printf .... |
let get_user ( ) = try Unix . getlogin ( ) with _ -> ( Unix . getpwuid ( Unix . getuid ( ) ) ) . Unix . pw_name |
let save_jobpack ofile pack = let ofd = Unix . openfile ofile [ Unix . O_WRONLY ; Unix . O_CREAT ; Unix . O_TRUNC ] 0o640 in ignore ( Unix . write ofd pack 0 ( String . length pack ) ) ; Unix . close ofd ; Printf . printf " Jobpack of size % d saved in % s . \ n " ( St... |
let gen_jobpack name worker save = let owner = Printf . sprintf " % s @% s " ( get_user ( ) ) ( Unix . gethostname ( ) ) in let pipeline , inputs = ! pipe , ! inputs in ( ( J . make_jobpack ~ save ~ name ~ worker ~ owner ~ pipeline inputs ) :> string ) |
let show_pipeline p = Printf . printf " Pipeline " ; : List . iter ( fun ( s , g ) -> Printf . printf " -> % s ( % s ) " s ( L . string_of_grouping g ) ) p ; Printf . printf " \ n " |
let show_inputs i = Printf . printf " Inputs :\ n " ; List . iter ( fun ( l , s , urls ) -> Printf . printf " \ t % d % d [ " l s ; List . iter ( fun u -> Printf . printf " % s " ( Uri . to_string u ) ) urls ; Printf . printf " ] \ n " ) i |
let chk_jobpack file = let jobpack = U . contents_of_file file in let hdr = J . header_of jobpack in let jobdict = J . jobdict_of hdr jobpack in let open J in Printf . printf " % s contains job ' % s ' by ' % s ' running ' % s ' . \ n " file jobdict . name jobdict . owner jobdict ... |
let submit_jobpack ? cfg ? timeout pack = let url = Api . url_for_job_submit ( Cfg . safe_config cfg ) in let err_of e = Failure ( C . string_of_error e ) in match ( Api . payload_of_req ? timeout ( H . Post , C . Payload ( [ url ] , Some pack ) ) err_of ) with | U . Lef... |
let _ = try match parse_args ( ) with | ` Output ( o , n , w , s ) -> save_jobpack o ( gen_jobpack n w s ) | ` Check o -> chk_jobpack o | ` Submit ( n , w , s ) -> submit_jobpack ( gen_jobpack n w s ) with e -> print_exception e ; exit 1 |
let ( !! ) = Jquery . selector |
let block s ? text ( ? classes = [ ] ) ( ? ons = [ ] ) ( ? css = [ ] ) ( ? props = [ ] ) children = let element = Jquery . selector ( Printf . sprintf " <% s " > s ) s in begin match text with | None -> ( ) | Some text -> Jquery . set_text element text end ; ... |
let ajax_test ( ) = let open Ajax in let complete h = function | " success " -> let pre = block " pre " ~ text ( : response_text h ) h [ ] in hide pre ; append " !! body " [ pre ] pre ; fade_in pre ~ duration : 2000 ~ finished ( : fun ( ) -> fade_out pre ~ finished ( ... |
let on_ready ( ) = let main = " !!# main " in print_endline ( text main ) main ; set_text main " Hello world " ; ! append_html main " < b > in bold </ b " ; > let elts = " . !! tofill " in update_text elts ( Printf . sprintf [ " % i :% s ] s ) " ; append main [ elts ; !! " ... |
let ( ) = ready on_ready |
let ( . < ) = Function . Infix . ( . < ) ; ; describe " Functor " ( fun ( ) -> let module V = Verify . Functor ( Dict . Functor ) in property1 " should satisfy identity " ( arb_dict arb_nat ) V . identity ; property1 " should satisfy composition " ( arb_dict ... |
let ( . < ) , ( . > ) = let open Function . Infix in ( . < ) , ( . > ) ; ; describe " Functor " ( fun ( ) -> property1 " should satisfy identity " arb_nat ( fun n -> let module V = Verify . Compare . Functor ( Function . Functor ( struct type t = int ... |
type t = Jq_null | Jq_bool of bool | Jq_number of float | Jq_string of string | Jq_array of t list | Jq_object of ( string * t ) t list |
let ( . < ) = let open Function . Infix in ( . < ) |
module ComparePromise = struct type ' a t = ' a Js . Promise . t let eq a b = Js . Promise . then_ ( fun a ' -> Js . Promise . then_ ( fun b ' -> Js . Promise . resolve ( a ' = b ' ) ) b ) a |> Obj . magic end ; ; let promise a = Js . Promise . make ( fun ~ r... |
type ' a arbitrary = ' a BsJsverify . Verify . Arbitrary . arbitrary |
let ( . < ) , ( . > ) = let open Function . Infix in ( . < ) , ( . > ) |
let const , id = Function . const , Function . Category . id |
module Toggle = struct open Interface type toggle = | Off | On let to_bool x = match x with | On -> true | Off -> false let from_bool x = match x with | true -> On | false -> Off let and_ x y = match x , y with | On , On -> On | _ -> Off let or_ x y = match x , y with | Off , Off -> Off ... |
let arb_result = ( fun arb_ok arb_error -> smap ( fun e -> match e with | Types . Left l -> Error l | Types . Right r -> Ok r ) ( fun e -> match e with | Ok r -> Types . Right r | Error l -> Types . Left l ) ~ newShow ( : fun a -> match a with | Ok a ' -> " Ok ( " ^ ( Js ... |
let ( . < ) = Function . Infix . ( . < ) ; ; describe " Semigroup " ( fun ( ) -> let module S = Tuple . Semigroup ( String . Semigroup ) ( Int . Additive . Semigroup ) in let module V = Verify . Semigroup ( S ) in property3 " should satisfy associativity " (... |
let key_state id is_down = let kbd = El . kbd [ El . txt ( Jstr . v id ) ] in Elr . def_class ( Jstr . v " down " ) is_down kbd ; kbd |
let key_dir down up = let show_dir = El . span [ ] in let show d _ = [ El . txt ' ( match d with ` Up -> " " ↑ | ` Down -> " " ) ] ↓ in let dir = E . select [ E . map ( show ` Down ) down ; E . map ( show ` Up ) up ] in Elr . set_children show_dir ~ on ... |
let key_id ev = let kbd = El . kbd [ El . txt ' " " ] in let id e = [ El . txt ( Key . to_jstr e ) ] in Elr . set_children kbd ~ on ( : E . map id ev ) ; kbd |
let key_viz evs = El . div [ El . p [ key_id ( E . select [ Key . any_down evs ; Key . any_up evs ] ) ; key_dir ( Key . any_down evs ) ( Key . any_up evs ) ] ; El . p [ key_state " Any " ( Key . any_holds evs ) ] ; El . p [ key_state " Shift " ( Key... |
let main ( ) = let h1 = El . h1 [ El . txt ' " Keyboard test " ] in let info = El . p [ El . txt ' " Hit your keyboard . " ] in let body = Document . body G . document in El . set_children body [ h1 ; info ; key_viz ( Key . on_el body ) ] |
let ( ) = main ( ) |
let show t = print_s [ % sexp ( t : t ) ] |
let define_key t key entry = define_key t ( Key_sequence . create_exn key ) entry |
let lookup_key_exn t key = lookup_key t ( Key_sequence . create_exn key ) |> ok_exn |
let show_keys t keys = List . iter keys ~ f ( : fun key -> print_s [ % message " " ~ _ ( : key : string ) ~ _ ( : lookup_key_exn t key : Entry . t ) ] ) ; ; show_keys ( global ( ) ) [ " a " ; " C - c " ; " C - x C - a " ; " C - x C - f " ; ... |
let test_keys ( ) = let open Keys . Vector in List . iter ( fun v -> let ak = R . ask_to_ak v . ask in assert ( ak = v . ak ) ; let nk = R . nsk_to_nk v . nsk in assert ( nk = v . nk ) ; let ivk = R . crh_ivk ak nk in assert ( ivk = v . ivk ) ; let pkd = R . ivk_to... |
let test_vectors_zip32 ( ) = let open Keys in List . iter ( fun v -> let open Vk in ( match v . xsk with | Some xsk -> let xfvk = of_sk xsk in assert ( xfvk = v . xfvk ) | None -> ( ) ) ; let j0 = default_index in let j1 = index_succ j0 in let j2 = index_succ j1 in let jmax = R . ... |
let test_zip32 ( ) = let open Keys in let v = List . nth vectors_zip32 0 in let open Sk in let open Vk in let seed = Bytes . init 32 char_of_int in let xsk = of_seed seed in assert ( xsk . depth = ba_of_hex " 00 " ) ; assert ( xsk . parent_fvk_tag = ba_of_hex " 00000000 " ) ; a... |
let tests = [ ( " keys " , ` Quick , test_keys ) ; ( " vectors_zip32 " , ` Quick , test_vectors_zip32 ) ; ( " zip32 " , ` Quick , test_zip32 ) ; ] |
let ( ) = Alcotest . run " sapling " [ ( " keys " , tests ) ] |
List . iter [ " " ; " C - c y " ; " C - M - q " ; " < f5 " > ; " C -< f5 " > ; " C -< right " > ; " < mouse - 2 " > ; " C -< down - mouse - 3 " > ] ~ f ( : fun string -> print_s [ % message " " ~ _ ( : string : string ) ~ _ ( ... |
let print_am_executing ( ) = print_s [ % sexp ( Current_buffer . value_exn am_executing : bool ) ] print_am_executing ( ) ; [ % expect { | false } ] ; | return ( ) ; ; defun_nullary_nil ( " foo " |> Symbol . intern ) [ % here ] ~ docstring " :< docstring "... |
let exn = Failure " failure " |
let then_exn l = let s = of_list l in ( fun throw _ k -> next s throw ( fun ( ) -> throw exn ) k ) |> make |
let failed_wrong = wrong_k " failed " |
let failed = assert_equal exn |
let internal_tests = [ ( " kstream . internal . make " >:: fun _ -> let s = ( fun _ _ k -> k " foo " ) |> make in next s failed_wrong ( wrong_k " empty " ) ( assert_equal " foo " ) ) ; ( " kstream . internal . of_list , next " >:: fun _ -> let s = of_list... |
let synchronous_interface_tests = [ ( " kstream . sync . stream , next " >:: fun _ -> let emitted = ref false in let s = stream ( fun ( ) -> if not ! emitted then ( emitted := true ; Some " foo " ) else None ) in next s |> assert_equal ~ msg " : foo " ( Some " foo " ... |
let tests = internal_tests @ synchronous_interface_tests |
module Testable = struct open Mdx . Label let relation = Alcotest . testable Relation . pp ( = ) let msg = Alcotest . testable ( fun fmt ( ` Msg e ) -> Format . pp_print_string fmt e ) ( = ) let label = Alcotest . testable pp ( = ) end |
let test_raw_parse = let ty = Alcotest . ( pair string ( option ( pair Testable . relation string ) ) ) in let make_test ~ input ~ expected = let test_name = Printf . sprintf " raw_parse : % S " input in let test_fun ( ) = Alcotest . check ty test_name expected ( Mdx . Label . ... |
let test_interpret = let ty = Alcotest . result Testable . label Testable . msg in let make_test ~ label ~ value ~ expected = let test_name = Printf . sprintf " interpret : % S " label in let test_fun ( ) = Alcotest . check ty test_name expected ( Mdx . Label . interpret label value ) ... |
let test_of_string = let ty = Alcotest . ( result ( list Testable . label ) ( list Testable . msg ) ) in let make_test ~ input ~ expected = let test_name = Printf . sprintf " of_string : % S " input in let test_fun ( ) = Alcotest . check ty test_name expected ( Mdx . Label . ... |
let suite = ( " Label " , test_raw_parse @ test_interpret @ test_of_string ) |
let r = ref 0 in let t = return ( ) >>= fun ( ) -> Int . incr r ; return ( ) in assert ( ! r = 0 ) ; force t ; assert ( ! r = 1 ) ; force t ; assert ( ! r = 1 ) ; ; let r = ref 0 in let t = return ( ) >>= fun ( ) -> lazy ( Int . incr r ) in assert... |
let ids = [ | 1 ; 42 ; 1337 ; 1984 ] | |> Array . map Z . of_int |> Array . map Lazy_storage_kind . Big_map . Id . parse_z |
let strs = [ " | 0 " ; " True " ; " nat " ; " bool " ] | |
let exprs = strs |> Array . map Expr . from_string |
let hashes = strs |> Array . map ( fun x -> [ x ] ) |> Array . map Script_expr_hash . hash_string |
let updates_len_existing = [ 1 ; 2 ; 3 ] |
let updates_len_other = 0 :: updates_len_existing |
let gen_inits idx : ( ( Lazy_storage_kind . Big_map . Id . t , Lazy_storage_kind . Big_map . alloc ) Lazy_storage_diff . init * int list ) list = [ ( Existing , updates_len_existing ) ; ( Copy { src = ids . ( idx - 1 ) } , updates_len_other ) ; ( Alloc { key_t... |
let gen_update_list idx : Lazy_storage_kind . Big_map . update list = [ None ; Some exprs . ( idx ) ] |> List . map ( fun value -> Lazy_storage_kind . Big_map . { key = exprs . ( idx ) ; key_hash = hashes . ( idx ) ; value } ) |
let rec gen_updates updates_len : Lazy_storage_kind . Big_map . updates list = if updates_len = 0 then [ ] else gen_updates ( updates_len - 1 ) |> List . map ( fun suffix -> gen_update_list updates_len |> List . map ( fun prefix -> prefix :: suffix ) ) |> List . flatten |
let gen_updates_list updates_lens : Lazy_storage_kind . Big_map . updates list = updates_lens |> List . map gen_updates |> List . flatten |
let gen_diffs idx : ( Lazy_storage_kind . Big_map . Id . t , Lazy_storage_kind . Big_map . alloc , Lazy_storage_kind . Big_map . updates ) Lazy_storage_diff . diff list = let open Lazy_storage_diff in Remove :: ( gen_inits idx |> List . map ( fun ( init , updates_lens ) -> gen_u... |
let gen_diffs_items idx : Lazy_storage_diff . diffs_item list = let id = ids . ( idx ) in gen_diffs idx |> List . map ( fun diff -> Lazy_storage_diff . make Big_map id diff ) |
let rec gen_diffs_list len : Lazy_storage_diff . diffs list = if len = 0 then [ ] else gen_diffs_list ( len - 1 ) |> List . map ( fun suffix -> gen_diffs_items len |> List . map ( fun prefix -> prefix :: suffix ) ) |> List . flatten |
let diffs_list_lens = [ 0 ; 1 ; 2 ; 3 ] |
let diffs_list : Lazy_storage_diff . diffs list = diffs_list_lens |> List . map gen_diffs_list |> List . flatten |
let conversion_roundtrip lazy_storage_diff = let legacy_big_map_diff = Contract_storage . Legacy_big_map_diff . of_lazy_storage_diff lazy_storage_diff in let reconverted = Contract_storage . Legacy_big_map_diff . to_lazy_storage_diff legacy_big_map_diff in assert ( Stdlib . ( = ) reconverted lazy_st... |
let encoding_roundtrip lazy_storage_diff = let encoded = Data_encoding . Binary . to_bytes_exn Lazy_storage_diff . encoding lazy_storage_diff in match Data_encoding . Binary . of_bytes Lazy_storage_diff . encoding encoded with | Ok decoded -> assert ( Stdlib . ( = ) decoded lazy_storage_diff ) ... |
let on_diffs f ( ) = List . iter f diffs_list ; return_unit |
let tests = [ Tztest . tztest " conversion roundtrip " ` Slow ( on_diffs conversion_roundtrip ) ; Tztest . tztest " encoding roundtrip " ` Slow ( on_diffs encoding_roundtrip ) ; ] |
let scy_addr = Uint16 . of_int 0xFF42 |
let scx_addr = Uint16 . of_int 0xFF43 |
let ly_addr = Uint16 . of_int 0xFF44 |
let lyc_addr = Uint16 . of_int 0xFF45 |
let wy_addr = Uint16 . of_int 0xFF4A |
let wx_addr = Uint16 . of_int 0xFF4B |
let create ( ) = Lcd_position . create ~ scy_addr ~ scx_addr ~ ly_addr ~ lyc_addr ~ wy_addr ~ wx_addr let t = create ( ) in [ scy_addr ; scx_addr ; ly_addr ; lyc_addr ; wy_addr ; wx_addr ] |> List . map ( Lcd_position . read_byte t ) |> List . map Uint8 . show |> List . ... |
let addr = ( Uint16 . of_int 0xFF41 ) let t = Lcd_stat . create ~ addr in Lcd_stat . read_byte t addr |> Uint8 . show |> print_endline ; [ % expect { | $ 82 } ] | let t = Lcd_stat . create ~ addr in Gpu_mode . [ HBlank ; VBlank ; OAM_search ; Pixel_transfer ] |> List . ... |
let flts = [ 1 . 1234 ; - 94 . 1239823897423 ; 0 . 000000000000012 ; 0 . 12130981239081238973249872349871346123873264876324 ; - 3 . 92 ] |
let op1 f a = LDouble . ( to_float ( f ( of_float a ) ) ) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.