text
stringlengths
12
786k
let test_cachecontrol_concat ( ) = let resp = get_resp [ " Cache - Control : public " ; " Cache - Control : max - age : 86400 " ] in let h = headers_of_response " concat Cache - Control " resp in aeso " test_cachecontrol_concat " ( Some " public , max - age : 86400 " ) ...
let ( ) = Printexc . record_backtrace true
let ( ) = Alcotest . run " test_header " [ ( " Link " , [ ( " simple " , ` Quick , link_simple ) ; ( " multiple rels " , ` Quick , link_multi_rel ) ; ( " multiple lines " , ` Quick , link_multi_line ) ; ( " multiheader " , ` Quick , link...
let check msg ~ expect actual = Alcotest ( . check ( list ( pair string string ) string ) string ) string msg expect ( Headers . to_list actual ) actual ; ;
let test_replace ( ) = check " replace trailing element " ~ expect [ " : c " , " d " ; " a " , " d ] " ( Headers . replace ( Headers . of_list [ " c " , " d " ; " a " , " b ] ) " " a " " d ) " ; check " replace middle element " ~ expect [ " : ...
let test_remove ( ) = check " remove leading element " ~ expect [ " : c " , " d ] " ( Headers . remove ( Headers . of_list [ " a " , " b " ; " c " , " d ] ) " " a ) " ; check " remove trailing element " ~ expect [ " : c " , " d ] " ( Headers . ...
let test_ci_equal ( ) = let string_of_char x = String . init 1 ( fun _ -> x ) x in let ascii = Array . init ( 0xff + 1 ) 1 ~ f : Char . chr |> Array . to_list in let ascii_pairs = List . map ascii ~ f ( : fun x -> List . map ascii ~ f ( : fun y -> x , y ) y ) y |> List ...
let tests = [ " remove " , ` Quick , test_remove ; " replace " , ` Quick , test_replace ; " CI equal " , ` Quick , test_ci_equal ]
module Camlboy = Camlboy . Make ( Rom_only )
let run_test_rom_and_print_framebuffer file = let rom_bytes = Read_rom_file . f file in let camlboy = Camlboy . create_with_rom ~ rom_bytes ~ print_serial_port : false in let rec loop ( ) = let run_result = Camlboy . run_instruction camlboy in let prev_instr = Camlboy . For_tests . prev_inst caml...
let l_to_prob = List . map ~ f ( : fun ( x , p ) -> ( x , Prob . of_float p ) )
let l_of_prob = List . map ~ f ( : fun ( x , p ) -> ( x , Prob . to_float p ) )
let test_normalise_sum_to_1 = QCheck_alcotest . to_alcotest @@ QCheck . Test . make ~ count : 1000 ~ name " : test normalisation " QCheck . ( list ( pair int float ) ) Float . ( fun l -> if Stdlib . ( l = [ ] ) then true else abs ( ( List . sum ( module Float ) ~ f ...
let test_norms ( desc , input , expected ) ( ) = let input = l_to_prob input in Alcotest . ( check ( list ( pair char ( float 0 . 00001 ) ) ) ) desc ( l_of_prob @@ normalise input ) expected
let normalise_io = [ ( " empty lists " , [ ] , [ ] ) ; ( " sums to less than one " , [ ( ' a ' , 0 . 5 ) ] , [ ( ' a ' , 1 . ) ] ) ; ( " sums to greater than one " , [ ( ' a ' , 1 . 5 ) ] , [ ( ' a ' , 1 . ...
let normalise_tests = List . map normalise_io ~ f ( : fun t -> ( fst3 t , ` Quick , test_norms t ) )
let test_unduplicate ( ) = Alcotest . ( check ( list ( pair int ( float 0 . 0000001 ) ) ) ) " " ( l_of_prob ( unduplicate @@ l_to_prob [ ( 1 , 0 . 2 ) ; ( 1 , 0 . 4 ) ] ) ) [ ( 1 , 0 . 6 ) ]
let test_print ( ) = let d = from_primitive ( Primitive . categorical [ ( 1 , 0 . 6 ) ; ( 2 , 0 . 4 ) ] ) in Alcotest . ( check unit ) " " ( print_exact_exn ( module Base . Int ) d ) ( )
let test_memoisation memo ( ) = let r = ref 0 in let f _ = incr r ; ! r + 1 in let f = memo f in let x = f 1 in let x ' = f 1 in let y = f 2 in Alcotest . ( check ( list int ) ) " " [ x ; x ' ; y ] [ 2 ; 2 ; 3 ]
let todo ( ) = ( )
let w = weighted_dist ~ n : 10 ( categorical [ ( 1 , 0 . 5 ) ] )
let test_sample_mean ( ) = let i = infer Unit_test_models . single_coin ( MH 100 ) in let m = sample_mean ~ n : 1000 i in Alcotest . ( check ( float 0 . 5 ) ) " " m 0 . 83
let tests : unit Alcotest . test list = [ ( " normalise " , normalise_tests ) ; ( " unduplicate " , [ ( " no duplicates " , ` Quick , test_unduplicate ) ; ( " correct sums " , ` Quick , todo ) ; ] ) ; ( " memoise " , [ ( " for an incrementi...
let test_baking_rights ( ) = Context . init 2 >>=? fun ( b , contracts ) -> let open Plugin . RPC . Baking_rights in get Block . rpc_ctxt b ~ all : true >>=? fun rights -> assert ( Compare . List_length_with . ( rights = 65 ) ) ; let max_round = 15 in get Block . rpc_ctxt b...
let tests = [ Tztest . tztest " baking_rights " ` Quick test_baking_rights ]
let require_same here ( name1 , string1 ) ( name2 , string2 ) = require here ( String . equal string1 string2 ) ~ if_false_then_print_s : ( lazy [ % message " output differs unexpectedly " ~ _ ( : name1 , string1 : string * string ) ~ _ ( : name2 , string2 : string * st...
let test_m ( type a ) here ( module T : Hexdump . S with type t = a ) ? max_lines ? pos ? len t = let to_string_hum = T . Hexdump . to_string_hum ? max_lines ? pos ? len t in let to_sequence = T . Hexdump . to_sequence ? max_lines ? pos ? len t |> Sequence . to_list |> String . con...
let test ? max_lines ? pos ? len string = let of_string = test_m [ % here ] ( module String ) ? max_lines ? pos ? len string in print_endline of_string ; let of_bigstring = test_m [ % here ] ( module Bigstring ) ? max_lines ? pos ? len ( Bigstring . of_string string ) in require_sa...
let string = " Good morning . In less than an hour , aircraft from here will join others from around \ the world . And you will be launching the largest aerial battle in the history of \ mankind . " \ Mankind . " \ That word should have new meaning for all of us today . We \ can ' t be consume...
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_higher_order_basic _ = assert_equal 1 ( higher_order_1 ( + ) 2 3 ) ; assert_equal 0 ( higher_order_1 ( * ) 2 3 ...
let suite = " Higher - order tests " >::: [ " test_higher_order_basic ( foreign ) " >:: Foreign_tests . test_higher_order_basic ; " test_higher_order_basic ( stubs ) " >:: Stub_tests . test_higher_order_basic ; " test_higher_higher_order ( foreign ) " >:: Foreign_tests . te...
let _ = run_test_tt_main suite
let button ? at onclick label = let but = El . button ? at [ El . txt ( Jstr . v label ) ] in Ev . listen Ev . click ( fun _e -> onclick ( ) ) ( El . as_target but ) ; but
let with_frag frag u = Uri . with_uri ~ fragment ( : Jstr . v frag ) u
let test_history ( ) = let h = Window . history G . window in let loc = Window . location G . window in Window . History . push_state h ~ uri ( : with_frag " h1 " loc |> Result . get_ok ) ; Window . History . push_state h ~ uri ( : with_frag " h2 " loc |> Result . get_ok...
let test_no_reload ( ) = let loc = Window . location G . window in Window . set_location G . window ( with_frag " l1 " loc |> Result . get_ok ) ; Window . set_location G . window ( with_frag " l2 " loc |> Result . get_ok ) ; ( )
let test_back ( ) = Window . History . back ( Window . history G . window )
let test_forward ( ) = Window . History . forward ( Window . history G . window )
let test_reload ( ) = Window . reload G . window
let main ( ) = let noreload = button test_no_reload " Set window location " in let history = button test_history " Use history API " in let reload = button test_reload " Reload window " in let prev = button test_back " ← prev " in let next = button test_forward " next " → in let children...
let ( ) = main ( )
let invalid_history_mode_switch ~ previous_mode ~ target_mode = Alcotest . fail ( Format . asprintf " Invalid switch from % a to % a " History_mode . pp previous_mode History_mode . pp target_mode )
let expected_savepoint chain_store current_head blocks_per_cycle ~ previous_mode ~ target_mode = let open Lwt_result_syntax in let * current_head_metadata = Store . Block . get_block_metadata chain_store current_head in let head_lafl = Store . Block . last_allowed_fork_level current_head_metadata in let m...
let expected_caboose chain_store current_head blocks_per_cycle ~ previous_mode ~ target_mode savepoint = let open Lwt_result_syntax in match target_mode with | Archive -> return 0l | Full _ -> return 0l | Rolling offset -> ( let target_offset = ( Option . value offset ~ default : History_mode . d...
let check_consistency_after_switch descr chain_store ~ previous_mode ~ target_mode blocks = let open Lwt_result_syntax in let current_head = List . ( hd ( rev blocks ) ) |> WithExceptions . Option . get ~ loc : __LOC__ in let * Tezos_protocol_alpha . Protocol . Alpha_context . Constants . ...
let test ~ test_descr ~ from_hm ~ to_hm ~ nb_blocks_to_bake ( store_dir , context_dir ) store ~ patch_context = let open Lwt_result_syntax in let chain_store = Store . main_chain_store store in let *! genesis_block = Store . Chain . genesis_block chain_store in let * ( previously_baked_blocks , ...
let make_tests speed patch_context = let history_modes = match speed with | ` Slow -> [ Archive ; Full ( Some { offset = 0 } ) ; Full ( Some { offset = 3 } ) ; default_full ; Full ( Some { offset = 7 } ) ; Full ( Some { offset = 10 } ) ; Rolling ( Some { o...
let tests speed = let patch_context ctxt = Alpha_utils . default_patch_context ctxt in let test_cases = make_tests speed patch_context in ( " history_mode_switch " , test_cases )
let test_encode__normal ctxt = let open Fixture . KernelInfoRequest in let key = Hmac . create key in let actual = Hmac . encode ~ key ~ header ~ parent_header ~ metadata ~ content ( ) in assert_equal ~ ctxt ~ printer [ :% show : string ] actual hmac ; let open Fixture . ExecuteRequest in ...
let test_encode__nokey ctxt = let open Fixture . KernelInfoRequest in let actual = Hmac . encode ~ header ~ parent_header ~ metadata ~ content ( ) in assert_equal ~ ctxt ~ printer [ :% show : string ] actual " " ; let open Fixture . ExecuteRequest in let actual = Hmac . encode ~ header...
let test_validate__success _ = let open Fixture . KernelInfoRequest in let key = Hmac . create key in Hmac . validate ~ key ~ hmac ~ header ~ parent_header ~ metadata ~ content ( ) ; let open Fixture . ExecuteRequest in let key = Hmac . create key in Hmac . validate ~ key ~ hmac ~ header ...
let test_validate__failure _ = let open Fixture . KernelInfoRequest in let key = Hmac . create key in assert_raises ( Failure " HMAC validation failed " ) ( fun ( ) -> Hmac . validate ~ key ~ hmac " " : ~ header ~ parent_header ~ metadata ~ content ( ) ) ; let open Fixture . ...
let test_validate__nokey _ = let open Fixture . KernelInfoRequest in Hmac . validate ~ hmac ~ header ~ parent_header ~ metadata ~ content ( ) ; let open Fixture . ExecuteRequest in Hmac . validate ~ hmac ~ header ~ parent_header ~ metadata ~ content ( )
let suite = " Hmac " >::: [ " encode " >::: [ " normal " >:: test_encode__normal ; " nokey " >:: test_encode__nokey ; ] ; " validate " >::: [ " success " >:: test_validate__success ; " failure " >:: test_validate__failure ; " nokey " >:: test_validate__nokey ; ...
let t = Wrap . ( " some - hook " <: Normal_hook )
let ( ) = clear t
let show t = print_s [ % sexp ( t : _ t ) ]
let create_function s = Function . create ( s |> Symbol . intern ) [ % here ] ~ docstring " :< docstring " > ~ hook_type : Normal_hook ( Returns Value . Type . unit ) ( fun ( ) -> print_s [ % message s ] ) ; ;
let f1 = create_function " f1 "
let f2 = create_function " f2 "
let f3 = create_function " f3 " show t ; [ % expect { | ( ( symbol some - hook ) ( hook_type Normal_hook ) ( value ( ( ) ) ) ) } ] ; | add t f1 ; show t ; [ % expect { | ( ( symbol some - hook ) ( hook_type Normal_hook ) ( value ( ( f1 ) ) ) ...
let create_after_load_fun s = Function . create ( s |> Symbol . intern ) [ % here ] ~ docstring " :< docstring " > ~ hook_type : File_hook ( Returns Value . Type . unit ) ( fun _ -> print_endline s ) ; ; let f1 = create_after_load_fun " f1 " in let f2 = create_after_load_...
let doctype ? name ? public_identifier ? system_identifier ( ? force_quirks = false ) ( ) = { doctype_name = name ; public_identifier ; system_identifier ; raw_text = None ; force_quirks }
let tag ( ? self_closing = false ) name attributes = { Token_tag . name ; attributes ; self_closing }
let expect ? state ( ? foreign = false ) text signals = let report , iterate , ended = expect_signals token_to_string text signals in let stream , set_state , set_foreign = text |> Markup__Stream_io . string |> Markup__Encoding . utf_8 |> Markup__Input . preprocess is_valid_html_char Error . ...
let char_sequence ( ? start = 1 ) ( ? no_eof = false ) s = let rec assemble acc index = if index >= String . length s then let acc = if no_eof then acc else ( 1 , index + start , S ` EOF ) :: acc in List . rev acc else assemble ( ( 1 , index + start , S ( ` Char ( Char ...
let tests = [ ( " html . tokenizer . empty " >:: fun _ -> expect " " [ 1 , 1 , S ` EOF ] ) ; ( " html . tokenizer . text " >:: fun _ -> expect " foo " ( char_sequence " foo " ) ; expect " f \ x00oo " ( [ 1 , 1 , S ( ` Char 0x66 ) ; 1...
let expect id signals strings = let _ , iterate , ended = expect_strings id strings in signals |> Markup__Kstream . of_list |> Markup__Html_writer . write |> iter iterate ; ended ( )
let tests = [ ( " html . writer . empty " >:: fun _ -> expect " empty " [ ] [ ] ) ; ( " html . writer . text " >:: fun _ -> expect " text " [ ` Text [ " foo " ] ] [ S " foo " ] ; expect " adjacent text " [ ` Text [ " foo " ] ; ` ...
( module struct module Counter = struct type t = | Compare | Hash | Of_string | Sexp_of_t | T_of_sexp | To_string [ @@ deriving compare , hash , sexp ] end open Counter module Counts = struct module Map = Map . Make ( Counter ) type t = int Map . t ref [ @@ deriving sexp_of ] let actu...
let read_file f = Stdio . In_channel . with_file f ~ f : Stdio . In_channel . input_all
let partial_let = read_file " . . / passing / tests / partial . ml "
module Partial_ast = struct let tests_indent_range = let test name ~ input : source ~ range ~ expected = let test_name = " Partial_ast . indent_range : " ^ name in ( test_name , ` Quick , fun ( ) -> let range = Range . make ~ range source in let indent = Indent . Partial_ast . inde...
let x = y in 2 } | ~ expected { :| let f = let x = y in 2 } | ; test " after in " ~ range ( : 1 , 12 ) ~ input : { | let f =
let x = let y = foooooooooooooooooooo in let x = fooooooooooooo in let k = fooooooo in foooooooooooooooooooooooooo foooooooooooooooooooo foooooooooooooooo fooooooooo in } | ~ expected : { | let f = let x = let y = foooooooooooooooooooo in let x = fooooooooooooo in let k = fooooooo in fooooooooooooooooo...
module Yaml = struct type t = | Scalar of string | List of t list | Record of ( string * t ) list let scalar str = Scalar str let list lst = List lst let record lst = Record lst module Pretty = Fmlib_pretty . Print let rec to_doc : t -> Pretty . doc = function | Scalar str -> Pretty . text str ...
module CP = Character . Make ( Unit ) ( Yaml ) ( Unit )
let comment : char t = let * _ = char ' ' # in let * _ = ( charp ( fun c -> c <> ' \ n ' ) " comment character " ) |> skip_zero_or_more in return ' ' #
let whitespace : int t = char ' ' </> char ' \ n ' </> comment |> skip_zero_or_more |> no_expectations |> detach
let lexeme ( p : ' a t ) : ' a t = let * a = p in let * _ = whitespace in return a
let raw_string : string t = let expect = " chars not containing colon and newline " in let inner c = c <> ' \ n ' && c <> ' ' : && c <> ' ' # in let first c = c <> ' " ' && inner c in ( word first inner expect ) |> map String . trim |> lexeme
let quoted_string : string t = let expect = " chars except newline and dquote " in let ok c = c <> ' \ n ' && c <> ' " ' in let * _ = char ' " ' in let * str = ( word ok ok expect ) </> return " " in let * _ = char ' " ' |> lexeme in return str
let scalar : Yaml . t t = quoted_string </> raw_string |> map Yaml . scalar <?> " scalar "
let dash : char t = char ' ' - |> lexeme
let key : string t = backtrack ( let * str = raw_string </> quoted_string in let * _ = char ' ' : |> lexeme in return str ) " < key " >:
let rec yaml ( ) : Yaml . t t = sequence_block ( ) </> record_block ( ) </> scalar one_or_more ( sequence_element ( ) <?> " sequence element : " \- < yaml value " " >\ |> align ) |> map ( fun ( a , lst ) -> Yaml . list ( a :: lst ) ) <?> " sequence of aligne...
let parse : Parser . t = make ( ) ( let * _ = whitespace in yaml ( ) )
let write_errors ( source : string ) ( p : Parser . t ) : unit = let open Parser in let open Error_reporter in assert ( has_result p ) ; assert ( not ( has_succeeded p ) ) ; make_syntax p |> run_on_string source |> Pretty . layout 50 |> Pretty . write_to_channel stdout
let write_result ( source : string ) ( p : Parser . t ) : unit = let open Parser in if has_succeeded p then Yaml . ( to_json ( final p ) ) |> print_endline else if has_failed_syntax p then write_errors source p else assert false
let print_expectations ( p : Parser . t ) : unit = let open Printf in let open Parser in assert ( has_failed_syntax p ) ; Stdlib . List . iter ( fun ( str , ind ) -> match ind with | None -> printf " - % s \ n " str | Some ind -> match ind with | Indent . Indent i -> printf " ...
module type S = Indexed_container . S1 with type ' a t = ' a list
module This_list : S = struct include List include Indexed_container . Make ( struct type ' a t = ' a list let fold = List . fold let iter = ` Custom List . iter let length = ` Custom List . length let foldi = ` Define_using_fold let iteri = ` Define_using_fold end ) end
module That_list : S = List
let examples = [ [ ] ; [ 1 ] ; [ 2 ; 3 ] ; [ 4 ; 5 ; 1 ] ; List . init 8 ~ f ( : fun i -> i * i ) ]
module type Output = sig type t [ @@ deriving compare , sexp_of ] end
module Int_list = struct type t = int list [ @@ deriving compare , sexp_of ] end
module Int_pair_option = struct type t = ( int * int ) option [ @@ deriving compare , sexp_of ] end
module Int_option = struct type t = int option [ @@ deriving compare , sexp_of ] end
let check ( type a ) here examples ~ actual ~ expect ( module Output : Output with type t = a ) = List . iter examples ~ f ( : fun example -> let actual = actual example in let expect = expect example in require here ( Output . compare actual expect = 0 ) ~ if_false_then_print_s ( : la...
let bool_examples = [ [ ] ; [ true ] ; [ false ] ; [ false ; false ] ; [ true ; false ] ; [ false ; true ] ; [ true ; true ] ] ; ; let f _i elt = elt in check [ % here ] bool_examples ( module Bool ) ~ actual ( : fun list -> This_list . for_alli...