text stringlengths 0 601k |
|---|
let base = { Request . meth = ` GET ; headers = [ ] ; url = Printf . sprintf " http :// 0 . 0 . 0 . 0 :% d " port ; body = " " } |
let t_response = Alcotest . testable Response . pp ( ) = |
let t_error = Alcotest . testable Error . pp ( ) = |
let t_result = Alcotest . result t_response t_error |
let with_path p = { base with Request . url = base . Request . url ^ " " / ^ p } |
let body_header b = [ " content - length " , string_of_int ( String . length b ) ] |
let run_simple_get _ = Alcotest . check t_result " simple_get " ( Curly . run ( with_path " simple_get " ) ) ( Ok { Response . code = 200 ; body " = curly " ; headers = body_header simple_get_body } ) ; ; |
let read_header _ = let ( k , v ) = ( " x - curly " , " header value " ) in Alcotest . check t_result " read_header " ( Curly . run { ( with_path " read_header " ) with Request . headers = [ k , v ] } ) ( Ok { Response . code = 200 ; body = v ; headers = body_header v } ) ; ; |
let write_body _ = let body = { | foo bar Baez sample body the quick brown fox Alcotest . check t_result " write_body " ( Ok { Response . code = 200 ; body ; headers = body_header body } ) ( Curly . run { ( with_path " write_body " ) with Request . body ; meth = ` POST } ) |
let ( ) = let stopper = test_server ( ) in let tests_done = Lwt_preemptive . detach ( fun ( ) -> Alcotest . run " curly " [ " curly " , [ " simple_get " , ` Quick , run_simple_get ; " read_header " , ` Quick , read_header ; " write_body " , ` Quick , write_body ] ] ) ( ) in tests_done >|= ( fun ( ) -> Lwt . wakeup stop... |
let show ( ) = print_s [ % sexp ( get ( ) : Buffer . t ) ] |
let show_point ( ) = print_s [ % message " " ~ point ( : Point . get ( ) : Position . t ) ] let show ( ) = print_s [ % sexp ( Customization . value transient_mark_mode : bool ) ] in show ( ) ; [ % expect { | true } ] ; | return ( ) ; ; show ( ) ; [ % expect { | " #< buffer * scratch " *> } ] ; | return ( ) ; ; let old ... |
let show ( ) = print_s [ % sexp ( contents ~ text_properties : true ( ) : Text . t ) ] set_temporarily_to_temp_buffer Sync ( fun ( ) -> Point . insert " foo " ; set_text_property face foreground_red ; show ( ) ; [ % expect { | ( foo 0 3 ( face ( : foreground red ) ) ) } ] ; | set_text_property face foreground_blue ; sh... |
let show_var var = print_s [ % message " " ~ value : ( Current_buffer . value { var with type_ = Value . Type . value } : Value . t option ) ~ is_buffer_local ( : is_buffer_local var : bool ) ~ is_buffer_local_if_set ( : is_buffer_local_if_set var : bool ) ] ; ; let var = int_var " s " in set_temporarily_to_temp_buffer... |
let show ( ) = print_s [ % sexp ( get ( ) : Buffer . t ) ] let t = Buffer . create ~ name " : foo " in let % bind ( ) = set_temporarily Async t ~ f ( : fun ( ) -> let % bind ( ) = Clock . after ( sec 0 . 001 ) in set t ; show ( ) ; [ % expect { | " #< buffer foo " > } ] ; | return ( ) ) in show ( ) ; [ % expect { | " #... |
let counter = ref 0 |
let next_counter ( ) = incr counter ; ! counter ; ; |
let group = Group . of_string " test - customization - group " |
let test ? show_form type_ customization_type standard_value = let variable = concat [ " test - customization - symbol " ; - next_counter ( ) |> Int . to_string ] |> Symbol . intern in ignore ( defcustom variable [ % here ] ~ docstring " :< docstring " > ~ group ~ type_ ~ customization_type ~ standard_value ? show_form... |
let test_managed_buffer_hashing_and_equality _ = let i1 = allocate int 20 in let i2 = allocate int 20 in assert_equal !@ i1 !@ i2 ; assert_equal ( hash i1 ) ( hash i1 ) ; assert_bool " equal - but - not - identical objects have distinct hashes " ( hash i1 <> hash i2 ) ; assert_bool " equal - but - not - identical objec... |
let test_type_info_hashing_and_equality _ = let module M = struct type s let s : s structure typ = structure " s " let _ = begin ignore ( field s " d " double ) ; ignore ( field s " p " ( ptr void ) ) ; seal s end type t let t : t structure typ = structure " s " let _ = begin ignore ( field t " d " double ) ; ignore ( ... |
let suite = " Custom ops tests " >::: [ " managed buffer hashing and equality " >:: test_managed_buffer_hashing_and_equality ; " type info hashing and equality " >:: test_type_info_hashing_and_equality ; ] |
let _ = run_test_tt_main suite |
let rsa_suite = let open Key_parsers in let open Cvc . Rsa in let expected_public = let n = Z . of_string " 0x0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f60616263646566676869... |
let ec_suite = let open Key_parsers in let open Cvc in let open Ec in let expected_public = let modulus = Z . of_string " 0xffffffff00000001000000000000000000000000fffffffffffffffffffffffc " in let coefficient_a = Test_util . cstruct_of_hex " ffffffff00000001000000000000000000000000fffffffffffffffffffffffc " in let coe... |
let suite = [ " Rsa " >::: rsa_suite ; " Ec " >::: ec_suite ] |
module Int = struct type t = int let compare = compare let hash = Hashtbl . hash let equal = ( ) = let default = 0 end |
let pp_comma p ( ) = Format . ( pp_print_char p ' , ' ; pp_print_space p ( ) ) |
let pp_edge p ( s , d ) = Format . fprintf p " % d -> % d " s d |
module GPDFS = Traverse . Dfs ( GP ) |
let pp_has_cycles p g = if GPDFS . has_cycle g then Format . pp_print_string p " cycles " else Format . pp_print_string p " no cycles " |
module FW = Cycles . Fashwo ( struct include Builder . P ( GP ) let weight _ = Cycles . Normal 1 end ) |
let g1 = List . fold_left ( fun g ( s , d ) -> GP . add_edge g s d ) GP . empty [ ( 1 , 4 ) ; ( 1 , 3 ) ; ( 2 , 1 ) ; ( 2 , 4 ) ; ( 3 , 2 ) ; ( 4 , 3 ) ; ] |
let cycles1 = FW . feedback_arc_set g1 |
let g1 ' = List . fold_left ( fun g ( s , d ) -> GP . remove_edge g s d ) g1 cycles1 |
let ( ) = Format . ( printf " cycles1 = [ @< hv 2 { > % a } ] @ ( % a to % a ) . " @ ( pp_print_list ~ pp_sep : pp_comma pp_edge ) cycles1 pp_has_cycles g1 pp_has_cycles g1 ' ) |
let g2 = List . fold_left ( fun g ( s , d ) -> GP . add_edge g s d ) GP . empty [ ( 1 , 2 ) ; ( 1 , 4 ) ; ( 2 , 3 ) ; ( 2 , 4 ) ; ( 3 , 1 ) ; ( 4 , 8 ) ; ( 5 , 3 ) ; ( 5 , 6 ) ; ( 6 , 7 ) ; ( 7 , 5 ) ; ( 8 , 6 ) ; ( 8 , 7 ) ; ] |
let cycles2 = FW . feedback_arc_set g2 |
let g2 ' = List . fold_left ( fun g ( s , d ) -> GP . add_edge ( GP . remove_edge g s d ) d s ) g2 cycles2 |
let ( ) = Format . ( printf " cycles2 = [ @< hv 2 { > % a } ] @ ( % a to % a ) . " @ ( pp_print_list ~ pp_sep : pp_comma pp_edge ) cycles2 pp_has_cycles g2 pp_has_cycles g2 ' ) |
let g3 = List . fold_left ( fun g ( s , d ) -> GP . add_edge g s d ) GP . empty [ ( 1 , 2 ) ; ( 1 , 5 ) ; ( 2 , 6 ) ; ( 3 , 1 ) ; ( 4 , 2 ) ; ( 4 , 3 ) ; ( 5 , 3 ) ; ( 5 , 6 ) ; ( 6 , 4 ) ; ] |
let cycles3 = FW . feedback_arc_set g3 |
let g3 ' = List . fold_left ( fun g ( s , d ) -> GP . add_edge ( GP . remove_edge g s d ) d s ) g3 cycles3 |
let ( ) = Format . ( printf " cycles3 = [ @< hv 2 { > % a } ] @ ( % a to % a ) . " @ ( pp_print_list ~ pp_sep : pp_comma pp_edge ) cycles3 pp_has_cycles g3 pp_has_cycles g3 ' ) |
module Node = P2p . Node . Make ( Node_id ) |
module View = P2p . View . Make ( Node_id ) ( Node ) |
module Cyclon = P2p_cyclon . Make ( Node_id ) ( Node ) ( View ) |
let me = Node . init ( u64 99L ) |
let my_view = View . add ( Node . init ( u64 1L ) ) ( View . add ( Node . init ( u64 2L ) ) ( View . add ( Node . init ( u64 3L ) ) ( View . add ( Node . init ( u64 4L ) ) ( View . add ( Node . init ( u64 5L ) ) ( View . add ( Node . init ( u64 6L ) ) ( View . add ( Node . init ( u64 7L ) ) View . empty ) ) ) ) ) ) |
let my_recvd = View . add ( Node . init ( u64 10L ) ) ( View . add ( Node . init ( u64 20L ) ) ( View . add ( Node . init ( u64 3L ) ) View . empty ) ) |
let test_gossip _ctx = printf " \ nCYCLON GOSSIP \ n " ; let view = my_view in let xview = View . empty in let ( dst , sent , view ) = Cyclon . initiate ~ me ~ view ~ xview ~ view_len ~ xchg_len in let recvd = my_recvd in let dst = match dst with | Some dst -> dst | None -> assert_failure " No gossip target " in pf out... |
let suite = " suite " >::: [ " gossip " >:: test_gossip ; ] |
let ( ) = Nocrypto_entropy_unix . initialize ( ) ; run_test_tt_main suite |
module Node = P2p . Node . Make ( Node_id ) |
module View = P2p . View . Make ( Node_id ) ( Node ) |
module Cyclon = P2p_cyclon . Make ( Node_id ) ( Node ) ( View ) |
module Sampler = Urps . Sampler . Make ( Node_id ) |
module Io = struct type t = { node_id : Node_id . t ; sampler : Node . t Sampler . t ; in_chan : Lwt_io . input_channel ; out_chan : Lwt_io . output_channel ; } let init node_id in_chan out_chan = let c = 700 in let s = 10 in let k = 50 in let sampler = Sampler . init c s k in { node_id ; sampler ; in_chan ; out_chan }... |
module Cyclon_lwt = P2p_cyclon_lwt . Make ( Node_id ) ( Node ) ( View ) ( Cyclon ) ( Io ) |
let rec read_chan ch cy node rnode = let % lwt recvd = Lwt_io . read_value ch in pf out " % a # READ_CHAN \ n " Node_id . pp ( Node . id node ) ; pf out " recvd :\ n % a \ n " View . pp recvd ; flush stdout ; let % lwt view = Cyclon_lwt . respond cy rnode recvd in pf out " recvd :\ n % a \ n " View . pp recvd ; pf out ... |
let _ = Nocrypto_entropy_lwt . initialize ( ) |
let ( ) = let view_len = 8 in let xchg_len = 4 in let period = 1 . 0 in let ( in_ch1 , out_ch2 ) = Lwt_io . pipe ( ) in let ( in_ch2 , out_ch1 ) = Lwt_io . pipe ( ) in let node1 = Node . init ( u64 100L ) in let io1 = Io . init ( Node . id node1 ) in_ch1 out_ch1 in let view1 = View . add ( Node . init ( u64 110L ) ) ( ... |
let int_list_opt = Check . ( option @@ list @@ int ) |
let int_opt = Check . ( option int ) |
module N_events = struct let tags = [ " daemon " ; " n_events " ] let should_evaluate_in_the_list_of_given_events ( ) = Test . register ~ __FILE__ ~ title " : Daemon . n_events should evaluate in the list of given events " ~ tags @@ fun ( ) -> let filter = Daemon . n_events 5 Option . some in let msg nth = Printf . spr... |
module Nth_event = struct let tags = [ " daemon " ; " nth_event " ] let should_evaluate_in_the_nth_given_event ( ) = Test . register ~ __FILE__ ~ title " : Daemon . nth_event should evaluate in the nth given event " ~ tags @@ fun ( ) -> let filter = Daemon . nth_event 5 Option . some in let msg nth = Printf . sprintf "... |
let register ( ) = N_events . should_evaluate_in_the_list_of_given_events ( ) ; N_events . calls_should_be_independent ( ) ; N_events . should_fail_if_n_inf_to_zero ( ) ; N_events . should_fail_if_n_eq_zero ( ) ; Nth_event . should_evaluate_in_the_nth_given_event ( ) ; Nth_event . calls_should_be_independent ( ) ; Nth_... |
( module struct module Intf = Merkle_ledger . Intf module Database = Merkle_ledger . Database module type DB = Merkle_ledger . Database_intf . S with type key := Key . t and type token_id := Token_id . t and type token_id_set := Token_id . Set . t and type account_id := Account_id . t and type account_id_set := Account... |
let stamp_of_date_time d = ( Ptime . of_date_time $ raw_date_time @-> ret_get_option stamp ) d |
let valid_date d = ignore ( ( Ptime . of_date $ raw_date @-> ret_some stamp ) d ) |
let wrong_date d = ignore ( ( Ptime . of_date $ raw_date @-> ret_none stamp ) d ) |
let bounds = test " Testing calendar date field bounds " @@ fun ( ) -> wrong_date ( - 1 , 01 , 01 ) ; valid_date ( 0 , 01 , 01 ) ; valid_date ( 1 , 01 , 01 ) ; valid_date ( 9999 , 01 , 01 ) ; wrong_date ( 10000 , 01 , 01 ) ; wrong_date ( 10001 , 01 , 01 ) ; wrong_date ( 0 , 00 , 01 ) ; valid_date ( 0 , 01 , 01 ) ; vali... |
let stamp_trips = test " Random valid dates to stamps round trips " @@ fun ( ) -> let of_date = Ptime . of_date $ raw_date @-> ret_get_option stamp in for i = 1 to Test_rand . loop_len ( ) do let date = Test_rand . date ( ) in let trip = Ptime . to_date ( of_date date ) in eq_date date trip done ; ( ) |
let suite = suite " Ptime date tests " [ bounds ; stamp_trips ; ] |
let stamp_of_date_time d = ( Ptime . of_date_time $ raw_date_time @-> ret_get_option stamp ) d |
let valid_date_time d = ignore ( ( Ptime . of_date_time $ raw_date_time @-> ret_some stamp ) d ) |
let wrong_date_time d = ignore ( ( Ptime . of_date_time $ raw_date_time @-> ret_none stamp ) d ) |
let span_of_d_ps s = match Ptime . Span . of_d_ps s with |
let time_bounds = test " Date - time time field bounds " @@ fun ( ) -> let min_date = Ptime . to_date Ptime . min in let min_utc t = min_date , ( t , 0 ) in wrong_date_time ( min_utc ( - 2 , 00 , 00 ) ) ; wrong_date_time ( min_utc ( - 1 , 00 , 00 ) ) ; valid_date_time ( min_utc ( 00 , 00 , 00 ) ) ; valid_date_time ( mi... |
let tz = test " Testing date - time time zone calculations " @@ fun ( ) -> wrong_date_time ( ( 0000 , 01 , 01 ) , ( ( 00 , 00 , 00 ) , + 1 ) ) ; valid_date_time ( ( 0000 , 01 , 01 ) , ( ( 00 , 00 , 00 ) , + 0 ) ) ; valid_date_time ( ( 0000 , 01 , 01 ) , ( ( 00 , 00 , 00 ) , - 1 ) ) ; wrong_date_time ( ( 9999 , 12 , 31 ... |
let subsecond = test " Subsecond stamp to date - time " @@ fun ( ) -> let add , sub = let add t ps = Ptime . ( add_span t ( span_of_d_ps ( 0 , ps ) ) ) in let sub t ps = Ptime . ( sub_span t ( span_of_d_ps ( 0 , ps ) ) ) in add $ stamp @-> int64 @-> ret_get_option stamp , sub $ stamp @-> int64 @-> ret_get_option stamp ... |
let leap_sec = test " Testing leap second date - times " @@ fun ( ) -> let after_leap_sec = ( 1999 , 01 , 01 ) , ( ( 00 , 00 , 00 ) , 0 ) in let t0 = stamp_of_date_time ( ( 1998 , 12 , 31 ) , ( ( 23 , 59 , 59 ) , 0 ) ) in let t1 = stamp_of_date_time ( ( 1998 , 12 , 31 ) , ( ( 23 , 59 , 60 ) , 0 ) ) in let t2 = stamp_of... |
let stamp_trips = test " Random stamps to date - time round trips " @@ fun ( ) -> let stamp_of_posix_s = Ptime . of_float_s $ pp_float @-> ( ret_get_option stamp ) in let trip ? tz_offset_s t = let back = stamp_of_posix_s ( floor ( Ptime . to_float_s t ) ) in let trip = stamp_of_date_time ( Ptime . to_date_time ? tz_of... |
let round_trips = test " Random valid date - times to stamp round trips " @@ fun ( ) -> let is_leap_sec = function | ( _ , _ , _ ) , ( ( _ , _ , 60 ) , _ ) -> true | _ -> false in let rec rand_date_time_stamp ( ) = let date = Test_rand . date ( ) in let time = Test_rand . time ( ) in let tz = Test_rand . tz_offset_s ( ... |
let weekday = test " Ptime . weekday " @@ fun ( ) -> let pp_weekday ppf v = Format . pp_print_string ppf begin match v with | ` Mon -> " ` Mon " | ` Tue -> " ` Tue " | ` Wed -> " ` Wed " | ` Thu -> " ` Thu " | ` Fri -> " ` Fri " | ` Sat -> " ` Sat " | ` Sun -> " ` Sun " end in let eq_weekday v v ' = eq ~ eq ( ) := ~ pp... |
let suite = suite " Ptime date - time tests " [ time_bounds ; tz ; subsecond ; leap_sec ; stamp_trips ; round_trips ; weekday ; ] |
let num_days_in_week = 7 ( module Stable_unit_test . Make ( struct include Stable . V1 let equal = [ % compare . equal : t ] let tests = [ Sun , " SUN " , " \ 000 " ; Mon , " MON " , " \ 001 " ; Tue , " TUE " , " \ 002 " ; Wed , " WED " , " \ 003 " ; Thu , " THU " , " \ 004 " ; Fri , " FRI " , " \ 005 " ; Sat , " SAT "... |
module StringMap = Map . Make ( struct type t = string let compare = compare end ) |
let verbose = ref false |
let print_usage ( ) = Printf . printf " % s : [ - v ] [ cmd . . . ] \ n " Sys . argv . ( 0 ) ; Printf . printf " where cmd can be :\ n " ; Printf . printf " - list : list all tag names \ n " ; Printf . printf " - size < tag > : print the ( unreplicated ) size of < tag >\ n " ; Printf . printf " - get < tag > : print th... |
let tag_show tag_name = match D . tag_of_tagname ~ timeout : tAG_TIMEOUT tag_name with | U . Left e -> Printf . eprintf " % s \ n " ( E . string_of_error e ) | U . Right t -> Printf . printf " id : % s \ n " t . D . tag_id ; Printf . printf " last_modified : % s \ n " t . D . tag_last_modified ; Printf . printf " attri... |
let tag_links tag_name = match D . child_tags_of_tag_name ~ timeout : tAG_TIMEOUT tag_name with | U . Left e -> Printf . eprintf " % s \ n " ( E . string_of_error e ) | U . Right children -> Printf . printf " % s : " tag_name ; List . iter ( Printf . printf " % s " ) children ; Printf . printf " \ n " |
let tag_links_all ( ) = match D . tag_list ~ timeout : tAG_LIST_TIMEOUT ( ) with | U . Left e -> Printf . eprintf " % s \ n " ( E . string_of_error e ) | U . Right tl -> List . iter tag_links tl |
let human_size size = let rec iter ord size = if size < kB || ord == mAX_ORD then size , ord else iter ( ord + 1 ) ( size / 1000 ) in let hsz , ord = iter 0 size in let unit = match ord with | 0 -> " B " | 1 -> " KB " | 2 -> " MB " | 3 -> " GB " | 4 | _ -> " TB " in Printf . sprintf " % d % s " hsz unit |
let log_tag_size ( ? errs = ( 0 , 0 ) ) tag_name size = if errs <> ( 0 , 0 ) then Printf . printf " tag % s contains % s ( and probably more ; some % d nested tags and % d blobs were inaccessible ) \ n " %! tag_name ( human_size size ) ( fst errs ) ( snd errs ) else Printf . printf " tag % s contains % s \ n " %! tag_n... |
let rec tag_size_helper tag_name visited ( ( tag_errs , blob_errs ) as errs ) ~ show_children = if StringMap . mem tag_name visited then ( StringMap . find tag_name visited ) , errs , visited else begin U . dbg " processing tag % s . . . " tag_name ; match D . tag_of_tagname ~ timeout : tAG_TIMEOUT tag_name with | U . ... |
let tag_size tag_name = let tsz , errs , _ = tag_size_helper tag_name StringMap . empty ( 0 , 0 ) ~ show_children : false in log_tag_size ~ errs tag_name tsz |
let tag_list ( ) = match D . tag_list ~ timeout : tAG_LIST_TIMEOUT ( ) with | U . Left e -> Printf . eprintf " % s \ n " ( E . string_of_error e ) | U . Right tl -> List . iter ( Printf . printf " % s \ n " ) tl |
let tag_size_all ( ) = match D . tag_list ~ timeout : tAG_LIST_TIMEOUT ( ) with | U . Left e -> Printf . eprintf " % s \ n " ( E . string_of_error e ) | U . Right tl -> let size_map = List . fold_left ( fun v tn -> let _ , _ , v ' = tag_size_helper tn v ( 0 , 0 ) ~ show_children : true in v ' ) StringMap . empty tl in ... |
let run ( ) = let is_opt a = a . [ 0 ] = ' ' - in let num_args = Array . length Sys . argv in let get_op_args indx = let rec helper i acc = if i >= num_args || is_opt Sys . argv . ( i ) then List . rev acc , i else helper ( i + 1 ) ( Sys . argv . ( i ) :: acc ) in helper indx [ ] in let rec process_args indx = if indx ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.