text stringlengths 0 601k |
|---|
let sha1 = Alcotest . testable Digestif . SHA1 . pp Digestif . SHA1 . equal |
let test_hex_iso i random_input = Alcotest . test_case ( strf " iso :% d " i ) i ` Quick @@ fun ( ) -> let hash : Digestif . SHA1 . t = Digestif . SHA1 . of_raw_string random_input in let hex = Digestif . SHA1 . to_hex hash in Alcotest ( . check sha1 ) sha1 " iso hex " ( Digestif . SHA1 . of_hex hex ) hex hash |
let test_consistent_hex_iso i random_input = Alcotest . test_case ( strf " iso :% d " i ) i ` Quick @@ fun ( ) -> let hash : Digestif . SHA1 . t = Digestif . SHA1 . of_raw_string random_input in let hex = Digestif . SHA1 . to_hex hash in Alcotest ( . check sha1 ) sha1 " iso consistent hex " ( Digestif . SHA1 . consiste... |
let tests ( ) = Alcotest . run " digestif " [ ( " of_hex 0 " , List . mapi test_hex_success consistent_hex ) consistent_hex ; ( " consistent_of_hex 0 " , List . mapi test_consistent_hex_success consistent_hex ) ; ( " of_hex 1 " , List . mapi test_hex_success spaces_hex ) spaces_hex ; ( " consistent_of_hex 1 " , List . ... |
let ( ) = tests ( ) |
let fv_const = Free_variable . of_string " const " |
let fv_v1 = Free_variable . of_string " v1 " |
let fv_v2 = Free_variable . of_string " v2 " |
module Term ( X : S ) = struct open X let linear = lam ~ name " : size " @@ fun size -> free ~ name : fv_const + ( free ~ name : fv_v1 * size ) let linear_sum = lam ~ name " : size1 " @@ fun size1 -> lam ~ name " : size2 " @@ fun size2 -> free ~ name : fv_const + ( free ~ name : fv_v1 * ( size1 + size2 ) ) let not_line... |
module PP = Term ( Pp ) |
let test_pp_1 ( ) = PP . linear = " fun size -> ( free ( const ) + ( free ( v1 ) * size ) ) " |
let test_pp_2 ( ) = PP . linear_sum = " fun size1 -> fun size2 -> ( free ( const ) + ( free ( v1 ) * ( size1 + size2 ) ) ) " |
let test_pp_3 ( ) = PP . applied_linear = " ( ( fun size1 -> fun size2 -> ( free ( const ) + ( free ( v1 ) * ( size1 + size2 ) ) ) ) \ 10 ) 33 " |
let test_eval1 ( ) = let module Subst = Subst ( struct let subst x = match List . assoc ~ equal : Free_variable . equal x [ ( fv_v1 , 88 . ) ; ( fv_v2 , 4 . ) ; ( fv_const , - 10 . ) ] with | Some v -> v | None -> Format . eprintf " failed to get % a . " @ Free_variable . pp x ; raise Not_found end ) ( Eval ) in let mo... |
let test_eval2 ( ) = let module Subst = Subst ( struct let subst x = match List . assoc ~ equal : Free_variable . equal x [ ( fv_v1 , 2 . ) ; ( fv_v2 , 4 . ) ; ( fv_const , - 10 . ) ] with | Some v -> v | None -> Format . eprintf " failed to get % a . " @ Free_variable . pp x ; raise Not_found end ) ( Eval ) in let mod... |
module Mset_impl = Term ( Eval_to_vector ) |
let test_eval_to_lincomb ( ) = let res = Hash_cons_vector . prj @@ Eval_to_vector . prj Mset_impl . ( Eval_to_vector . ( applied_linear + applied_linear ) ) in match Eval_linear_combination_impl . run ( fun _ -> None ) res with | exception _ -> false | { linear_comb ; const } -> Free_variable . Sparse_vec . ( equal lin... |
let test_eval_to_lincomb_fail ( ) = let res = Hash_cons_vector . prj @@ Eval_to_vector . prj Mset_impl . ( applied_not_linear ) in match Eval_linear_combination_impl . run ( fun _ -> None ) res with | exception Eval_linear_combination " " * -> true | _ -> false |
let tests = [ Test . tztest_assert " pp1 " ` Quick test_pp_1 ; Test . tztest_assert " pp2 " ` Quick test_pp_2 ; Test . tztest_assert " pp3 " ` Quick test_pp_3 ; Test . tztest_assert " eval " ` Quick test_eval1 ; Test . tztest_assert " eval " ` Quick test_eval2 ; Test . tztest_assert " eval_to_linear_comb " ` Quick test... |
module U = struct let string_of_list f l = " [ " ^ List . fold_left ( fun a b -> a ^ ( f b ) ^ " ; " ) " " l ^ " ] " let print_header h = Printf . printf " % s " ( " \ n " ^ h ^ " \ n " ) |
let _ = U . print_header " Counter " ; |
let module MkConfig ( Vars : sig val root : string end ) : Icounter . Config = struct let root = Vars . root let shared = " / tmp / repos / shared . git " let init ( ) = let _ = Sys . command ( Printf . sprintf " rm - rf % s " root ) in let _ = Sys . command ( Printf . sprintf " mkdir - p % s " root ) in ( ) |
let module CInit = MkConfig ( struct let root = " / tmp / repos / init . git " end ) in |
let module MInit = Icounter . MakeVersioned ( CInit ) in |
let module M = Counter . Make in |
let module Vpst = MInit . Vpst in |
let ( ) >>= = Vpst . bind in |
let thread2_f : unit Vpst . t = Vpst . get_latest_version ( ) >>= fun c0 -> let c0 ' = M . inc c0 10 in Vpst . sync_next_version ~ v : c0 ' >>= fun c1 -> Vpst . liftLwt @@ Lwt_unix . sleep 0 . 5 >>= fun ( ) -> let c1 ' = M . dec c1 9 in Vpst . sync_next_version ~ v : c1 ' >>= fun c2 -> let _ = Printf . printf " thread2... |
let thread1_f : unit Vpst . t = Vpst . get_latest_version ( ) >>= fun c0 -> Vpst . fork_version thread2_f >>= fun ( ) -> Vpst . liftLwt @@ Lwt_unix . sleep 0 . 1 >>= fun ( ) -> let c0 ' = M . inc ( M . inc c0 2 ) 3 in Vpst . sync_next_version ~ v : c0 ' >>= fun c1 -> Vpst . liftLwt @@ Lwt_unix . sleep 0 . 1 >>= fun ( )... |
let main ( ) = Vpst . with_init_version_do 0 thread1_f in |
module Char_class = struct open Table module T = struct type t = transition or_error list [ @@ deriving compare , sexp_of , hash ] end let compute ( table : Table . t ) = let transitions_to_class = Hashtbl . create ( module T ) in let classes = Array . create 0 ~ len : 256 in for i = 0 to 255 do let transitions = List ... |
type ' a result = | Sexp of ' a | Error |
let transition_count = State . count * Char_class . count |
let transition_seen = Array . create false ~ len : transition_count |
let transition_eoi_seen = Array . create false ~ len : State . count |
let feed state char stack = transition_seen . ( ( A . automaton_state state * Char_class . count ) + Char_class . of_char char ) <- true ; A . feed state char stack ; ; |
let feed_eoi state stack = transition_eoi_seen . ( A . automaton_state state ) <- true ; A . feed_eoi state stack ; ; |
let parse_string_gen mode s = let state = A . new_state mode Sexp in let len = String . length s in let rec loop pos stack = if pos = len then feed_eoi state stack else ( let stack = feed state s . [ pos ] stack in loop ( pos + 1 ) stack ) in loop 0 Automaton_stack . empty ; ; |
let parse_string s = Automaton_stack . get_single ( parse_string_gen Single s ) |
let parse_string_many s = Automaton_stack . get_many ( parse_string_gen Many s ) |
let cases_where_sexplib_disagree_with_itself = ref [ ] |
let add_to_list cell x = cell := x :: ! cell |
let test_one_case_dealing_with_a_single_sexp ( str , expected ) = let parsexp = match parse_string str with | sexp -> Ok sexp | exception Parse_error . Parse_error error -> Error error in let matches_expected = match parsexp , expected with | Ok a , Sexp b -> Sexp . equal a b | Error _ , Error -> true | _ -> false in i... |
let test_one_case_dealing_with_many_sexps ( str , expected ) = let parsexp = match parse_string_many str with | sexps -> Ok sexps | exception Parse_error . Parse_error error -> Error error in let matches_expected = match parsexp , expected with | Ok a , Sexp b -> [ % compare . equal : Sexp . t list ] a b | Error _ , Er... |
let witness_for_class cl = let rec loop i = if i = 256 then raise Caml . Not_found ; if Char_class . of_char ( Char . of_int_exn i ) = cl then Char . of_int_exn i else loop ( i + 1 ) in let ch = loop 0 in match ch with | ' \ 000 ' -> if Char_class . of_char ' z ' = cl then ' z ' else ch | _ -> ch ; ; |
let some_cases : ( string * Sexp . t result ) list = [ " foo " , Sexp ( Atom " foo " ) ; " foo " , Sexp ( Atom " foo " ) ; " zoo " , Sexp ( Atom " zoo " ) ; " 123 " , Sexp ( Atom " 123 " ) ; " ( foo bar ) " , Sexp ( List [ Atom " foo " ; Atom " bar " ] ) ; " " , \\ Sexp ( Atom " " ) \\ ; " " , | Sexp ( Atom " " ) | ; "... |
let quoted_string_cases : ( string * Sexp . t result ) list = [ " " \ foo \\\\ bar \ n1 \ r \ n2 \\\ n3 \\\ r \ n4 \\\ n 5 " " , \ Sexp ( Atom " foo \\ bar \ n1 \ r \ n2345 " ) ; " " \\\\ r " " , \ Sexp ( Atom " \ r " ) ; " " \\\\ n " " , \ Sexp ( Atom " " ) ; " " \\\\ n \ n " " , \ Sexp ( Atom " \ n " ) ; " " \\\\ n \... |
let trailing_whitespace_cases : ( string * Sexp . t result ) list = [ " x " , Sexp ( Atom " x " ) ; " x \ n " , Sexp ( Atom " x " ) ; " x ; " , Sexp ( Atom " x " ) ] ; ; |
let cases = some_cases @ quoted_string_cases @ trailing_whitespace_cases @ List . map quoted_string_cases ~ f ( : fun ( s , result ) -> ( " #| " ^ s ^ " |# blah " , match result with | Sexp _ -> Sexp ( Sexp . Atom " blah " ) | Error -> Error ) ) ; ; |
let zero_sexp_cases : ( string * Sexp . t list result ) list = [ " " , Sexp [ ] ; " \ n " , Sexp [ ] ; " ; " , Sexp [ ] ] ; ; List . iter cases ~ f ( : fun ( input , result ) -> let result_many = match result with | Sexp x -> Sexp [ x ] | Error -> Error in test_one_case_dealing_with_a_single_sexp ( input , result ) ; t... |
let rec f n acc = if n = 0 then acc ( ) else f ( n - 1 ) 1 ( fun _ -> print_endline ( string_of_int n ) n ; acc ( ) ) |
let test_closure ( ) = let n = 6 in let arr = Array . make n ( fun x -> x ) in for i = 0 to n do arr ( . i ) i <- fun _ -> i done ; arr |
let create_cpu ( ? a = 0x00 ) ( ? b = 0x00 ) ( ? c = 0x00 ) ( ? d = 0x00 ) ( ? e = 0x00 ) ( ? h = 0x00 ) ( ? l = 0x00 ) ( ? carry = false ) ( ? half_carry = false ) ( ? sub = false ) ( ? zero = false ) ( ? pc = 0x00 ) ( ? sp = 0x00 ) ( ? halted = false ) ( ? bus = Bus . create ~ size : 0x10 ) ( ? ime = true ) ( ) = let... |
let execute_result t inst = let inst_info = Inst_info . { len ( = Uint16 . of_int 2 ) ; mcycles { = branched = 1 ; not_branched = 2 ; } ; inst } in Cpu . For_tests . execute t inst_info |> ( fun x -> ignore ( x : int ) ) |
let print_execute_result t inst = execute_result t inst ; Cpu . show t |> print_endline |
let print_addr_content bus addr = Bus . read_byte bus ( Uint16 . of_int addr ) |> Uint8 . show |> print_endline let t = create_cpu ( ) in NOP |> print_execute_result t ; [ % expect { | A :$ 00 F :---- BC :$ 0000 DE :$ 0000 HL :$ 0000 SP :$ 0000 PC :$ 0000 } ] | let t = create_cpu ( ) in LD8 ( R A , Immediate8 ( Uint8 .... |
let crc data = P . int_crc ~ initial : 0 ~ data |
let crc_cumulative ~ acc data = P . int_crc ~ initial : acc ~ data let examples = [ Int . min_value ; - 1234 ; - 1 ; 0 ; 1 ; 1234 ; Int . max_value ] in List . iter examples ~ f ( : fun x -> let crc = crc x in let cumulative_crc = crc_cumulative ~ acc : 0 x in require_equal [ % here ] ( module Int ) crc cumulative_crc ... |
let data = Jstr . v " Brr it ' s cold out there . " |
let test_random log = let t = Tarray . create Tarray . Uint8 10 in let to_hex t = Tarray . to_hex_jstr ~ sep : Jstr . sp t in log ( El . [ txt ' " New array : " ; code [ txt ( to_hex t ) ] ] ) ; Crypto . set_random_values Crypto . crypto t ; log ( El . [ txt ' " Rand fill : " ; code [ txt ( to_hex t ) ] ] ) ; Fut . ok ... |
let sign_key_pair s = let sig_key_gen = let name = Crypto_algo . rsassa_pkcs1_v1_5 in let modulus_length = 2048 in let i65537 = [ | 0x01 ; 0x0 ; 0x01 ] | in let public_exponent = Tarray . of_int_array Tarray . Uint8 i65537 in let hash = Jstr . v " SHA - 256 " in Crypto_algo . Rsa_hashed_key_gen_params . v ~ name ~ modu... |
let sign_algo = Crypto_algo . v Crypto_algo . rsassa_pkcs1_v1_5 |
let sign s priv_key d = Subtle_crypto . sign s sign_algo priv_key d |
let verify s pub_key sig ' d = Subtle_crypto . verify s sign_algo pub_key ~ sig ' d |
let test_signing log = let d = Tarray . of_jstr data in let s = Crypto . subtle Crypto . crypto in let * k = sign_key_pair s in let * sig ' = sign s ( Crypto_key . private ' k ) d in let sig ' = Tarray . uint8_of_buffer sig ' in let * verif = verify s ( Crypto_key . public k ) sig ' d in let to_hex t = Tarray . to_hex_... |
let sym_key s = let sym_key_gen = let name = Crypto_algo . aes_cbc and length = 128 in Crypto_algo . Aes_key_gen_params . v ~ name ~ length ( ) in let usages = Crypto_key . Usage . [ encrypt ; decrypt ] in Subtle_crypto . generate_key s sym_key_gen ~ extractable : false ~ usages |
let sym_algo = let iv = Tarray . create Tarray . Uint8 16 in let ( ) = Crypto . set_random_values Crypto . crypto iv in Crypto_algo . Aes_cbc_params . v ~ iv ( : Tarray . buffer iv ) ( ) |
let sym_encrypt s key clear = Subtle_crypto . encrypt s sym_algo key clear |
let sym_decrypt s key cipher = Subtle_crypto . decrypt s sym_algo key cipher |
let test_sym_crypt log = let clear = Tarray . of_jstr data in let s = Crypto . subtle Crypto . crypto in let * k = sym_key s in let * cipher = sym_encrypt s k clear in let cipher = Tarray . uint8_of_buffer cipher in let * clear ' = sym_decrypt s k cipher in let * clear ' = Fut . return Tarray . ( to_jstr ( uint8_of_buf... |
let test_import_export log = let to_hex t = Tarray . to_hex_jstr ~ sep : Jstr . sp t in let s = Crypto . subtle Crypto . crypto in let sym_key_gen = let name = Crypto_algo . aes_cbc and length = 128 in Crypto_algo . Aes_key_gen_params . v ~ name ~ length ( ) in let * k = Subtle_crypto . generate_key s sym_key_gen ~ ext... |
let test log = Fut . map ( Console . log_if_error ~ use ( ) ) : @@ let * ( ) = test_random log in let * ( ) = test_signing log in let * ( ) = test_sym_crypt log in let * ( ) = test_import_export log in Fut . ok ( ) |
let main ( ) = let h1 = El . h1 [ El . txt ' " Web Crypto test " ] in let log_view = El . ol [ ] in let log cs = El . append_children log_view [ El . li cs ] in let children = [ h1 ; log_view ] in El . set_children ( Document . body G . document ) children ; test log |
let ( ) = ignore ( main ( ) ) |
let ( sk , pk , pkh ) = Crypto_box . random_keypair ( ) |
let chkey = Crypto_box . precompute sk pk |
let test_check_pow ( ) = let open Lwt . Infix in let target = Crypto_box . make_pow_target 2 . in Crypto_box . generate_proof_of_work pk target >|= fun pow -> Alcotest . ( check bool ) " check_pow " ( Crypto_box . check_proof_of_work pk pow target ) true |
let test_neuterize sk pk ( ) = Alcotest . check ( Alcotest . testable Crypto_box . pp_pk Crypto_box . equal ) " neuterize " ( Crypto_box . neuterize sk ) pk |
let test_hash pk pkh ( ) = Alcotest . check ( Alcotest . testable Crypto_box . Public_key_hash . pp Crypto_box . Public_key_hash . equal ) " test_hash " ( Crypto_box . hash pk ) pkh |
let test_fast_box_noalloc msg ( ) = let buf = Bytes . copy msg in let tag = Bytes . make Crypto_box . tag_length ' \ x00 ' in Crypto_box . fast_box_noalloc chkey zero_nonce tag buf ; Alcotest . ( check bool " fast_box_open " true ( Crypto_box . fast_box_open_noalloc chkey zero_nonce tag buf ) ) ; Alcotest . ( check byt... |
let test_fast_box msg ( ) = let cmsg = Crypto_box . fast_box chkey zero_nonce msg in match Crypto_box . fast_box_open chkey zero_nonce cmsg with | Some decrypted_msg -> Alcotest . ( check bytes " test_fast_box " msg decrypted_msg ) | None -> Alcotest . fail " Box : Decryption error " |
let tests = [ ( " crypto_box " , [ ( " Neuterize Secret roundtrip " , ` Quick , test_neuterize sk pk ) ; ( " Public Key Hash roundtrip " , ` Quick , test_hash pk pkh ) ; ( " HACL * box ( noalloc ) " , ` Quick , test_fast_box_noalloc ( Bytes . of_string " test " ) ) ; ( " HACL * box " , ` Quick , test_fast_box ( Bytes .... |
let tests_lwt = [ ( " crypto_box " , [ ( " Check PoW " , ` Slow , test_check_pow ) ] ) ] |
module Csexp_arg = struct open Csexp type t = Csexp . t let atom s = Atom s let list l = List l let match_ s ~ atom ~ list = match s with | Atom s -> atom s | List l -> list l type loc = unit let make_loc = None let atom_with_loc ~ loc ( ) : = atom let list_with_loc ~ loc ( ) : = list end |
let gen_csexp ( str : string Q . Gen . t ) : CS0 . t Q . Gen . t = let open Q . Gen in let open Csexp in begin fix @@ fun self depth -> let mklist n = list_size ( 0 -- n ) ( self ( depth + 1 ) ) >|= fun l -> List l in frequency @@ List . flatten [ [ ( 3 , str >|= fun s -> Atom s ) ] ; ( match depth with | 0 -> [ 4 , mk... |
let rec shrink_csexp ( s : Csexp . t ) : Csexp . t Q . Iter . t = let open Csexp in let open Q . Iter in match s with | Atom s -> Q . Shrink . string s >|= fun s -> Atom s | List l -> Q . Shrink . list ~ shrink : shrink_csexp l >|= fun l -> List l |
let arb_csexp_pp = let genstr = Q . Gen . ( string_size ~ gen : Q . Gen . printable ( 0 -- 15 ) ) in Q . make ~ print : Sexp0 . to_string ~ shrink : shrink_csexp ( gen_csexp genstr ) |
let arb_csexp_arb = let genchar = Q . Gen . ( 0 -- 255 >|= Char . chr ) in let genstr = Q . Gen . ( string_size ~ gen : genchar ( 0 -- 15 ) ) in Q . make ~ print : Sexp0 . to_string ~ shrink : shrink_csexp ( gen_csexp genstr ) |
module Make ( X : sig val arb : Csexp . t Q . arbitrary end ) = struct open X let test_print_cc_parse_csexp = Q . Test . make ~ count : 2_000 ~ name " : cc - print - csexp - parse " arb @@ fun sexp -> let s = CS0 . to_string sexp in match Csexp . parse_string s with | Ok sexp ' -> sexp = sexp ' | Error ( _ , msg ) -> Q... |
let suite = let module M1 = Make ( struct let arb = arb_csexp_pp end ) in let module M2 = Make ( struct let arb = arb_csexp_arb end ) in List . flatten [ M1 . suite ; M2 . suite ] |
let ( ) = QCheck_base_runner . run_tests_main suite |
let ls = [ CSS . Length . Em 0 . 1 ; CSS . Length . Ex 0 . 12 ; CSS . Length . Px 5 . 4 ; CSS . Length . Gd 0 . ; CSS . Length . Rem 10 . 0 ; CSS . Length . Vw 0 . 10 ; CSS . Length . Vh 0 . 1 ; CSS . Length . Vm 0 . 5 ; CSS . Length . Ch 20 . 6 ; CSS . Length . Zero ; CSS . Length . Mm 100 . ; CSS . Length . Cm 10 . 1... |
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_isX_functions _ = begin assert_bool " " ( isalnum ' a ' ) ; assert_bool " " ( not ( isalnum ' ' ) ) ; assert_bool " " ( isalpha ' x ' ) ; assert_bool " " ( not ( ... |
let test_div _ = let module M = struct type div_t let div_t : div_t structure typ = structure " div_t " let ( ) -: ty label = field div_t label ty let quot = int -: " quot " let rem = int -: " rem " let ( ) = seal div_t let div = foreign " div " ( int @-> int @-> returning div_t ) let test ~ num ~ dem ~ quotient ~ rema... |
let suite = " C standard library tests " >::: [ " test isX functions ( foreign ) " >:: Foreign_tests . test_isX_functions ; " test isX functions ( stubs ) " >:: Stub_tests . test_isX_functions ; " test string function ( foreign ) " >:: Foreign_tests . test_string_functions ; " test string function ( stubs ) " >:: Stub_... |
let _ = run_test_tt_main suite |
let test ~ op ~ op_name ~ to_string x = printf " % s % s = % d \ n " op_name ( to_string x ) ( op x ) |
let numbers = [ 0 ; 1 ; 7 ; 2 ; 4 ; 12 ; 18 ; - 1 ] let open Int64 in let numbers = List . map numbers ~ f : of_int in let f = test ~ op : Ocaml_intrinsics . Int64 . count_trailing_zeros ~ op_name " : ctz " ~ to_string : Hex . to_string_hum in List . iter ~ f ( max_value :: min_value :: numbers ) ; [ % expect { | ctz 0... |
let callback req body = function | [ " simple_get " ] -> Server . respond_string ~ status ` : OK ~ body : simple_get_body ( ) | [ " read_header " ] -> Server . respond_string ~ status ` : OK ~ body ( : match Header . get ( Request . headers req ) " x - curly " with | None -> failwith " x - curly header not present " | ... |
let test_server ( ) = let ( stop , stopper ) = Lwt . task ( ) in Server . make ~ callback ( : fun _ req body -> let uri_parts = req |> Request . uri |> Uri . path |> String . split_on_char ' ' / |> List . tl in Cohttp_lwt . Body . to_string body >>= fun body -> callback req body uri_parts ) ( ) |> Server . create ~ mod... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.