text stringlengths 12 786k |
|---|
let while_parse_tests = [ " test_while " >:: test_compare_asts while_tokens while_ast ; " test_while_block " >:: test_compare_asts while_block_tokens while_block_ast ; " test_do_while " >:: test_compare_asts do_while_tokens do_while_ast ; " test_do_while_block " >:: test_compare_asts do_whi... |
let make_foo_decl params = FunDecl { fun_type = IntType ; name = ID " foo " ; params ; body = Some [ ] } |
let make_fun_call_program params args = let foo_decl = make_foo_decl params in let fun_call = FunCall ( ID " foo " , args ) in let main_body = [ Statement ( ReturnVal fun_call ) ] in let main_decl = FunDecl { fun_type = IntType ; name = ID " main " ; params [ ] ; = body = Some... |
let make_param name = Param ( IntType , ID name ) |
let fun_tokens = Lex . lex " int foo ( ) { } int main ( ) { return foo ( ) ; } " |
let fun_ast = make_fun_call_program [ ] [ ] |
let fun_args_tokens = Lex . lex " int foo ( int a ) { } int main ( ) { return foo ( 5 ) ; } " |
let fun_args_ast = let foo_params = [ make_param " a " ] in let foo_args = [ make_int 5 ] in make_fun_call_program foo_params foo_args |
let fun_arg_exp_tokens = Lex . lex " int foo ( int a ) { } int main ( ) { return foo ( a + 5 ) ; } " |
let fun_arg_exp_ast = let foo_params = [ make_param " a " ] in let arg_exp = BinOp ( Add , Var ( ID " a " ) , make_int 5 ) in make_fun_call_program foo_params [ arg_exp ] |
let fun_call_standalone = " int main ( ) { incr ( b ) ; } " |
let fun_call_parse_tests = [ " test_simple_call " >:: test_compare_asts fun_tokens fun_ast ; " test_call_with_args " >:: test_compare_asts fun_args_tokens fun_args_ast ; " test_call_with_complex_arg " >:: test_compare_asts fun_arg_exp_tokens fun_arg_exp_ast ; ] |
let missing_semicolon = Lex . lex " int main ( ) { return 2 } " |
let incomplete_addition = Lex . lex " int main ( ) { return 2 ; } " + |
let mismatched_parens = Lex . lex " int main ( ) { return ( ( 1 ) ; } " |
let mismatched_right_parens = Lex . lex " int main ( ) { return ( 1 ) ) ; } " |
let one_paren = Lex . lex " int main ( ) { return ( 1 ; } " |
let backwards_parens = Lex . lex " int main ( ) { return ) 1 + 2 ; } " |
let failure_parse_tests = [ " test_parse_fail " >:: test_expect_failure bad_token_list " Parse error in parse_fun : bad function type or name " ; " test_semicolon_required " >:: test_expect_failure missing_semicolon " Expected semicolon after return statement " ; " test_incomplete_addition "... |
let parse_tests = basic_parse_tests @ unop_parse_tests @ binop_parse_tests @ boolean_binop_tests @ bitwise_binops_tests @ comp_parse_tests @ variable_parse_tests @ conditional_parse_tests @ fun_call_parse_tests @ for_parse_tests @ while_parse_tests @ failure_parse_tests |
let assert_tokenize ~ loc given expected = match Micheline_parser . tokenize given with | ( tokens , [ ] ) -> let tokens_got = List . map ( fun x -> x . Micheline_parser . token ) tokens in Assert . equal_tokens ~ loc tokens_got expected | ( _ , _ ) -> failwith " % s - Canno... |
let assert_tokenize_error ~ loc given forbidden_tokens = match Micheline_parser . tokenize given with | ( tokens , [ ] ) -> let tokens_got = List . map ( fun x -> x . Micheline_parser . token ) tokens in Assert . not_equal_tokens ~ loc tokens_got forbidden_tokens | ( _ , _ ) -> ... |
let test_tokenize_basic ( ) = let * ( ) = assert_tokenize ~ loc : __LOC__ " " \ abc " " \ [ String " abc " ] in let * ( ) = assert_tokenize ~ loc : __LOC__ " " \ abc \ t " " \ [ String " abc \ t " ] in let * ( ) = assert_tokenize ~ loc : __LOC__ " ... |
let test_one_line_contract ( ) = let * ( ) = assert_tokenize ~ loc : __LOC__ " ( option int ) " [ Open_paren ; Ident " option " ; Ident " int " ; Close_paren ] in let * ( ) = assert_tokenize ~ loc : __LOC__ " DIP { ADD } " [ Ident " DIP " ; Open_brace ; ... |
let test_condition_contract ( ) = let * ( ) = assert_tokenize ~ loc : __LOC__ " parameter ( or string ( option int ) ) ; storage unit ; return string ; code \ { CAR ; IF_LEFT { } { IF_NONE { FAIL } { PUSH int 0 ; CMPGT ; IF { FAIL } { PUSH string \ " " } ... |
let assert_toplevel_parsing ~ loc source expected = match Micheline_parser . tokenize source with | ( _ , _ :: _ ) -> failwith " % s - Cannot tokenize % s " loc source | ( tokens , [ ] ) -> ( match Micheline_parser . parse_toplevel tokens with | ( _ , _ :: _ ) -> failw... |
let assert_toplevel_parsing_error ~ loc source forbidden_tokens = match Micheline_parser . tokenize source with | ( _ , _ :: _ ) -> return_unit | ( tokens , [ ] ) -> ( match Micheline_parser . parse_toplevel tokens with | ( _ , _ :: _ ) -> return_unit | ( ast , [ ] )... |
let test_basic_parsing ( ) = let * ( ) = assert_toplevel_parsing ~ loc : __LOC__ " parameter unit ; " [ Prim ( ( ) , " parameter " , [ Prim ( ( ) , " unit " , [ ] , [ ] ) ] , [ ] ) ] in let * ( ) = assert_toplevel_parsing ~ loc : __LOC_... |
let test_condition_contract_parsing ( ) = assert_toplevel_parsing ~ loc : __LOC__ " parameter unit ; return unit ; storage tez ; # How much you have to send me \ n \ code { CDR ; DUP ; AMOUNT ; CMPLT ; IF { FAIL } } " [ Prim ( ( ) , " parameter " , [ Prim ( ( )... |
let test_list_append_parsing ( ) = assert_toplevel_parsing ~ loc : __LOC__ " parameter ( pair ( list int ) ( list int ) ) ; return ( list int ) ; storage unit ; code \ { CAR ; DUP ; DIP { CDR } ; CAR ; NIL int ; SWAP ; LAMBDA ( pair int ( list int ) ) ( list ... |
let assert_expression_parsing ~ loc source expected = match Micheline_parser . tokenize source with | ( _ , _ :: _ ) -> failwith " % s - Cannot tokenize % s " loc source | ( tokens , [ ] ) -> ( match Micheline_parser . parse_expression tokens with | ( _ , _ :: _ ) -> f... |
let test_parses_expression ( ) = let * ( ) = assert_expression_parsing ~ loc : __LOC__ " Pair False " \ abc " " \ ( Prim ( ( ) , " Pair " , [ Prim ( ( ) , " False " , [ ] , [ ] ) ; String ( ( ) , " abc " ) ] , [ ] ) ) in let... |
let tests = [ ( " tokenize " , fun _ -> test_tokenize_basic ( ) ) ; ( " test one line contract " , fun _ -> test_one_line_contract ( ) ) ; ( " test_condition_contract " , fun _ -> test_condition_contract ( ) ) ; ( " test_basic_parsing " , fun _ -> test_... |
let wrap ( n , f ) = Alcotest . test_case n ` Quick ( fun ( ) -> match f ( ) with Ok ( ) -> ( ) | Error err -> Stdlib . failwith err ) |
let ( ) = Alcotest . run ~ argv [ " " ] :|| " tezos - lib - micheline " [ ( " micheline " , List . map wrap tests ) ] |
let test s = Single . parse_string s |> [ % sexp_of : ( Sexp . t , Parse_error . t ) Result . t ] |> print_s ; ; test " ( abc " ; [ % expect { | ( Error ( ( position ( ( line 1 ) ( col 4 ) ( offset 4 ) ) ) ( message " unclosed parentheses at end of... |
let parse_eager_cst ~ no_sexp_is_error str = let r = ref [ ] in let state = Eager_cst . State . create ~ no_sexp_is_error ( fun _ v -> r := v :: ! r ) in Result . try_with ( fun ( ) -> let stack = Eager_cst . Stack . empty in let stack = Eager_cst . feed_string state str stack in ... |
let parse_eager_cst_no_sexp_is_error = parse_eager_cst ~ no_sexp_is_error : true |
let parse_eager_cst = parse_eager_cst ~ no_sexp_is_error : false missing comments or assertion failures ) " = let test s = parse_eager_cst s |> [ % sexp_of : ( Cst . t_or_comment list , exn ) Result . t ] |> print_s in test " ; " ; [ % expect { | ( Ok ( ( Comment ( Plain... |
let rec hot_loop state stream stack = match Stream . peek stream with | None -> P . feed_eoi state stack | Some char -> let stack = P . feed state char stack in Stream . junk stream ; hot_loop state stream stack ; ; |
let fetch_sexp ( stream : char Stream . t ) = let got_sexp _state sexp = Exn . raise_without_backtrace ( Got_sexp sexp ) in let count = Stream . count stream in let state = P . State . create got_sexp in match hot_loop state stream P . Stack . empty with | ( ) -> None | exception Got_... |
let iter_sexps ( stream : char Stream . t ) ~ f = let got_sexp _state sexp = f sexp in let state = P . State . create got_sexp in hot_loop state stream P . Stack . empty ; ; |
let input = { | } | let stream = Stream . of_string input in let rec loop stream = match fetch_sexp stream with | None -> assert ( Option . is_none ( Stream . peek stream ) ) | Some sexp -> Caml . Format . printf " got : % a . " @ Sexp . pp_hum sexp ; loop stream in loop stre... |
let all_short_strings ( ) = let all_chars = [ ' \ 000 ' ; ' \ 001 ' ; ' \ t ' ; ' ' ; ' \ n ' ; ' \ 012 ' ; ' \ r ' ; ' " ' ; ' ' # ; ' ( ' ; ' ) ' ; ' 8 ' ; ' ; ' ; ' A ' ; ' b ' ; ' ' \\ ; ' x... |
let test input = Single_just_positions . parse_string input |> Result . map ~ f : Positions . to_list |> [ % sexp_of : ( Positions . pos list , Parse_error . t ) Result . t ] |> print_s ; ; |
let test_many input = Many_just_positions . parse_string input |> Result . map ~ f : Positions . to_list |> [ % sexp_of : ( Positions . pos list , Parse_error . t ) Result . t ] |> print_s ; ; test " ( 1 2 3 ) " ; [ % expect { | ( Ok ( ( ( line 1 ) ( col... |
type ' a conv_result = ( ' a , Conv_error . t ) Result . t [ @@ deriving sexp_of ] |
let test a_of_sexp input = match Conv_single . parse_string input a_of_sexp with | Ok _ -> ( ) | Error error -> Conv_error . report Caml . Format . std_formatter error ~ filename " :< string " > ; ; |
let test_many a_of_sexp input = match Conv_many . parse_string input a_of_sexp with | Ok _ -> ( ) | Error error -> Conv_error . report Caml . Format . std_formatter error ~ filename " :< string " > ; ; test [ % of_sexp : int list ] { | [ % expect { | File " < string " , ... |
let assoc s = Lexer . assoc ( Eager . Lexbuf_consumer . create ( ) ) ( Lexing . from_string s ) |> [ % sexp_of : ( string * Sexp . t ) list ] |> print_s ; ; |
let sexps s = let lexbuf = Lexing . from_string s in let p = Eager . Lexbuf_consumer . create ( ) in let rec loop ( ) = match Eager . Lexbuf_consumer . parse_opt p lexbuf with | None -> [ ] | Some sexp -> sexp :: loop ( ) in loop ( ) |> List . iter ~ f : print_s ; ; assoc... |
let bake_and_endorse_once ( b_pred , b_cur ) baker endorser = let open Context in Context . get_endorsers ( B b_cur ) >>=? fun endorsers_list -> List . find_map ( function | { Plugin . RPC . Validators . delegate ; slots ; _ } -> if Signature . Public_key_hash . equal delegate en... |
let test_participation ~ sufficient_participation ( ) = let n_accounts = 2 in Context . init ~ consensus_threshold : 1 n_accounts >>=? fun ( b0 , accounts ) -> Context . get_constants ( B b0 ) >>=? fun csts -> let blocks_per_cycle = Int32 . to_int csts . parametric . blocks_per_cycle... |
let test_participation_rpc ( ) = let n_accounts = 2 in Context . init ~ consensus_threshold : 1 n_accounts >>=? fun ( b0 , accounts ) -> let ( account1 , account2 ) = match accounts with a1 :: a2 :: _ -> ( a1 , a2 ) | _ -> assert false in Context . Contract . pkh account1 >>... |
let tests = [ Tztest . tztest " test insufficient participation " ` Quick ( test_participation ~ sufficient_participation : false ) ; Tztest . tztest " test minimal participation " ` Quick ( test_participation ~ sufficient_participation : true ) ; Tztest . tztest " test participat... |
let test_primitives_are_passable _ = let _ = void @-> returning void and _ = char @-> returning char and _ = schar @-> returning schar and _ = float @-> returning float and _ = double @-> returning double and _ = int @-> returning int and _ = nativeint @-> returning nativeint and _ = int8_t @-... |
let test_unions_are_not_passable _ = let module M = struct type u let u : u union typ = union " u " let ( ) -: ty label = field u label ty let c = int -: " c " let f = double -: " f " let p = ptr u -: " p " let ( ) = seal u let _ = begin ignore ( u @-> returning void ) ; a... |
let test_ldouble_not_passable _ = assert_raises ~ msg " : Foreign rejects ldouble type as argument " ( Unsupported " libffi does not support passing long double " ) ( fun ( ) -> Foreign . funptr ( ldouble @-> returning void ) ) ; assert_raises ~ msg " : Foreign rejects ldouble type... |
let test_complex_value_passability _ = ignore ( complex32 @-> returning void ) ; ignore ( complex64 @-> returning void ) ; ignore ( complexld @-> returning void ) ; assert_raises ~ msg " : Foreign rejects complex32 type as argument " ( Unsupported " libffi does not support passing float... |
let test_arrays_are_not_passable _ = assert_raises ~ msg " : Array type rejected as argument " ( Unsupported " Unsupported argument type " ) ( fun ( ) -> array 1 int @-> returning void ) ; assert_raises ~ msg " : Array type rejected as return type " ( Unsupported " Unsupported ret... |
let test_bigarrays_are_not_passable _ = assert_raises ~ msg " : bigarray type rejected as argument " ( Unsupported " Unsupported argument type " ) ( fun ( ) -> bigarray genarray [ | 1 ] | Bigarray_compat . int @-> returning void ) ; assert_raises ~ msg " : bigarray1 type rejecte... |
let test_pointers_are_passable _ = let _ = ptr void @-> returning ( ptr void ) and _ = ptr int @-> returning ( ptr int ) and _ = ptr ( ptr int ) @-> returning ( ptr ( ptr int ) ) in let module M = struct type s1 and u let s1 : s1 structure typ = structure " s1 " let _ = field s1 ... |
let test_function_pointers_are_passable _ = ignore ( Foreign . funptr ( int @-> returning int ) @-> returning ( Foreign . funptr ( int @-> returning int ) ) ) |
let test_abstract_values_are_not_passable _ = begin assert_raises ~ msg " : Abstract type rejected as argument " ( Unsupported " Unsupported argument type " ) ( fun ( ) -> ( abstract ~ name " : abstract " ~ size : 1 ~ alignment : 1 ) @-> returning void ) ; assert_raises ~ ms... |
let test_struct_passability _ = let module M = struct type s1 and s2 and s3 and s4 and s5 and s6 and u let s1 : s1 structure typ = structure " s1 " let ( ) -: ty label = field s1 label ty let _ = int -: " _ " let _ = double -: " _ " let _ = ptr s1 -: " _ " let _ = Foreign . fu... |
let test_incomplete_passability _ = let s = structure " incomplete " and u = union " incomplete " in begin assert_raises IncompleteType ( fun ( ) -> s @-> returning void ) ; assert_raises IncompleteType ( fun ( ) -> void @-> returning s ) ; assert_raises IncompleteType ( fun ( ) ... |
let test_ocaml_values_are_not_passable_when_releasing_the_lock _ = begin assert_raises ( Unsupported " Unsupported argument type when releasing runtime lock " ) ( fun ( ) -> Foreign . foreign " puts " ( ocaml_string @-> returning int ) ~ release_runtime_lock : true ) ; let module Bindi... |
let suite = " Passability tests " >::: [ " primitives are passable " >:: test_primitives_are_passable ; " unions are not passable " >:: test_unions_are_not_passable ; " complex values passability " >:: test_complex_value_passability ; " long doubles are not passble " >:: test_ldouble_n... |
let _ = run_test_tt_main suite |
let testlib = Dl . ( dlopen ~ filename " : clib / libtest_functions . so " ~ flags [ : RTLD_NOW ] ) |
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_passing_strings _ = let input = " abcdefghijklmnopqrstuvwxyz " in let len = String . length input in let buf = String . make... |
let test_ocaml_types_rejected_as_pointer_reference_types _ = assert_raises IncompleteType ( fun ( ) -> allocate ocaml_string ( ocaml_string_start " " ) ) |
let strdup = if Sys . os_type = " Win32 " then " _strdup " else " strdup " |
let test_ocaml_types_rejected_as_return_types _ = assert_raises IncompleteType ( fun ( ) -> Foreign . foreign strdup ( string @-> returning ocaml_string ) ) |
let test_pointers_to_ocaml_types_cannot_be_dereferenced _ = let p = allocate_n char 10 in let po = coerce ( ptr char ) ( ptr ocaml_string ) p in begin assert_raises IncompleteType ( fun ( ) -> !@ po ) ; assert_raises IncompleteType ( fun ( ) -> po <-@ ocaml_string_start " " ) ; ... |
let test_no_higher_order_ocaml_string_support _ = begin assert_raises IncompleteType ( fun ( ) -> funptr ( void @-> returning ocaml_string ) ) end |
let suite = " Tests passing OCaml values " >::: [ " passing strings ( foreign ) " >:: Foreign_tests . test_passing_strings ; " passing strings ( stubs ) " >:: Stub_tests . test_passing_strings ; " pointer arithmetic on OCaml values ( foreign ) " >:: Foreign_tests . test_poin... |
let _ = run_test_tt_main suite |
let password str = Password_hash . Bytes . wipe_to_password ( Bytes . of_string str ) str |
let test_derive_secret_box_keys ctxt = let pw = password " Correct Horse Battery Staple " in let pw ' = password " Correct Battery Horse Staple " in let n = Password_hash . random_salt ( ) in let n ' = Password_hash . random_salt ( ) in let derive_interactive = Secret_box . derive_key Passw... |
let test_password_hashing ctxt = let pw = password " Correct Horse Battery Staple " in let pw ' = password " Correct Battery Horse Staple " in let h = Password_hash . Bytes . hash_password Password_hash . interactive pw in assert_bool " " = ( Password_hash . Bytes . verify_password_hash h pw ) ... |
let suite = " Password_hash " >::: [ " test_password_hashing " >:: test_password_hashing ; " test_derive_secret_box_keys " >:: test_derive_secret_box_keys ; ] |
let eqp = eq ~ eq : Pat . equal ~ pp : Pat . pp |
let string_conv = test " Pat . { v , of_string , to_string } " @@ fun ( ) -> let trip p = eq_str p Pat . ( to_string ( v p ) ) in app_invalid ~ pp : Pat . pp Pat . v " ( " ; $ app_invalid ~ pp : Pat . pp Pat . v " ( $ a " ; app_invalid ~ pp : Pat . pp Pa... |
let dom = test " Pat . dom " @@ fun ( ) -> let eq s l = eq ~ eq : String . Set . equal ~ pp : String . Set . dump ( Pat . ( dom @@ v s ) ) ( String . Set . of_list l ) in eq " bla " [ ] ; eq " bla ha " $$ [ ] ; eq " hey ( $ bla ) " [ " bla "... |
let subst = test " Pat . subst " @@ fun ( ) -> let eq ? undef defs p s = eq_str Pat . ( to_string @@ subst ? undef defs ( v p ) ) s in let defs = String . Map . of_list [ " bli " , " bla " ] in let undef = function " blu " -> Some " bla " $ | _ -> None in eq ... |
let format = test " Pat . format " @@ fun ( ) -> let eq ? undef defs p s = eq_str ( Pat . ( format ? undef defs ( v p ) ) ) s in let defs = String . Map . of_list [ " hey " , " ho " ; " hi " , " ha " ] $ in let undef = fun _ -> " undef " in eq ~ unde... |
let matches = test " Pat . matches " @@ fun ( ) -> let m p s = Pat . ( matches ( v p ) s ) in eq_bool ( m " ( $ mod ) . mli " " string . mli " ) true ; eq_bool ( m " ( $ mod ) . mli " " string . mli " ) false ; eq_bool ( m " ( $ mod ) . ml... |
let query = test " Pat . query " @@ fun ( ) -> let u ? init p s = Pat . ( query ? init ( v p ) s ) in let eq = eq_option ~ eq ( : String . Map . equal String . equal ) ~ pp ( : String . Map . dump String . dump ) in let eq ? init p s = function | None -> eq ( u ... |
let suite = suite " Pat module " [ string_conv ; dom ; subst ; format ; matches ; query ; ] |
module Patdiff_core = Patdiff_core . Without_unix ( module struct let prev : Diff_input . t = { name = " old " ; text = " Foo bar buzz " } let next : Diff_input . t = { name = " old " ; text = " Foo buzz " } let % expect_test " Ansi output generates a single line diff " ... |
let links = ( " . . . . // bin / patdiff - git - wrapper " , ` In_path_as , " patdiff - git - wrapper " ) :: links ; ; within_temp_dir ~ links ( fun ( ) -> let % bind ( ) = run " git " [ " init " ; " - q " ] in let % bind ( ) = Writer . save... |
let test_resolve_local_file ( ) = let tests = [ ( " full URL simple " , " / foo / bar / baz " , " https :// example . com / images / buzz " , " / foo / bar / baz / images / buzz " ) ; ( " full URL cwd " , " / foo / bar / baz " , " https :// example . ... |
let ( ) = Printexc . record_backtrace true |
let ( ) = Alcotest . run " test_path " [ ( " Path " , [ ( " Check resolve_local_file " , ` Quick , test_resolve_local_file ) ] ) ; ] |
let a = Array . make 10 0 |
let f ( ) = a ( . 11 ) 11 |
let f2 x = match x with | 0 -> 1 | 1 -> 2 | 2 -> 3 |
let f3 = function | 0 -> 1 | 1 -> 2 | 3 -> 4 |
let main = h ( ) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.