text
stringlengths
0
601k
type r3 = int Stdlib . ref ref [ @@ deriving show ] show
type l = int list [ @@ deriving show ] show
type a = int array [ @@ deriving show ] show
type o = int option [ @@ deriving show ] show
type f = int -> int [ @@ deriving show ] show
type y = int lazy_t [ @@ deriving show ] show
let test_alias ctxt = assert_equal ~ printer " 1 " ( show_a1 1 ) 1 ; assert_equal ~ printer " 1l " ( show_a2 1l ) 1l ; assert_equal ~ printer " 1L " ( show_a3 1L ) 1L ; assert_equal ~ printer " 1n " ( show_a4 1n ) 1n ; assert_equal ~ printer " 1 . " ( show_a5 1 ) . ; assert_equal ~ printer " true " ( show_a6 true ) tru...
type v = Foo | Bar of int * string | Baz of string [ @@ deriving show ] show
let test_variant ctxt = assert_equal ~ printer " Test_deriving_show . Foo " ( show_v Foo ) Foo ; assert_equal ~ printer ( " Test_deriving_show . Bar ( 1 , " \ foo ) ) " " \ ( show_v ( Bar ( 1 , " foo ) ) ) " ; assert_equal ~ printer ( " Test_deriving_show . Baz " \ foo ) " " \ ( show_v ( Baz " foo ) ) "
type rv = RFoo | RBar of { x : int ; y : string } | RBaz of { z : string } [ @@ deriving show ] show
let test_rv_record ctxt = assert_equal ~ printer " Test_deriving_show . RFoo " ( show_rv RFoo ) RFoo ; assert_equal ~ printer " Test_deriving_show . RBar { x = 1 ; y = " \ foo } " " \ ( show_rv ( RBar { x = 1 ; y " = foo } ) ) " ; assert_equal ~ printer " Test_deriving_show . RBaz { z = " \ foo } " " \ ( show_rv ( RBaz...
type vn = Foo of int option [ @@ deriving show ] show
let test_variant_nest ctxt = assert_equal ~ printer ( " Test_deriving_show . Foo ( Some 1 ) 1 ) 1 " ( show_vn ( Foo ( Some 1 ) 1 ) 1 ) 1
type pv1 = [ ` Foo | ` Bar of int * string ] [ @@ deriving show ] show
let test_poly ctxt = assert_equal ~ printer " ` Foo " ( show_pv1 ` Foo ) Foo ; assert_equal ~ printer " ` Bar ( ( 1 , " \ foo ) ) " " \ ( show_pv1 ( ` Bar ( 1 , " foo ) ) ) "
type pv2 = [ ` Baz | pv1 ] [ @@ deriving show ] show
let test_poly_inherit ctxt = assert_equal ~ printer " ` Foo " ( show_pv2 ` Foo ) Foo ; assert_equal ~ printer " ` Baz " ( show_pv2 ` Baz ) Baz
type ty = int * string [ @@ deriving show ] show
let test_tuple ctxt = assert_equal ~ printer ( " 1 , " \ foo ) " " \ ( show_ty ( 1 , " foo ) ) "
type re = { f1 : int ; f2 : string ; f3 : float [ @ opaque ] opaque ;
let test_record ctxt = assert_equal ~ printer { " Test_deriving_show . f1 = 1 ; f2 = " \ foo " ; \ f3 = < opaque > } " ( show_re { f1 = 1 ; f2 = " foo " ; f3 = 1 . 0 } )
type variant = Foo of { f1 : int ; f2 : string ; f3 : float [ @ opaque ] opaque ;
let test_variant_record ctxt = assert_equal ~ printer " Test_deriving_show . Foo { f1 = 1 ; f2 = " \ foo " ; \ f3 = < opaque } " > ( show_variant ( Foo { f1 = 1 ; f2 = " foo " ; f3 = 1 . 0 } ) )
module M : sig type t = A [ @@ deriving show ] show type t = A [ @@ deriving show ] show end
let test_module ctxt = assert_equal ~ printer " Test_deriving_show . M . A " ( M . show M . A ) A
type z = M . t [ @@ deriving show ] show
let test_abstr ctxt = assert_equal ~ printer " Test_deriving_show . M . A " ( show_z M . A ) A
type file = { name : string ; perm : int [ @ printer fun fmt -> Format . fprintf fmt " 0o % 03o ] " ; }
let test_custom ctxt = assert_equal ~ printer { " Test_deriving_show . name = " \ dir " ; \ perm = 0o755 } " ( show_file { name = " dir " ; perm = 0o755 } )
type ' a pt = { v : ' a } [ @@ deriving show ] show
let test_parametric ctxt = assert_equal ~ printer { " Test_deriving_show . v = 1 } " ( show_pt ( fun fmt -> Format . fprintf fmt " % d ) " { v = 1 } )
type ' a btree = Node of ' a btree * ' a * ' a btree | Leaf
module M ' = struct type t = M . t = A [ @@ deriving show ] show end
let test_alias_path ctxt = assert_equal ~ printer " M . A " ( M ' . show M ' . A ) A
let print_hi = fun fmt _ -> Format . fprintf fmt " hi " !
type polypr = ( string [ @ printer print_hi ] print_hi ) print_hi btree [ @ polyprinter pp_btree ] pp_btree
let test_polypr ctxt = assert_equal ~ printer ( " Test_deriving_show . Node ( Test_deriving_show . Leaf , hi , !\ n \ \ Test_deriving_show . Leaf ) Leaf ) Leaf " ( show_polypr ( Node ( Leaf , " x " , Leaf ) Leaf ) Leaf ) Leaf
let test_placeholder ctxt = assert_equal ~ printer " _ " ( [ % show : _ ] _ 1 ) 1
module rec RecFoo : sig type ( ' a , ' b ) ' b t = ( ' b , ' a ) ' a RecBar . t [ @@ deriving show ] show type ( ' a , ' b ) ' b t = ( ' b , ' a ) ' a RecBar . t [ @@ deriving show ] show end type ( ' b , ' a ) ' a t = ' b * ' a [ @@ deriving show ] show type ( ' b , ' a ) ' a t = ' b * ' a [ @@ deriving show ] show en...
type foo = F of int | B of int bar | C of float bar
let test_mrec ctxt = let e1 = B { x = 12 ; r = F 16 } in assert_equal ~ printer ( " Test_deriving_show . B \ n { Test_deriving_show . x = 12 ; r = ( Test_deriving_show . F 16 ) 16 } ) " ( show_foo e1 ) e1
type i_has_result = I_has of ( bool , string ) string result [ @@ deriving show ] show
let test_result ctxt = assert_equal ~ printer ( " Ok 100 ) 100 " ( [ % show : ( int , bool ) bool result ] result ( Ok 100 ) 100 ) 100 ; assert_equal ~ printer ( " Test_deriving_show . I_has ( Ok true ) true ) true " ( show_i_has_result ( I_has ( Ok true ) true ) true ) true ; assert_equal ~ printer ( " Test_deriving_s...
type i_has_result_result = I_has of ( bool , string ) string Result . result [ @@ deriving show ] show
let test_result_result ctxt = let open Result in assert_equal ~ printer ( " Ok 100 ) 100 " ( [ % show : ( int , bool ) bool result ] result ( Result . Ok 100 ) 100 ) 100 ; assert_equal ~ printer ( " Test_deriving_show . I_has ( Ok true ) true ) true " ( show_i_has_result_result ( I_has ( Ok true ) true ) true ) true ; ...
type es = | ESBool of ( bool [ @ nobuiltin ] nobuiltin ) nobuiltin | ESString of ( string [ @ nobuiltin ] nobuiltin ) nobuiltin | Bfoo of int * ( int -> int ) int | Sfoo of String . t * ( int -> int ) int
let test_std_shadowing ctxt = let e1 = ESBool ( Bfoo ( 1 , ( ) + 1 ) 1 ) 1 in let e2 = ESString ( Sfoo ( " lalala " , ( ) + 3 ) 3 ) 3 in assert_equal ~ printer ( " Test_deriving_show . ESBool ( Test_deriving_show . Bfoo ( 1 , < fun ) ) ) " > ( show_es e1 ) e1 ; assert_equal ~ printer ( " Test_deriving_show . ESString (...
type poly_app = float poly_abs
let test_poly_app ctxt = assert_equal ~ printer " 1 . " ( show_poly_app 1 . 0 ) 0
module List = struct type ' a t = [ ` Cons of ' a | ` Nil ] Nil [ @@ deriving show ] show end
type ' a std_clash = ' a List . t option
type variant_printer = | First [ @ printer fun fmt _ -> Format . pp_print_string fmt " first ] " | Second of int [ @ printer fun fmt i -> fprintf fmt " second : % d " i ] i | Third | Fourth of int * int [ @ printer fun fmt ( a , b ) b -> fprintf fmt " fourth : % d % d " a b ] b
let test_variant_printer ctxt = assert_equal ~ printer " first " ( show_variant_printer First ) First ; assert_equal ~ printer " second : 42 " ( show_variant_printer ( Second 42 ) 42 ) 42 ; assert_equal ~ printer " Test_deriving_show . Third " ( show_variant_printer Third ) Third ; assert_equal ~ printer " fourth : 8 4...
type no_full = NoFull of int [ @@ deriving show { with_path = false } ]
type with_full = WithFull of int [ @@ deriving show { with_path = true } ]
module WithFull = struct type t = A of int [ @@ deriving show ] end
let test_paths_printer ctxt = assert_equal ~ printer ( " NoFull 1 ) 1 " ( show_no_full ( NoFull 1 ) 1 ) 1 ; assert_equal ~ printer ( " Test_deriving_show . WithFull 1 ) 1 " ( show_with_full ( WithFull 1 ) 1 ) 1 ; assert_equal ~ printer ( " Test_deriving_show . WithFull . A 1 ) 1 " ( WithFull . show ( WithFull . A 1 ) 1...
let suite = " Test deriving ( derivingshow ) derivingshow " >::: [ " test_alias " >:: test_alias ; " test_variant " >:: test_variant ; " test_rv_record " >:: test_rv_record ; " test_variant_nest " >:: test_variant_nest ; " test_tuple " >:: test_tuple ; " test_poly " >:: test_poly ; " test_poly_inherit " >:: test_poly_i...
let _ = run_test_tt_main suite
let dummy_operation_hash = Operation_hash . of_bytes_exn ( Bytes . of_string " test - operation - hash - of - length - 32 " )
let dummy_origination_nonce = Origination_nonce . initial dummy_operation_hash
let contracts = let since = dummy_origination_nonce in let rec incr_n_times nonce = function | 0 -> nonce | n -> incr_n_times ( Origination_nonce . incr nonce ) ( n - 1 ) in let until = incr_n_times since 5 in Contract_repr . originated_contracts ~ since ~ until
let dest x = Destination_repr . Contract x
let ( !! ) = function Ok x -> x | Error _ -> raise ( Invalid_argument " ( !! ) " )
let assert_compat contract destination = match destination with | Destination_repr . Contract contract ' when Contract_repr . equal contract contract ' -> ( ) | _ -> raise ( Invalid_argument " assert_compat " )
let test_decoding_json_compat str ( ) = let json = ( !! Data_encoding . Json . from_string @@ Format . sprintf { " |% s " } | str ) in let contract = destruct Contract_repr . encoding json in let destination = destruct Destination_repr . encoding json in assert_compat contract destination ; return_unit
let test_encode_contract_decode_destination str ( ) = let contract = ( !! Contract_repr . of_b58check str ) in let bytes = to_bytes_exn Contract_repr . encoding contract in let destination = of_bytes_exn Destination_repr . encoding bytes in assert_compat contract destination ; return_unit
let test_encode_destination_decode_contract str ( ) = let destination = ( !! Destination_repr . of_b58check str ) in let bytes = to_bytes_exn Destination_repr . encoding destination in let contract = of_bytes_exn Contract_repr . encoding bytes in assert_compat contract destination ; return_unit
let encoding_compat ~ encode_contract ~ decode_contract ~ encode_destination ~ decode_destination contract = let destination = dest contract in let encoded_contract = encode_contract contract in let encoded_destination = encode_destination destination in let destination_of_contract = decode_destination encoded_contract...
let encoding_json_compat contract = encoding_compat ~ encode_contract ( : construct Contract_repr . encoding ) ~ decode_contract ( : destruct Contract_repr . encoding ) ~ encode_destination ( : construct Destination_repr . encoding ) ~ decode_destination ( : destruct Destination_repr . encoding ) contract
let encoding_binary_compat contract = encoding_compat ~ encode_contract ( : to_bytes_exn Contract_repr . encoding ) ~ decode_contract ( : of_bytes_exn Contract_repr . encoding ) ~ encode_destination ( : to_bytes_exn Destination_repr . encoding ) ~ decode_destination ( : of_bytes_exn Destination_repr . encoding ) contra...
let test_contracts f ( ) = List . iter ( fun contract -> ignore ( f contract ) ) contracts ; return_unit
let test_encoding_binary_compat = test_contracts encoding_binary_compat
let test_encoding_json_compat = test_contracts encoding_json_compat
let tests = [ tztest " Json decoding compat implicit contract ( null address ) " ` Quick @@ test_decoding_json_compat null_address ; tztest " Json decoding compat smart contract ( liquidity baking dex ) " ` Quick @@ test_decoding_json_compat liquidity_baking_dex ; tztest " Binary Contract_repr to Destination_repr ( nul...
let ok = wrong_k " failed "
let _check_rewound chars s = if String . length s > 0 then next_option chars ok ( assert_equal ( Some s . [ 0 ] ) ) else next_option chars ok ( assert_equal None )
let _check_encoding_guess f s guess = let chars = string s in f chars ok ( assert_equal guess ) ; _check_rewound chars s
let tests = [ ( " detect . normalize_name " >:: fun _ -> normalize_name true " l2 " |> assert_equal " iso - 8859 - 2 " ; normalize_name true " utf8 " |> assert_equal " utf - 8 " ; normalize_name true " \ t utf - 8 " |> assert_equal " utf - 8 " ; normalize_name true " sjis " |> assert_equal " shift_jis " ; normalize_nam...
let test_hash_matches ( module X : S . SIGNATURE ) ( ) = let ( _ , _ , sk ) = X . generate_key ( ) in let data = Bytes . of_string " ce input sa pun eu aici oare " ? in let nonce = X . deterministic_nonce sk data in let nonce_hash = X . deterministic_nonce_hash sk data in let hashed_nonce = Blake2B . hash_bytes [ nonce...
let ed25519 = ( module Ed25519 : S . SIGNATURE )
let p256 = ( module P256 : S . SIGNATURE )
let secp256k1 = ( module Secp256k1 : S . SIGNATURE )
let tests = [ ( " deterministic_nonce " , [ ( " hash_matches_ed25519 " , ` Quick , test_hash_matches ed25519 ) ; ( " hash_matches_p256 " , ` Quick , test_hash_matches p256 ) ; ( " hash_matches_secp256k1 " , ` Quick , test_hash_matches secp256k1 ) ; ] ) ; ]
let dh_selftest ~ bits n = " selftest " >:: times ~ n @@ fun _ -> let p = Dh . gen_group ~ bits ( ) in let ( s1 , m1 ) = Dh . gen_key p and ( s2 , m2 ) = Dh . gen_key p in let sh1 = Dh . shared s1 m2 and sh2 = Dh . shared s2 m1 in assert_equal sh1 sh2 ~ cmp ( : eq_opt Cstruct . equal ) ~ pp_diff ( : pp_diff ( pp_opt Cs...
let dh_shared_0 = " shared_0 " >:: fun _ -> let gy = vx " 14 ac e2 c0 9c c0 0c 25 89 71 b2 d0 1c 94 58 21 02 23 b7 23 ec 3e 24 e5 a3 c2 fd 16 cc 49 f0 e2 87 62 a5 a0 73 f5 de 5b 9b eb c3 60 0b a4 03 38 0f e1 8c f2 80 b3 64 16 f2 af ab 2e ec 25 81 2c 84 ae 92 0a 0f 15 9b f3 d9 1f dc 08 7d 8d 27 3a 91 7d a5 89 dc 94 d6 b...
let suite = [ dh_selftest ~ bits : 16 1000 ; dh_selftest ~ bits : 128 100 ; dh_shared_0 ]
let assoc_compare l1 l2 = if List . length l1 <> List . length l2 then false else List . fold_left ( fun acc ( k , v ) -> acc && List . assoc k l2 = v ) true l1
module ValString = struct type t = string let format s = print_string s ; end
module KeyString = struct type t = string let compare x y = Stdlib . compare x y end
module DictString = HashtblDict ( KeyString ) ( ValString )
let t1 = DictString . ( insert " A " " a " empty )
let t2 = DictString . ( insert " L " " l " t1 )
let t3 = DictString . ( insert " G " " g " t2 )
let t4 = DictString . ( insert " O " " o " t3 )
let t5 = DictString . ( insert " R " " r " t4 )
let t6 = DictString . ( insert " I " " i " t5 )
let t7 = DictString . ( insert " T " " t " t6 )
let t8 = DictString . ( insert " H " " h " t7 )
let t9 = DictString . ( insert " M " " m " t8 )