text stringlengths 0 601k |
|---|
module R = struct let filter_attrib ( name , a ) on = match a with | Xml . Event _ | Xml . MouseEvent _ | Xml . KeyboardEvent _ | Xml . TouchEvent _ -> raise ( Invalid_argument " filter_attrib not implemented for event handler " ) | Xml . Attr a -> name , Xml . Attr ( React . S . l2 ( fun on a -> if on then a else None... |
module Core_category = struct type t = [ ` Branch | ` Temporary | ` Permanent ] let default_category = ` Temporary let string_of_category = function | ` Permanent -> " permanent " | ` Temporary -> " temporary " | ` Branch -> " branch " let classify = function | ` Permanent -> Error_classification . Permanent | ` Tempor... |
let get_int32_string s off = Bytes . get_int32_be ( Bytes . unsafe_of_string s ) off |
let get_int8_string s off = Bytes . get_int8 ( Bytes . unsafe_of_string s ) off |
let get_int16_string s off = Bytes . get_int16_be ( Bytes . unsafe_of_string s ) off |
let get_int64_string s off = Bytes . get_int64_be ( Bytes . unsafe_of_string s ) off |
let get_uint8_string s off = Bytes . get_uint8 ( Bytes . unsafe_of_string s ) off |
let get_uint16_string s off = Bytes . get_uint16_be ( Bytes . unsafe_of_string s ) off |
let get_double buff i = Int64 . float_of_bits ( Bytes . get_int64_be buff i ) |
let get_double_string buff i = Int64 . float_of_bits ( Bytes . get_int64_be ( Bytes . unsafe_of_string buff ) i ) |
let set_double buff i v = Bytes . set_int64_be buff i ( Int64 . bits_of_float v ) |
let is_empty = function [ ] -> true | _ -> false |
let rev_sub l n = if n < 0 then invalid_arg " Utils . rev_sub : ` n ` must be non - negative . " ; let rec append_rev_sub acc l = function | 0 -> acc | n -> ( match l with | [ ] -> acc | hd :: tl -> append_rev_sub ( hd :: acc ) tl ( n - 1 ) ) in append_rev_sub [ ] l n |
let sub l n = rev_sub l n |> List . rev |
let rec remove nb = function | [ ] -> [ ] | l when nb <= 0 -> l | _ :: tl -> remove ( nb - 1 ) tl |
let rec repeat n x = if n <= 0 then [ ] else x :: repeat ( pred n ) x |
let split_n n l = let rec loop acc n = function | [ ] -> ( l , [ ] ) | rem when n <= 0 -> ( List . rev acc , rem ) | x :: xs -> loop ( x :: acc ) ( pred n ) xs in loop [ ] n l |
let take_n_unsorted n l = fst ( split_n n l ) |
let take_n_sorted ( type a ) compare n l = let module B = Bounded_heap . Make ( struct type t = a let compare = compare end ) in let t = B . create n in List . iter ( fun x -> B . insert x t ) l ; B . get t |
let take_n ? compare n l = match compare with | None -> take_n_unsorted n l | Some compare -> take_n_sorted compare n l |
let rec drop_n n l = if n <= 0 then l else match l with [ ] -> [ ] | _ :: xs -> drop_n ( n - 1 ) xs |
let select n l = let rec loop n acc = function | [ ] -> invalid_arg " Utils . select " | x :: xs when n <= 0 -> ( x , List . rev_append acc xs ) | x :: xs -> loop ( pred n ) ( x :: acc ) xs in loop n [ ] l |
let shift = function [ ] -> [ ] | hd :: tl -> tl @ [ hd ] |
let rec product a b = match a with | [ ] -> [ ] | hd :: tl -> List . map ( fun x -> ( hd , x ) ) b @ product tl b |
let shuffle ? rng_state l = let randint = match rng_state with | None -> Random . int | Some rng_state -> Random . State . int rng_state in let a = Array . of_list l in let len = Array . length a in for i = len downto 2 do let m = randint i in let n ' = i - 1 in if m <> n ' then ( let tmp = a . ( m ) in a . ( m ) <- a ... |
let index_of ( ? compare = Stdlib . compare ) item list = let rec find index = function | [ ] -> None | head :: tail -> if compare head item = 0 then Some index else find ( index + 1 ) tail in find 0 list |
let filter_some l = let rec go acc = function | [ ] -> List . rev acc | None :: xs -> go acc xs | Some x :: xs -> go ( x :: acc ) xs in go [ ] l |
let rec find_map f = function | [ ] -> None | x :: l -> ( match f x with None -> find_map f l | r -> r ) |
let fold_left_i f init l = List . fold_left ( fun ( i , accu ) x -> let accu = f i accu x in ( i + 1 , accu ) ) ( 0 , init ) l |> snd |
module List = struct include Tezos_stdlib . TzList include Tezos_error_monad . TzLwtreslib . List end |
module String = struct include String include Tezos_stdlib . TzString module Hashtbl = Tezos_error_monad . TzLwtreslib . Hashtbl . MakeSeeded ( struct type t = string let equal = String . equal let hash = Hashtbl . seeded_hash end ) end |
module Filename = struct include Stdlib . Filename include Tezos_stdlib . TzFilename end |
module Set = Set . Make ( String ) |
module Map = Map . Make ( String ) |
let split delim ( ? dup = true ) ( ? limit = max_int ) path = let l = String . length path in let rec do_slashes acc limit i = if i >= l then List . rev acc else if path . [ i ] = delim then if dup then do_slashes acc limit ( i + 1 ) else do_split acc limit ( i + 1 ) else do_split acc limit i and do_split acc limit i =... |
let split_path path = split ' ' / path |
let has_prefix ~ prefix s = let x = String . length prefix in let n = String . length s in n >= x && String . sub s 0 x = prefix |
let remove_prefix ~ prefix s = let x = String . length prefix in let n = String . length s in if n >= x && String . sub s 0 x = prefix then Some ( String . sub s x ( n - x ) ) else None |
let common_prefix s1 s2 = let last = min ( String . length s1 ) ( String . length s2 ) in let rec loop i = if last <= i then last else if s1 . [ i ] = s2 . [ i ] then loop ( i + 1 ) else i in loop 0 |
let mem_char s c = String . index_opt s c <> None |
let fold_left f init s = let acc = ref init in String . iter ( fun c -> acc := f ! acc c ) s ; ! acc |
let pp_bytes_hex fmt bytes = Hex . ( of_bytes bytes |> pp fmt ) |
let tztest ( name : string ) ( speed : Alcotest . speed_level ) ( f : unit -> ' a Lwt . t ) : unit Alcotest_lwt . test_case = Alcotest_lwt . test_case name speed ( fun _sw ( ) -> let open Lwt_syntax in let * r = f ( ) in match r with | Ok ( ) -> Lwt . return_unit | Error err -> let * ( ) = Tezos_base_unix . Internal_ev... |
let tztest_qcheck ~ name generator f = let ( name , speed , run ) = QCheck_alcotest . to_alcotest ( QCheck . Test . make ~ name generator @@ fun x -> match Lwt_main . run ( f x ) with | Ok _ -> true | Error err -> QCheck . Test . fail_reportf " @\ n % a . " @ pp_print_trace err ) in Alcotest_lwt . test_case name speed ... |
let mock_sink : Mock_sink . t Internal_event . sink_definition = ( module Mock_sink : Internal_event . SINK with type t = Mock_sink . t ) |
let with_empty_mock_sink ( f : unit -> unit Lwt . t ) : unit Lwt . t = let open Lwt_syntax in if not ( Mock_sink . is_activated ( ) ) then ( Internal_event . All_sinks . register mock_sink ; let * r = Internal_event . All_sinks . activate ( Uri . of_string " mock - log " ) :// in match r with | Ok _ -> f ( ) | Error er... |
let patch_env_loading ( ) = let open Tezos_base . TzPervasives in let preloaded_cmis : Persistent_env . Persistent_signature . t String . Hashtbl . t = Tezos_protocol_compiler . Compiler . preloaded_cmis in Persistent_env . Persistent_signature . load := fun ~ unit_name -> match String . Hashtbl . find preloaded_cmis (... |
let directive_string_fn fn_name = match Hashtbl . find_opt Toploop . directive_table fn_name with | Some ( Toploop . Directive_string fn ) -> fn | _ -> Printf . printf " Tztop failed to load due to an internal error \ n \ Unable to find directive % s \ n " fn_name ; exit ( - 1 ) |
let use_output command = directive_string_fn " use_output " command |
let load_stdlib ( ) = directive_string_fn " load " " stdlib . cma " |
let load_dune_libs directory = use_output @@ " dune top " ^ directory |
module Arg : sig type t val of_sys_argv : string array -> t option val get_working_directory : t -> string val to_toplevel_sys_argv : t -> string array type t = string array let of_sys_argv argv = if Array . length argv < 2 then None else Some Sys . argv let [ @ inline ] get_working_directory arg = arg . ( 1 ) let to_t... |
let ( ) = match Arg . of_sys_argv Sys . argv with | Some arg -> let directory = Arg . get_working_directory arg in let directory_does_exist = try Sys . is_directory directory with _ -> false in if not directory_does_exist then ( Printf . printf " stdout :% s is either not a directory or doesn ' t exist \ n " directory ... |
type ' err trace = ' err list |
let make err = [ err ] |
let cons err trace = err :: trace |
let cons_list err errs = err :: errs |
let conp trace _trace = trace |
let conp_list tr _trs = tr |
let pp_print pp_error ppf = function | [ ] -> assert false | [ error ] -> Format . fprintf ppf " [ @< v 2 > Error :@ % a ] . " @@ pp_error error | error :: _ as errors -> Format . fprintf ppf " [ @< v 2 > Error :@ % a , @ trace :@ % a ] . " @@ pp_error error ( Format . pp_print_list pp_error ) ( List . rev errors ) |
let pp_print_top pp_error fmt = function | [ ] -> assert false | error :: _ -> pp_error fmt error |
let encoding error_encoding = Data_encoding . list error_encoding |
let ipv4 = map ~ rev : Ipaddr . V4 . to_int32 Ipaddr . V4 . of_int32 int32 |> set_print Ipaddr . V4 . to_string |
let ipv6 = map ~ rev : Ipaddr . V6 . to_int64 Ipaddr . V6 . of_int64 ( pair int64 int64 ) |> set_print Ipaddr . V6 . to_string |
let ipv4_as_v6 = let open QCheck in map Ipaddr . v6_of_v4 ipv4 |> set_print Ipaddr . V6 . to_string |
let addr_port_id = let gen = let open Gen in let open P2p_point . Id in let * addr = map Ipaddr . V4 . to_string @@ gen ipv4 and * port = opt @@ gen Lib_test . Qcheck_helpers . uint16 in pure { addr ; port ; peer_id = None } in make gen ~ print : P2p_point . Id . addr_port_id_to_string |
let port_opt = QCheck . option port |
let peer_id = QCheck . option QCheck . ( map P2p_identity . generate_with_pow_target_0 unit ) |
let ip = QCheck . choose [ ipv4_as_v6 ; ipv6 ] |
let ipv4_as_v6_or_v6 = QCheck . choose [ ipv4_as_v6 ; ipv6 ] |
let ipv4t = QCheck . triple ipv4 port_opt peer_id |
let ipv6t = QCheck . triple ipv6 port_opt peer_id |
let p2p_point_id_t = QCheck . pair ip port |
let ae = assert_equal ~ printer ( : fun x -> x ) x |
let pqi ( d : ( ' a , ' b ) ' b S . statement ) statement = d . S . sql_statement |
let pq ( d : ( ' a , ' b , ' c ) ' c S . expression ) expression = pqi d . S . statement |
let test_sql _ = let s = pqi [ % sql " insert into values ( values % s { sfoo } sfoo , % s { sbar } sbar ) sbar ] " in ae " insert into values ( values { ? foo } foo , { ? bar } bar ) bar " s ; let s = pq [ % sql " @ d { dkilroy } dkilroy was @ s { shere } shere ] " in ae " kilroy was here " s ; let s = pq [ % sql " se... |
let test_quotes _ = let s = pq [ % sql " strftime ( strftime ' % s -% d ' , % s -% d @ s { sabc } sabc % d { ddef } ddef ' @ s { sabc } sabc % d { ddef } ddef ' ) ddef ' ] " in ae " strftime ( strftime ' % s -% d ' , ?-? abc { ? def } def ' @ s { sabc } sabc % d { ddef } ddef ' ) ddef ' " s ; let s = pq [ % sql { sql |... |
let tests = " ppx_tests " >::: [ " test_sql " >:: test_sql ; " test_quotes " >:: test_quotes ; ] |
let _ = run_test_tt_main tests |
let aeq_int = assert_equal ~ printer ( : sprintf " % d ) " |
let aeq_str = assert_equal ~ printer ( : sprintf " % S ) " |
let aeq_float = assert_equal ~ printer ( : sprintf " % f ) " |
let aeq_int32 = assert_equal ~ printer ( : sprintf " % ld ) " |
let aeq_int64 = assert_equal ~ printer ( : sprintf " % Ld ) " |
let aeq_bool = assert_equal ~ printer : string_of_bool |
let aeq_list ~ printer = assert_equal ~ printer ( : fun l -> [ " " ^ String . concat " ; " ( List . map printer l ) l ^ " ] ) " |
module Test ( Lwt : sig include Sqlexpr_concurrency . THREAD val iter : ( ' a -> unit t ) t -> ' a list -> unit t val run : ' a t -> ' a end ) end ( Sqlexpr : sig include Sqlexpr_sqlite . S with type ' a result = ' a Lwt . t end ) end = struct open Lwt module S = Sqlexpr let ( ) >|= f g = bind f ( fun x -> return ( g x... |
let test_lwt_recursive_mutex ( ) = let module M = Sqlexpr_concurrency . Lwt in let mv = Lwt_mvar . create ( ) in let m = M . create_recursive_mutex ( ) in let l = ref [ ] in let push x = l := x :: ! l ; return ( ) in lwt n = M . with_lock m ( fun ( ) -> M . with_lock m ( fun ( ) -> return 42 ) 42 ) 42 in aeq_int 42 n ;... |
module type S_LWT = Sqlexpr_sqlite . S with type ' a result = ' a Lwt . t |
let with_db ( type a ) a ( module S : S_LWT with type db = a ) a ( ? in_mem = true ) true f x = let file = if in_mem then " : memory " : else Filename . temp_file " t_sqlexpr_sqlite_ " " " in let db = S . open_db file in try_lwt f db x finally S . close_db db ; if not in_mem then Sys . remove file ; return ( ) |
let test_exclusion ( type a ) a ( ( module S : S_LWT with type db = a ) a as s ) s ( ) = let module Sqlexpr = S in with_db s ~ in_mem : false begin fun db ( ) -> S . execute db sql " CREATE TABLE foo ( foon INTEGER NOT NULL ) NULL " >>= fun ( ) -> let exclusion_between_tx_and_single_stmt ( ) = let t1 , u1 = Lwt . wait ... |
module IdConc = struct include Sqlexpr_concurrency . Id let iter = List . iter let run x = x end |
module LwtConc = struct include Sqlexpr_concurrency . Lwt let run x = Lwt_main . run ( Lwt . pick [ x ; Lwt_unix . timeout 1 . 0 ] 0 ) 0 let iter = Lwt_list . iter_s end |
let lwt_run f ( ) = LwtConc . run ( f ( ) ) |
let all_tests = [ " Sqlexpr_concurrency . Lwt . with_lock " >:: lwt_run test_lwt_recursive_mutex ; ( let module M = Test ( TestIdConc ) TestIdConc ( TestIdConcSqlexpr_sqlite . Make ( MakeIdConc ) MakeIdConc ) MakeIdConc in " Sqlexpr_sqlite . Make ( MakeSqlexpr_concurrency . Id ) Id " >::: M . all_tests false ) false ; ... |
let _ = run_test_tt_main ( " All " >::: all_tests ) all_tests |
type t = { version : string ; application_id : string ; } |
let create application_id = { version = " U2F_V2 " ; application_id } |
type protocol_error = [ ` Other_error | ` Bad_request | ` Configuration_unsupported | ` Device_ineligible | ` Timeout | ` Unrecognized of int ] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.