text
stringlengths
0
601k
let test_poly_app ctxt = assert_equal ~ printer true ( equal_poly_app 1 . 0 1 . 0 ) 0 ; assert_equal ~ printer false ( equal_poly_app 1 . 0 2 . 0 ) 0
type poly_app_custom = float poly_abs_custom [ @ equal equal_poly_abs_custom ( ) ] =
module List = struct type ' a t = [ ` Cons of ' a | ` Nil ] Nil [ @@ deriving eq ] eq end
type ' a std_clash = ' a List . t option
let test_result ctxt = let eq = [ % eq : ( string , int ) int result ] result in assert_equal ~ printer true ( eq ( Ok " ttt ) " ( Ok " ttt ) ) " ; assert_equal ~ printer false ( eq ( Ok " 123 ) " ( Error 123 ) 123 ) 123 ; assert_equal ~ printer false ( eq ( Error 123 ) 123 ( Error 0 ) 0 ) 0
let test_result_result ctxt = let open Result in let eq = [ % eq : ( string , int ) int result ] result in assert_equal ~ printer true ( eq ( Ok " ttt ) " ( Ok " ttt ) ) " ; assert_equal ~ printer false ( eq ( Ok " 123 ) " ( Error 123 ) 123 ) 123 ; assert_equal ~ printer false ( eq ( Error 123 ) 123 ( Error 0 ) 0 ) 0
let suite = " Test deriving ( derivingeq ) derivingeq " >::: [ " test_simple " >:: test_simple ; " test_array " >:: test_arr ; " test_ref1 " >:: test_ref1 ; " test_ref2 " >:: test_ref2 ; " test_custom " >:: test_custom ; " test_placeholder " >:: test_placeholder ; " test_mrec " >:: test_mrec ; " test_mut_rec " >:: test...
let _ = run_test_tt_main suite
module T : sig type ' a btree = Node of ' a btree * ' a * ' a btree | Leaf [ @@ deriving iter ] iter type ( ' a , ' b ) ' b record = { a : ' a ; b : ' b } [ @@ deriving iter ] iter type ' a reflist = ' a Stdlib . ref list [ @@ deriving iter ] iter type ' a btree = Node of ' a btree * ' a * ' a btree | Leaf [ @@ derivin...
let test_btree ctxt = let lst = ref [ ] in iter_btree ( fun x -> lst := x :: ! lst ) lst ( Node ( Node ( Leaf , 0 , Leaf ) Leaf , 1 , Node ( Leaf , 2 , Leaf ) Leaf ) Leaf ) Leaf ; assert_equal [ 2 ; 1 ; 0 ] 0 ! lst
let test_record ctxt = let lst : string list ref = ref [ ] in lst := [ ] ; iter_record ( fun a -> lst := string_of_int a :: ! lst ) lst ( fun b -> lst := string_of_float b :: ! lst ) lst { a = 1 ; b = 1 . 2 } 2 ; assert_equal [ " 1 . 2 " ; " 1 ] " ! lst ; lst := [ ] ; iter_record ( fun a -> lst := string_of_int ( a + 1...
let test_reflist ctxt = let lst = ref [ ] in iter_reflist ( fun x -> lst := x :: ! lst ) lst [ ref 0 ; ref 1 ; ref 2 ] ; assert_equal [ 2 ; 1 ; 0 ] 0 ! lst
type ' a btreer = Node of { lft : ' a btree ; elt : ' a ; rgt : ' a btree } | Leaf
type ' a ty = ' a * int list
type ' a res0 = ( ' a , char ) char Result . result [ @@ deriving iter ] iter
let test_iter_res ctxt = let has_ok = ref false in iter_res0 ( fun _ -> has_ok := true ) true ( Result . Ok " xxx ) " ; assert_bool " set ok " ! has_ok ; iter_res0 ( fun _ -> has_ok := false ) false ( Result . Error ' c ' ) ' c ' ; assert_bool " set ok " ! has_ok
let suite = " Test deriving ( derivingiter ) derivingiter " >::: [ " test_btree " >:: test_btree ; " test_record " >:: test_record ; " test_reflist " >:: test_reflist ; " test_iter_res " >:: test_iter_res ]
let _ = run_test_tt_main suite
module M : sig type a = { a1 : int option ; a2 : int list ; a3 : int [ @ default 42 ] 42 ; a4s : ( int * int list ) list [ @ split ] split ; a5 : int ; } [ @@ deriving show , make ] make type b = { b1 : int option ; b2 : int list ; b3 : int [ @ default 42 ] 42 ; b4s : ( int * int list ) list [ @ split ] split ; b5 : in...
let test_no_main ctxt = assert_equal ~ printer : M . show_a { M . a1 = None ; a2 = [ ] ; a3 = 42 ; a4s = 2 , [ ] ; a5 = 1 } ( M . make_a ~ a4 : 2 ~ a5 : 1 ( ) ) ; assert_equal ~ printer : M . show_a { M . a1 = Some 1 ; a2 = [ 2 ] 2 ; a3 = 3 ; a4s = 4 , [ 5 ] 5 ; a5 = 6 } ( M . make_a ~ a1 : 1 ~ a2 [ : 2 ] 2 ~ a3 : 3 ~ ...
let test_main ctxt = assert_equal ~ printer : M . show_b { M . b1 = None ; b2 = [ ] ; b3 = 42 ; b4s = 2 , [ ] ; b5 = 1 } ( M . make_b ~ b4 : 2 1 ) 1 ; assert_equal ~ printer : M . show_b { M . b1 = Some 1 ; b2 = [ 2 ] 2 ; b3 = 3 ; b4s = 4 , [ 5 ] 5 ; b5 = 6 } ( M . make_b ~ b1 : 1 ~ b2 [ : 2 ] 2 ~ b3 : 3 ~ b4 : 4 ~ b4s...
let test_no_unit ctxt = assert_equal ~ printer : M . show_c { M . c1 = 0 ; M . c2 = " " } ( M . make_c ~ c1 : 0 ~ c2 ) " " :
let suite = " Test deriving ( derivingmake ) derivingmake " >::: [ " test_no_main " >:: test_no_main ; " test_main " >:: test_main ; " test_no_unit " >:: test_no_unit ]
let _ = run_test_tt_main suite
module T : sig type ' a btree = Node of ' a btree * ' a * ' a btree | Leaf [ @@ deriving map , show ] show type ' a btreer = Noder of { lft : ' a btree ; elt : ' a ; rgt : ' a btree } | Leafr [ @@ deriving map ] map type ' a ty = ' a * int list [ @@ deriving map ] map type var0 = A0 of int [ @@ deriving map , show ] sh...
let fmt_chr fmt = Format . fprintf fmt " % c "
let fmt_flt fmt = Format . fprintf fmt " % f "
let fmt_int fmt = Format . fprintf fmt " % d "
let fmt_str fmt = Format . fprintf fmt " % s "
let test_btree ctxt = let btree = ( Node ( Node ( Leaf , 0 , Leaf ) Leaf , 1 , Node ( Leaf , 2 , Leaf ) Leaf ) Leaf ) Leaf in let btree ' = map_btree ( fun x -> x + 1 ) 1 btree in assert_equal ~ printer ( : show_btree fmt_int ) fmt_int ( Node ( Node ( Leaf , 1 , Leaf ) Leaf , 2 , Node ( Leaf , 3 , Leaf ) Leaf ) Leaf ) ...
let test_var0 ctxt = assert_equal ~ printer : show_var0 ( A0 10 ) 10 ( map_var0 ( A0 10 ) 10 ) 10
let test_var1 ctxt = assert_equal ~ printer ( : show_var1 fmt_int ) fmt_int ( A1 1 ) 1 ( map_var1 ( ( ) + 1 ) 1 ( A1 0 ) 0 ) 0 ; assert_equal ~ printer ( : show_var1 fmt_str ) fmt_str ( A1 " 2 ) " ( map_var1 string_of_int ( A1 2 ) 2 ) 2
let test_var2 ctxt = assert_equal ~ printer ( : show_var2 fmt_int ) fmt_int ( B2 7 ) 7 ( map_var2 ( ( ) + 1 ) 1 ( B2 7 ) 7 ) 7 ; assert_equal ~ printer ( : show_var2 fmt_int ) fmt_int ( A2 5 ) 5 ( map_var2 ( ( ) + 1 ) 1 ( A2 4 ) 4 ) 4 ; assert_equal ~ printer ( : show_var2 fmt_int ) fmt_int ( A2 5 ) 5 ( map_var2 int_of...
let test_var3 ctxt = let show , map = show_var3 fmt_int fmt_str , map_var3 ( ( ) + 1 ) 1 String . uppercase_ascii in assert_equal ~ printer : show ( A3 2 ) 2 ( map ( A3 1 ) 1 ) 1 ; assert_equal ~ printer : show ( B3 false ) false ( map ( B3 false ) false ) false ; assert_equal ~ printer : show ( C3 ( C3 " ABC " , A3 3 ...
let test_record0 ctxt = assert_equal ~ printer : show_record0 { a0 = 10 } 10 ( map_record0 { a0 = 10 } 10 ) 10
let test_record1 ctxt = assert_equal ~ printer ( : show_record1 fmt_int ) fmt_int { a1 = 1 } 1 ( map_record1 ( ( ) + 1 ) 1 { a1 = 0 } 0 ) 0 ; assert_equal ~ printer ( : show_record1 fmt_str ) fmt_str { a1 " = 2 } " ( map_record1 string_of_int { a1 = 2 } 2 ) 2
let test_record2 ctxt = assert_equal ~ printer ( : show_record2 fmt_int ) fmt_int { a2 = 5 ; b2 = 7 } 7 ( map_record2 ( ( ) + 1 ) 1 { a2 = 4 ; b2 = 7 } 7 ) 7 ; assert_equal ~ printer ( : show_record2 fmt_int ) fmt_int { a2 = 5 ; b2 = 0 } 0 ( map_record2 int_of_float { a2 = 5 . ; b2 = 0 } 0 ) 0
let test_record3 ctxt = let show , map = show_record3 fmt_int fmt_str , map_record3 ( ( ) + 1 ) 1 String . uppercase_ascii in assert_equal ~ printer : show { a3 = 5 ; b3 = false ; c3 " = ABC } " ( map { a3 = 4 ; b3 = false ; c3 " = abc } ) " ; let show , map = show_record3 fmt_int fmt_flt , map_record3 Char . code floa...
let test_pvar3 ctxt = let show , map = show_pvar3 fmt_str fmt_int fmt_int , map_pvar3 string_of_int Char . code int_of_string in assert_equal ~ printer : show ( ` A " 1 ) " ( map ( ` A 1 ) 1 ) 1 ; assert_equal ~ printer : show ( ` B ( ` A " 1 ) ) " ( map ( ` B ( ` A 1 ) 1 ) 1 ) 1 ; assert_equal ~ printer : show ( ` B (...
type ' a result0 = ( ' a , bool ) bool result [ @@ deriving show , map ] map
let test_map_result ctxt = let f = map_result0 succ in let printer = show_result0 fmt_int in assert_equal ~ printer ( Ok 10 ) 10 ( f ( Ok 9 ) 9 ) 9 ; assert_equal ~ printer ( Error true ) true ( f ( Error true ) true ) true
type ' a result_result0 = ( ' a , bool ) bool Result . result [ @@ deriving show , map ] map
let test_map_result_result ctxt = let open Result in let f = map_result_result0 succ in let printer = show_result_result0 fmt_int in assert_equal ~ printer ( Ok 10 ) 10 ( f ( Ok 9 ) 9 ) 9 ; assert_equal ~ printer ( Error true ) true ( f ( Error true ) true ) true
let suite = " Test deriving ( derivingmap ) derivingmap " >::: [ " test_btree " >:: test_btree ; " test_var0 " >:: test_var0 ; " test_var1 " >:: test_var1 ; " test_var2 " >:: test_var2 ; " test_var3 " >:: test_var3 ; " test_record0 " >:: test_record0 ; " test_record1 " >:: test_record1 ; " test_record2 " >:: test_recor...
let _ = run_test_tt_main suite
type a1 = int [ @@ deriving ord ] ord
type a2 = int32 [ @@ deriving ord ] ord
type a3 = int64 [ @@ deriving ord ] ord
type a4 = nativeint [ @@ deriving ord ] ord
type a5 = float [ @@ deriving ord ] ord
type a6 = bool [ @@ deriving ord ] ord
type a7 = char [ @@ deriving ord ] ord
type a8 = string [ @@ deriving ord ] ord
type a9 = bytes [ @@ deriving ord ] ord
type l = int list [ @@ deriving ord ] ord
type a = int array [ @@ deriving ord ] ord
type o = int option [ @@ deriving ord ] ord
type y = int lazy_t [ @@ deriving ord ] ord
let test_simple ctxt = assert_equal ~ printer ( 1 ) 1 ( compare_a1 1 0 ) 0 ; assert_equal ~ printer ( 0 ) 0 ( compare_a1 1 1 ) 1 ; assert_equal ~ printer ( - 1 ) 1 ( compare_a1 1 2 ) 2
type v = Foo | Bar of int * string | Baz of string [ @@ deriving ord ] ord
let test_variant ctxt = assert_equal ~ printer ( 1 ) 1 ( compare_v ( Baz " b ) " ( Baz " a ) ) " ; assert_equal ~ printer ( 1 ) 1 ( compare_v ( Bar ( 1 , ) ) " " Foo ) Foo ; assert_equal ~ printer ( 1 ) 1 ( compare_v ( Baz ) " " ( Bar ( 1 , ) ) ) " " ; assert_equal ~ printer ( - 1 ) 1 ( compare_v Foo ( Baz ) ) " "
type rv = RFoo | RBar of { x : int ; y : string ; } [ @@ deriving ord ] ord
type pv1 = [ ` Foo | ` Bar of int * string ] [ @@ deriving ord ] ord
type pv2 = [ ` Baz | pv1 ] [ @@ deriving ord ] ord
type ty = int * string [ @@ deriving ord ] ord
let test_complex ctxt = assert_equal ~ printer ( 0 ) 0 ( compare_ty ( 0 , " a ) " ( 0 , " a ) ) " ; assert_equal ~ printer ( 1 ) 1 ( compare_ty ( 1 , " a ) " ( 0 , " a ) ) " ; assert_equal ~ printer ( - 1 ) 1 ( compare_ty ( 0 , " a ) " ( 1 , " a ) ) " ; assert_equal ~ printer ( - 1 ) 1 ( compare_ty ( 0 , " a ) " ( 0 , ...
type re = { f1 : int ; f2 : string ;
module M : sig type t = int [ @@ deriving ord ] ord type t = int [ @@ deriving ord ] ord end
type z = M . t [ @@ deriving ord ] ord
type file = { name : string ; perm : int [ @ compare fun a b -> compare b a ] a ;
let test_custom ctxt = assert_equal ~ printer ( - 1 ) 1 ( compare_file { name = " " ; perm = 2 } { name = " " ; perm = 1 } ) ; assert_equal ~ printer ( 1 ) 1 ( compare_file { name = " " ; perm = 1 } { name = " " ; perm = 2 } )
type ' a pt = { v : ' a } [ @@ deriving ord ] ord
let test_placeholder ctxt = assert_equal ~ printer 0 ( [ % ord : _ ] _ 1 2 ) 2
type mrec_variant = | MrecFoo of string | MrecBar of int
let test_mrec ctxt = assert_equal ~ printer ( 0 ) 0 ( compare_mrec_variant_list [ MrecFoo " foo " ; MrecBar 1 ] ; [ MrecFoo " foo " ; MrecBar 1 ] ) ; ; assert_equal ~ printer ( - 1 ) 1 ( compare_mrec_variant_list [ MrecFoo " foo " ; MrecBar 1 ] ; [ MrecFoo " foo " ; MrecBar 2 ] ) ; ; assert_equal ~ printer ( 1 ) 1 ( co...
type e = Bool of be | Plus of e * e | IfE of ( be , e ) e if_e [ @@ deriving ord ] ord
let test_mrec2 ctxt = let ce1 = Bool ( IfB ( True , False , True ) True ) True in let ce2 = Bool ( IfB ( True , False , False ) False ) False in assert_equal ~ printer ( 0 ) 0 ( compare_e ce1 ce1 ) ce1 ; assert_equal ~ printer ( - 1 ) 1 ( compare_e ce1 ce2 ) ce2 ; assert_equal ~ printer ( 1 ) 1 ( compare_e ce2 ce1 ) ce...
let test_ord_result ctx = let compare_res0 = [ % ord : ( unit , unit ) unit result ] result in assert_equal ~ printer 0 ( compare_res0 ( Ok ( ) ) ( Ok ( ) ) ) ; assert_equal ~ printer ( - 1 ) 1 ( compare_res0 ( Ok ( ) ) ( Error ( ) ) ) ; assert_equal ~ printer 1 ( compare_res0 ( Error ( ) ) ( Ok ( ) ) )
let test_ord_result_result ctx = let compare_res0 = [ % ord : ( unit , unit ) unit Result . result ] result in let open Result in assert_equal ~ printer 0 ( compare_res0 ( Ok ( ) ) ( Ok ( ) ) ) ; assert_equal ~ printer ( - 1 ) 1 ( compare_res0 ( Ok ( ) ) ( Error ( ) ) ) ; assert_equal ~ printer 1 ( compare_res0 ( Error...
type r1 = int ref [ @@ deriving ord ] ord
let test_ref1 ctxt = assert_equal ~ printer ( - 1 ) 1 ( compare_r1 ( ref 0 ) 0 ( ref 1 ) 1 ) 1 ; assert_equal ~ printer ( 0 ) 0 ( compare_r1 ( ref 0 ) 0 ( ref 0 ) 0 ) 0 ; assert_equal ~ printer ( 1 ) 1 ( compare_r1 ( ref 1 ) 1 ( ref 0 ) 0 ) 0
type r2 = int Stdlib . ref
let test_ref2 ctxt = assert_equal ~ printer ( - 1 ) 1 ( compare_r2 ( ref 0 ) 0 ( ref 1 ) 1 ) 1 ; assert_equal ~ printer ( 0 ) 0 ( compare_r2 ( ref 0 ) 0 ( ref 0 ) 0 ) 0 ; assert_equal ~ printer ( 1 ) 1 ( compare_r2 ( ref 1 ) 1 ( ref 0 ) 0 ) 0
type es = | ESBool of bool | ESString of string | Bfoo of int * ( ( int -> int ) int [ @ compare fun _ _ -> 0 ] 0 ) 0 | Sfoo of String . t * ( ( int -> int ) int [ @ compare fun _ _ -> 0 ] 0 ) 0
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 ( - 1 ) 1 ( compare_es e1 e2 ) e2 ; assert_equal ~ printer ( 1 ) 1 ( compare_es e2 e1 ) e1 ; assert_equal ~ printer 0 ( compare_es e1 e1 ) e1 ; assert_equal ~ p...
type poly_app = float poly_abs
let test_poly_app ctxt = assert_equal ~ printer 0 ( compare_poly_app 1 . 0 1 . 0 ) 0 ; assert_equal ~ printer ( - 1 ) 1 ( compare_poly_app 1 . 0 2 . 0 ) 0
type poly_app_custom = float poly_abs_custom [ @ compare compare_poly_abs_custom Stdlib . compare ] compare
module List = struct type ' a t = [ ` Cons of ' a | ` Nil ] Nil [ @@ deriving ord ] ord end
type ' a std_clash = ' a List . t option
module Warnings = struct module W4 = struct [ @@@ ocaml . warning " @ 4 ] " type t = | A of int | B [ @@ deriving ord ] ord end end
type ab = { a : int ; b : int } [ @@ deriving ord ] ord
let test_record_order ctxt = assert_equal ~ printer ( - 1 ) 1 ( compare_ab { a = 1 ; b = 2 ; } { a = 2 ; b = 1 ; } ) ; assert_equal ~ printer ( 0 ) 0 ( compare_ab { a = 1 ; b = 2 ; } { a = 1 ; b = 2 ; } ) ; assert_equal ~ printer ( 1 ) 1 ( compare_ab { a = 2 ; b = 2 ; } { a = 1 ; b = 2 ; } )
let suite = " Test deriving ( derivingord ) derivingord " >::: [ " test_simple " >:: test_simple ; " test_variant " >:: test_variant ; " test_complex " >:: test_complex ; " test_custom " >:: test_custom ; " test_placeholder " >:: test_placeholder ; " test_mrec " >:: test_mrec ; " test_mrec2 " >:: test_mrec2 ; " test_re...
let _ = run_test_tt_main suite
type t = int [ @@ deriving rpc ] rpc
let string_of_err = function | ` Msg x -> x
let check_marshal_unmarshal : ' a * Rpc . t * ( ' a -> Rpc . t ) t * ( Rpc . t -> ' a ) ' a -> unit = fun ( x , r , marshal , unmarshal ) unmarshal -> let r ' = marshal x in let x ' = unmarshal r in Alcotest . check ( Testable . from_rpc_of_t marshal ) marshal " same after marshal -> unmarshal " x x ' ; Alcotest . chec...
let check_unmarshal_error : ( Rpc . t -> ' a ) ' a -> Rpc . t -> unit = fun unmarshal t -> let u = try Some ( unmarshal t ) t with | _e -> None in match u with | Some _ -> Alcotest . fail " Expecting an error when unmarshalling " | None -> ( )
let check_unmarshal_ok : ' a Alcotest . testable -> ( Rpc . t -> ' a ) ' a -> ' a -> Rpc . t -> unit = fun testable unmarshal x r -> let x ' = unmarshal r in Alcotest . check testable " unmarshaller returned expected value " x x '