text stringlengths 12 786k |
|---|
let f2 x = try match x with | 0 -> 1 | 1 -> 2 | 2 -> 3 with | exc -> ( Format . eprintf " Exception tracer at File " / Users / bobzhang1988 / Writing / ocaml - book / camlp4 / examples / test_pa_exception_wrapper . ml " , line 7 , characters 11 - 56 ( end at line 10 , charact... |
let f3 = function | 0 -> ( try 1 with | exc -> ( Format . eprintf " Exception tracer at File " / Users / bobzhang1988 / Writing / ocaml - book / camlp4 / examples / test_pa_exception_wrapper . ml " , line 14 , characters 9 - 10 ( % s ) s . " @ ( Printexc . to_string exc ) ex... |
let main = h ( ) |
let f1 x = printf " f1 % d . " @ x ; ; |
let f2 x = printf " f2 % f . " @ x ; ; |
let f3 x = printf " f3 % s . " @ x ; ; |
let global_handler e = Format . eprintf " global_handler : % s . " @ ( Printexc . to_string e ) e Format . eprintf " global_handler : % s . " @ ( Printexc . to_string e ) e end in ( ) with ( fun e -> Format . eprintf " global_handler : % s . " @ ( Printexc . to_string e ) e )... |
let id = <: lam < \ x -> x x >> |
let zero = <: lam < \ s -> \ z -> s z >> |
let succ = <: lam < \ n -> \ s -> \ z -> s n >> |
let one = <: lam < $ succ $ >> |
let iota = <: lam < \ x -> z >> |
let rho = <: lam < \ m -> \ r -> ( s m ( m r iota r ) ) >> |
let rec_nat = <: lam < \ n -> \ s -> \ z -> n $ rho $ $ iota $ $ rho $ >> |
let plus = <: lam < \ n -> \ m -> $ rec_nat $ n ( \ n -> \ p -> $ succ $ p ) m >> |
let times = <: lam < \ n -> \ m -> $ rec_nat $ n ( \ n -> \ p -> $ plus $ m p ) $ zero $ >> |
let fact = <: lam < \ n -> $ rec_nat $ n ( \ n -> \ p -> $ times $ ( $ succ $ n ) p ) $ one $ >> |
let id = ` Lam ( ( ` Var " x ) " , ( ` App ( ( ` Var " x ) " , ( ` Var " x ) ) ) ) " |
let zero = ` Lam ( ( ` Var " s ) " , ( ` Lam ( ( ` Var " z ) " , ( ` App ( ( ` Var " s ) " , ( ` Var " z ) ) ) ) ) ) " |
let succ = ` Lam ( ( ` Var " n ) " , ( ` Lam ( ( ` Var " s ) " , ( ` Lam ( ( ` Var " z ) " , ( ` App ( ( ` Var " s ) " , ( ` Var " n ) ) ) ) ) ) ) ) " |
let iota = ` Lam ( ( ` Var " x ) " , ( ` Var " z ) ) " |
let rho = ` Lam ( ( ` Var " m ) " , ( ` Lam ( ( ` Var " r ) " , ( ` App ( ( ` App ( ( ` Var " s ) " , ( ` Var " m ) ) ) " , ( ` App ( ( ` App ( ( ` App ( ( ` Var " m ) " , ( ` Var " r ) ) ) " , ( ` Var " i... |
let rec_nat = ` Lam ( ( ` Var " n ) " , ( ` Lam ( ( ` Var " s ) " , ( ` Lam ( ( ` Var " z ) " , ( ` App ( ( ` App ( ( ` App ( ( ` Var " n ) " , rho ) rho ) rho , iota ) iota ) iota , rho ) rho ) rho ) rho ) rho ) rho ) rh... |
let plus = ` Lam ( ( ` Var " n ) " , ( ` Lam ( ( ` Var " m ) " , ( ` App ( ( ` App ( ( ` App ( rec_nat , ( ` Var " n ) ) ) " , ( ` Lam ( ( ` Var " n ) " , ( ` Lam ( ( ` Var " p ) " , ( ` App ( succ , ( ` Var " ... |
let times = ` Lam ( ( ` Var " n ) " , ( ` Lam ( ( ` Var " m ) " , ( ` App ( ( ` App ( ( ` App ( rec_nat , ( ` Var " n ) ) ) " , ( ` Lam ( ( ` Var " n ) " , ( ` Lam ( ( ` Var " p ) " , ( ` App ( ( ` App ( plus , ... |
let fact = ` Lam ( ( ` Var " n ) " , ( ` App ( ( ` App ( ( ` App ( rec_nat , ( ` Var " n ) ) ) " , ( ` Lam ( ( ` Var " n ) " , ( ` Lam ( ( ` Var " p ) " , ( ` App ( ( ` App ( times , ( ` App ( succ , ( ` Var " n... |
let a = <: me < let rec fib x = >> |
let b = <: me < let f = $ a $ in f >> |
let c = <: me < $ int : x $ >> |
let d x = match x with | <: me < $ int : _ $ >> -> true | _ -> false |
let test_antiquot x = <: me < fun $ patt : x $ -> $ lid : x $ >> |
let test_antiquot2 x = <: me < let $ patt : x $ = 3 in $ lid : x $ >> |
let x = a |> generate_type_constraints |> rob |
let with_dump = with_access ~ from_dump ( : Filename . concat ( Sys . getcwd ( ) ) " lib_test / dump . data " ) |
let resident_pages ( ) = let with_channel c f = try let r = f c in close_in c ; r with exn -> close_in_noerr c ; raise exn in let statm = with_channel ( open_in " / proc / self / statm " ) input_line in Scanf . sscanf statm " % d % d % d % d % d % d % d " ( fun _ res _ _ _ _ ... |
let smoke_test ( ) = with_dump ( fun a -> let ( _ : Pci_dev . t list ) = get_devices a in ( ) ) |
let test_with_access_cleanup ( ) = let _ = Gc . compact ( ) ; resident_pages ( ) in for i = 1 to 6000 do with_dump ~ cleanup : true ( fun _ -> ( ) ) done ; let mem = Gc . compact ( ) ; resident_pages ( ) in for i = 1 to 1000 do with_dump ~ cleanup : true ( fun _ ... |
let test_lookup_functions ( ) = let test_lookup = assert_equal ~ printer ( : fun x -> x ) in with_dump ( fun acc -> test_lookup " Bridge " @@ lookup_class_name acc 0x0680 ; test_lookup " Intel Corporation " @@ lookup_vendor_name acc 0x8086 ; test_lookup " 82371AB / EB / MB PIIX4 ACP... |
let _ = let suite = " pci " >::: [ " smoke_test " >:: smoke_test ; " test_with_access_cleanup " >:: test_with_access_cleanup ; " test_lookup_functions " >:: test_lookup_functions ; ] in OUnit2 . run_test_tt_main @@ ounit2_of_ounit1 suite |
let string_of_group = function | Text s -> sp " Text % s " s | Delim s -> sp " Delim % s " s | Group ( x , s ) -> sp " Group ( % d % s ) " x s | NoGroup -> " NoGroup " |
let list_printer f xs = String . concat " ; " ( List . map f xs ) |
let test_blank_class _ = let re = Re . Perl . compile_pat " \\ d [ [ : blank ] ] :\\ d [ [ : blank ] ] [ :+ a - z ] " in let successes = [ " 1 2 a " ; " 2 \ t3 z " ; " 9 \ t0 \ t a " ] in let failures = [ " " ; " 123 " ; " " ; " 1 ... |
let rex = regexp " [ : _ ] " |
let split_empty _ = assert_equal ( full_split ~ rex " " ) [ ] |
let split_max_1 _ = assert_equal ( full_split ~ rex ~ max : 1 " xxx : yyy " ) [ Text " xxx : yyy " ] |
let rex = regexp " x ( x ) " ? |
let printer = list_printer string_of_group |
let group_split1 _ = let sp = full_split ~ rex " testxxyyy " in assert_equal ~ printer sp [ Text " test " ; Delim " xx " ; Group ( 1 , " x " ) ; Text " yyy " ] |
let group_split2 _ = let sp = full_split ~ rex " testxyyy " in assert_equal ~ printer sp [ Text " test " ; Delim " x " ; NoGroup ; Text " yyy " ] |
let test_fixtures = " test pcre features " >::: [ " test [ : blank ] : class " >:: test_blank_class ; " test splitting empty string " >:: split_empty ; " test split with max of 1 " >:: split_max_1 ; " test group split 1 " >:: group_split1 ; " test group split 2 - NoGroup ... |
let _ = run_test_tt_main test_fixtures |
( module Stable_unit_test . Make ( struct include Stable . V1 let equal = equal let tests = [ of_mult 0 . 375 , " 37 . 5 " , % " \ 000 \ 000 \ 000 \ 000 \ 000 \ 000 \ 216 " ? ; of_mult 4 . 5 , " 4 . 5x " , " \ 000 \ 000 \ 000 \ 000 \ 000 \ 0... |
let test raw_grammar = Sexp_grammar_validation . Raw_grammar . sexp_of_t raw_grammar |> Stdio . print_s ; ; test [ % sexp_grammar : < for_all : ' k ' v . ( ' k * ' v ) list > ] ; [ % expect { | ( ( generic_groups ( ( 6a84293b8771489e87de480107049eda ( ( implicit_... |
let eq_re ? opts r s = expect_equal_app ~ msg : s id r ( re ? opts ) s ; ; |
let parse_error_re ? opts s = try ignore ( re ? opts s ) ; OUnit2 . assert_failure s with | Re . Perl . Parse_error -> ( ) |
let _ = expect_pass " ordinary characters " ( fun ( ) -> eq_re ( char ' a ' ) " a " ; ) ; expect_pass " concatenation " ( fun ( ) -> eq_re ( seq [ char ' a ' ; char ' b ' ] ) " ab " ; ) ; expect_pass " escaping metacharacters " ( fun ( ) -... |
let base_dir_class_testable = Alcotest . ( testable Persistence . pp_base_dir_class ( = ) ) |
let check_base_dir s bd1 bd2 = Alcotest . check base_dir_class_testable s bd1 bd2 |
let test_classify_does_not_exist = let open Lwt_tzresult_syntax in Tztest . tztest " Classify a non existing directory " ` Quick ( fun ( ) -> Lwt_utils_unix . with_tempdir " test_persistence " ( fun base_dir -> let + bd = Persistence . classify_base_dir ( Filename . concat base_dir " ... |
let test_classify_is_file = let open Lwt_tzresult_syntax in Tztest . tztest " Classify a file " ` Quick ( fun ( ) -> let tmp_file = Filename . temp_file " " " " in let + bd = Persistence . classify_base_dir tmp_file in check_base_dir " A file " Base_dir_is_file bd ) |
let test_classify_is_mockup = let open Lwt_tzresult_syntax in Tztest . tztest " Classify a mockup directory " ` Quick ( fun ( ) -> Lwt_utils_unix . with_tempdir " test_persistence " ( fun dirname -> let mockup_directory = ( Files . get_mockup_directory ~ dirname :> string ) and mockup_... |
let test_classify_is_nonempty = let open Lwt_tzresult_syntax in Tztest . tztest " Classify a non empty directory " ` Quick ( fun ( ) -> Lwt_utils_unix . with_tempdir " test_persistence " ( fun temp_dir -> let _ = Filename . temp_file ~ temp_dir " " " " in let + bd = Persistence .... |
let test_classify_is_empty = let open Lwt_tzresult_syntax in Tztest . tztest " Classify an empty directory " ` Quick ( fun ( ) -> Lwt_utils_unix . with_tempdir " test_persistence " ( fun base_dir -> let + bd = Persistence . classify_base_dir base_dir in check_base_dir " An empty directory... |
module Mock_protocol : Registration . PROTOCOL = struct include Environment_protocol_T_test . Internal_for_tests . Mock_all_unit let hash = Protocol_hash . hash_string [ " " ] end |
module Mock_mockup : Registration . MOCKUP = struct type parameters = unit type protocol_constants = unit let parameters_encoding = Data_encoding . unit let default_parameters = ( ) let protocol_constants_encoding = Data_encoding . unit let default_protocol_constants _ = assert false let default_boot... |
let mock_mockup_module ( protocol_hash ' : Protocol_hash . t ) : ( module Registration . MOCKUP ) = ( module struct include Mock_mockup let protocol_hash = protocol_hash ' end ) |
let mock_printer ( ) = let rev_logs : string list ref = ref [ ] in object inherit Tezos_client_base . Client_context . simple_printer ( fun _channel log -> rev_logs := log :: ! rev_logs ; Lwt . return_unit ) method get_logs = List . rev ! rev_logs end |
let test_get_registered_mockup_no_env = let open Lwt_result_syntax in Tztest . tztest " get_registered_mockup fails when no environment was registered " ` Quick ( fun ( ) -> let module Registration = Registration . Internal_for_tests . Make ( ) in let module Persistence = Persistence . Inter... |
let test_get_registered_mockup_not_found = let open Lwt_result_syntax in Tztest . tztest " get_registered_mockup fails if the requested protocol is not found " ` Quick ( fun ( ) -> let module Registration = Registration . Internal_for_tests . Make ( ) in let module Persistence = Persistence . ... |
let test_get_registered_mockup_take_alpha = let open Lwt_result_syntax in Tztest . tztest " get_registered_mockup returns Alpha if none is specified " ` Quick ( fun ( ) -> let module Registration = Registration . Internal_for_tests . Make ( ) in let module Persistence = Persistence . Interna... |
let test_get_registered_mockup_take_requested = let open Lwt_result_syntax in Tztest . tztest " get_registered_mockup returns the requested protocol " ` Quick ( fun ( ) -> let module Registration = Registration . Internal_for_tests . Make ( ) in let module Persistence = Persistence . Interna... |
let ( ) = Alcotest_lwt . run " tezos - mockup " [ ( " persistence " , [ test_classify_does_not_exist ; test_classify_is_file ; test_classify_is_mockup ; test_classify_is_nonempty ; test_classify_is_empty ; test_get_registered_mockup_no_env ; test_get_registered_mockup_not_found ; t... |
module Hello = struct module Model = struct let name = " hello " type query = unit type response = unit end include Model include Versioned_rpc . Caller_converts . Rpc . Make ( Model ) module V1 = Register ( struct let version = 1 type query = unit [ @@ deriving bin_io ] type response = u... |
let ( ) = ( List . iter begin List . iter begin |
let print_row i row = printf " row % d : [ % s ] s \ n " i ( String . concat " ; " ( List . map ( function |
let print_rows rows = List . iteri print_row rows |
let print_params_description params = printf " params :\ n " ; List . iteri ( fun i param -> printf " parameter % d :\ n " i ; printf " type : % ld \ n " param . PGOCaml . param_type ) params |
let print_row_description results = match results with | None -> printf " this statement returns no data \ n " | Some results -> printf " results :\ n " ; List . iteri ( ) results |
let ( ) = let dbh = PGOCaml . connect ( ) in let query = " select current_timestamp " in let name = " timestamp_query " in ignore ( PGOCaml . prepare dbh ~ query ~ name ( ) ) ; let i = ref 0 in PGOCaml . cursor dbh ~ name ~ params [ ] : ( fun row -> incr i ; print_row ... |
let test_val ( ? nth = 0 ) ~ decode ~ expected filename ctxt = let file = fixture filename in let res = decode file in let ( public_packet : Packet . t ) = Result . get_ok ( List . nth res nth ) in assert_equal ~ printer [ :% show : Packet . Body . t ] ~ ctxt public_packet . pa... |
module Rsa = struct let public_packet = let expected_public = let n = Z . of_string " 0xfb4be4285f7bf636362c2a86b2680899c30d9d07851850b474e8db8d96743001917984e222e989751930c09c6c88dff8f17ecf8be3d4796bd18946ffae7be00a95055ad9d508225ce3dcec571a804fb15b34dcea1c52ec3720852a0c3c19a5772b7b2fa3c602209df84bd9756cacc040... |
module Dsa = struct let public_packet = let expected_public = let p = Z . of_string " 0xd93edd8915add1c50daa9f232b17be4b47e8af10d92505dbcd095a332f583c2a64176faa557e896a56e662e8fe72859edce012ca0977dff484a01d969376f46853b4f03a3c23829a2b5b1012b84fbe733d6e384d80ac7406581ae0524f69cf8580d25efd6d976a8756cad44bcbd5c3e3... |
module Elgamal = struct let public_packet = let expected_public = let p = Z . of_string " 0xd56ae8fb6b6bc0fc32e663a7a961607331bd7b41641a048516bfbbb7add148f1b3bffe7ce7544e29cd33c87cafd86b37e49e6d70273e53dcb0f7f3af63655a0c70f11dc4a7d397fbcd70a8666cffc8b6be3506960dcf091881e4faacf6c6530185431a4f96ed10a3e0ef35d9ccd9... |
let id_packet = Packet . Body . Id " Clement < clement @ test " > |
let id_packet2 = Packet . Body . Id " Dimitri Torterat < kra @ diti . me " > |
module Test_errors = struct let test_rsa_tag0 ctxt = let file = fixture " rsa_tag0 . pgp " in let res = decode file in let error = Result . get_error ( List . hd res ) in assert_equal ~ ctxt error " Tag 0 " let test_bad_algo ctxt = let file = fixture " bad_pub_algo . pgp " in let res =... |
module Signature = struct let signature ~ tag ~ id ( ? version = 4 ) ( ? revocation = [ ] ) ( ? key_flags = [ ] ) validity_period signature_type = let subpackets = List . concat [ key_flags ; validity_period |> Option . to_list |> List . map ( fun validity_period -> Packet... |
module Id = struct let test_id = test_val ~ nth : 1 ~ decode ~ expected : id_packet " rsa_public . pgp " let test_id2 = test_val ~ nth : 6 ~ decode ~ expected : id_packet2 " revocation_signature . pgp " let suite = [ " Id 1 " >:: test_id ; " Id 2 " >:: test_id2 ] end |
let test_marker = test_val ~ decode ~ expected : Packet . Body . Marker " test_marker . pgp " |
let suite = [ " Rsa " >::: Rsa . suite ; " Dsa " >::: Dsa . suite ; " Id " >::: Id . suite ; " Signatures " >::: Signature . suite ; " Marker " >:: test_marker ; " Errors " >::: Test_errors . suite ; " Elgamal " >::: Elgamal . suite ] |
let pp_value ppf x = Sexp . pp_hum ppf ( sexp_of_t x ) |
let equal_value ( x : t ) ( y : t ) = x = y |
let pp_hstore ppf x = Sexp . pp_hum ppf ( sexp_of_hstore x ) |
let equal_hstore x y = Sexp . equal ( sexp_of_hstore x ) ( sexp_of_hstore y ) |
let printer sexp value = sexp value |> Sexp . to_string_hum |
let sort_hstore = List . sort ( fun ( k , _ ) ( k ' , _ ) -> String . compare k k ' ) |
let to_hstore_sorted v = to_hstore v |> Option . map sort_hstore |
let to_hstore_sorted_exn v = to_hstore_exn v |> sort_hstore |
let pp_inet ppf ( addr , port ) = Format . fprintf ppf " % a :% d " Ipaddr . pp addr port |
let equal_inet ( a1 , p1 ) ( a2 , p2 ) = Ipaddr . compare a1 a2 = 0 && p1 = p2 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.