lift tests to ast_simplify
This commit is contained in:
parent
de6a3bbf6d
commit
55bff7b530
@ -1,2 +1,6 @@
|
|||||||
let compose = fun f g x -> f (g x)
|
let compose = fun f g x -> f (g x)
|
||||||
let (>|) = compose
|
let (>|) = compose
|
||||||
|
|
||||||
|
let compose_2 = fun f g x y -> f (g x y)
|
||||||
|
let compose_3 = fun f g x y z -> f (g x y z)
|
||||||
|
let compose_4 = fun f g a b c d -> f (g a b c d)
|
||||||
|
@ -159,6 +159,8 @@ let bind_map_smap f smap = bind_smap (X_map.String.map f smap)
|
|||||||
|
|
||||||
let bind_map_list f lst = bind_list (List.map f lst)
|
let bind_map_list f lst = bind_list (List.map f lst)
|
||||||
let bind_map_ne_list : _ -> 'a X_list.Ne.t -> 'b X_list.Ne.t result = fun f lst -> bind_ne_list (X_list.Ne.map f lst)
|
let bind_map_ne_list : _ -> 'a X_list.Ne.t -> 'b X_list.Ne.t result = fun f lst -> bind_ne_list (X_list.Ne.map f lst)
|
||||||
|
let bind_iter_list : (_ -> unit result) -> _ list -> unit result = fun f lst ->
|
||||||
|
bind_map_list f lst >>? fun _ -> ok ()
|
||||||
|
|
||||||
let bind_location (x:_ Location.wrap) =
|
let bind_location (x:_ Location.wrap) =
|
||||||
x.wrap_content >>? fun wrap_content ->
|
x.wrap_content >>? fun wrap_content ->
|
||||||
|
@ -4,3 +4,36 @@ let lr (a , b) = match (a , b) with
|
|||||||
| Some x , _ -> Some (`Left x)
|
| Some x , _ -> Some (`Left x)
|
||||||
| None , Some x -> Some (`Right x)
|
| None , Some x -> Some (`Right x)
|
||||||
| _ -> None
|
| _ -> None
|
||||||
|
|
||||||
|
(* TODO: recursive terminal *)
|
||||||
|
let rec bind_list = fun lst ->
|
||||||
|
match lst with
|
||||||
|
| [] -> Some []
|
||||||
|
| hd :: tl -> (
|
||||||
|
match hd with
|
||||||
|
| None -> None
|
||||||
|
| Some hd' -> (
|
||||||
|
match bind_list tl with
|
||||||
|
| None -> None
|
||||||
|
| Some tl' -> Some (hd' :: tl')
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
let bind_pair = fun (a , b) ->
|
||||||
|
a >>= fun a' ->
|
||||||
|
b >>= fun b' ->
|
||||||
|
Some (a' , b')
|
||||||
|
|
||||||
|
let bind_map_list = fun f lst -> bind_list (X_list.map f lst)
|
||||||
|
|
||||||
|
let bind_map_pair = fun f (a , b) -> bind_pair (f a , f b)
|
||||||
|
|
||||||
|
let bind_smap (s:_ X_map.String.t) =
|
||||||
|
let open X_map.String in
|
||||||
|
let aux k v prev =
|
||||||
|
prev >>= fun prev' ->
|
||||||
|
v >>= fun v' ->
|
||||||
|
Some (add k v' prev') in
|
||||||
|
fold aux s (Some empty)
|
||||||
|
|
||||||
|
let bind_map_smap f smap = bind_smap (X_map.String.map f smap)
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
include Types
|
include Types
|
||||||
|
include Misc
|
||||||
|
|
||||||
module Types = Types
|
module Types = Types
|
||||||
|
module Misc = Misc
|
||||||
module PP = PP
|
module PP = PP
|
||||||
module Combinators = Combinators
|
module Combinators = Combinators
|
||||||
|
@ -2,16 +2,18 @@ open Types
|
|||||||
|
|
||||||
module SMap = Map.String
|
module SMap = Map.String
|
||||||
|
|
||||||
|
let get_type_annotation (x:annotated_expression) = x.type_annotation
|
||||||
|
|
||||||
let t_bool : type_expression = T_constant ("bool", [])
|
let t_bool : type_expression = T_constant ("bool", [])
|
||||||
let t_string : type_expression = T_constant ("string", [])
|
let t_string : type_expression = T_constant ("string", [])
|
||||||
let t_bytes : type_expression = T_constant ("bytes", [])
|
let t_bytes : type_expression = T_constant ("bytes", [])
|
||||||
let t_int : type_expression = T_constant ("int", [])
|
let t_int : type_expression = T_constant ("int", [])
|
||||||
|
let t_nat : type_expression = T_constant ("nat", [])
|
||||||
let t_unit : type_expression = T_constant ("unit", [])
|
let t_unit : type_expression = T_constant ("unit", [])
|
||||||
let t_option o : type_expression = T_constant ("option", [o])
|
let t_option o : type_expression = T_constant ("option", [o])
|
||||||
let t_list t : type_expression = T_constant ("list", [t])
|
let t_list t : type_expression = T_constant ("list", [t])
|
||||||
let t_tuple lst : type_expression = T_tuple lst
|
let t_tuple lst : type_expression = T_tuple lst
|
||||||
let t_pair a b = t_tuple [a ; b]
|
let t_pair (a , b) = t_tuple [a ; b]
|
||||||
let t_record m : type_expression = (T_record m)
|
let t_record m : type_expression = (T_record m)
|
||||||
let t_ez_record (lst:(string * type_expression) list) : type_expression =
|
let t_ez_record (lst:(string * type_expression) list) : type_expression =
|
||||||
let aux prev (k, v) = SMap.add k v prev in
|
let aux prev (k, v) = SMap.add k v prev in
|
||||||
@ -29,22 +31,72 @@ let ez_t_sum (lst:(string * type_expression) list) : type_expression =
|
|||||||
T_sum map
|
T_sum map
|
||||||
|
|
||||||
let t_function param result : type_expression = T_function (param, result)
|
let t_function param result : type_expression = T_function (param, result)
|
||||||
|
let t_map key value = (T_constant ("map", [key ; value]))
|
||||||
|
|
||||||
let make_e_a ?type_annotation expression = {expression ; type_annotation}
|
let make_e_a ?type_annotation expression = {expression ; type_annotation}
|
||||||
let make_e_a_full expression type_annotation = make_e_a ~type_annotation expression
|
let make_e_a_full expression type_annotation = make_e_a ~type_annotation expression
|
||||||
|
|
||||||
let name (s : string) : name = s
|
let make_name (s : string) : name = s
|
||||||
|
|
||||||
let e_var (s : string) : expression = E_variable s
|
let e_var (s : string) : expression = E_variable s
|
||||||
|
|
||||||
let e_unit () : expression = E_literal (Literal_unit)
|
let e_unit () : expression = E_literal (Literal_unit)
|
||||||
let e_int n : expression = E_literal (Literal_int n)
|
let e_int n : expression = E_literal (Literal_int n)
|
||||||
let e_nat n : expression = E_literal (Literal_nat n)
|
let e_nat n : expression = E_literal (Literal_nat n)
|
||||||
let e_bool b : expression = E_literal (Literal_bool b)
|
let e_bool b : expression = E_literal (Literal_bool b)
|
||||||
let e_string s : expression = E_literal (Literal_string s)
|
let e_string s : expression = E_literal (Literal_string s)
|
||||||
let e_bytes b : expression = E_literal (Literal_bytes (Bytes.of_string b))
|
let e_bytes b : expression = E_literal (Literal_bytes (Bytes.of_string b))
|
||||||
|
let e_record map : expression = E_record map
|
||||||
|
let e_tuple lst : expression = E_tuple lst
|
||||||
|
let e_some s : expression = E_constant ("SOME", [s])
|
||||||
|
let e_none : expression = E_constant ("NONE", [])
|
||||||
|
let e_map lst : expression = E_map lst
|
||||||
|
let e_list lst : expression = E_list lst
|
||||||
|
let e_pair a b : expression = E_tuple [a; b]
|
||||||
|
|
||||||
let e_a_int n : annotated_expression = make_e_a_full (e_int n) t_int
|
let e_a_int n : annotated_expression = make_e_a_full (e_int n) t_int
|
||||||
|
let e_a_nat n : annotated_expression = make_e_a_full (e_nat n) t_nat
|
||||||
|
let e_a_bool b : annotated_expression = make_e_a_full (e_bool b) t_bool
|
||||||
|
let e_a_unit : annotated_expression = make_e_a_full (e_unit ()) t_unit
|
||||||
|
|
||||||
|
let e_a_record r =
|
||||||
|
let type_annotation = Option.(
|
||||||
|
map ~f:t_record (bind_map_smap get_type_annotation r)
|
||||||
|
) in
|
||||||
|
make_e_a ?type_annotation (e_record r)
|
||||||
|
|
||||||
|
let ez_e_a_record lst =
|
||||||
|
let aux prev (k, v) = SMap.add k v prev in
|
||||||
|
let map = List.fold_left aux SMap.empty lst in
|
||||||
|
e_a_record map
|
||||||
|
|
||||||
|
let e_a_tuple lst =
|
||||||
|
let type_annotation = Option.(
|
||||||
|
map ~f:t_tuple (bind_map_list get_type_annotation lst)
|
||||||
|
) in
|
||||||
|
make_e_a ?type_annotation (e_tuple lst)
|
||||||
|
|
||||||
|
let e_a_pair a b =
|
||||||
|
let type_annotation = Option.(
|
||||||
|
map ~f:t_pair
|
||||||
|
@@ bind_map_pair get_type_annotation (a , b)
|
||||||
|
) in
|
||||||
|
make_e_a ?type_annotation (e_pair a b)
|
||||||
|
|
||||||
|
let e_a_some opt =
|
||||||
|
let type_annotation = Option.(
|
||||||
|
map ~f:t_option (get_type_annotation opt)
|
||||||
|
) in
|
||||||
|
make_e_a ?type_annotation (e_some opt)
|
||||||
|
|
||||||
|
let e_a_none t_opt =
|
||||||
|
let type_annotation = t_option t_opt in
|
||||||
|
make_e_a ~type_annotation e_none
|
||||||
|
|
||||||
|
let e_a_list lst t =
|
||||||
|
make_e_a ~type_annotation:(t_list t) (e_list lst)
|
||||||
|
|
||||||
|
let e_a_map lst k v = make_e_a ~type_annotation:(t_map k v) (e_map lst)
|
||||||
|
|
||||||
let e_lambda (binder : string)
|
let e_lambda (binder : string)
|
||||||
(input_type : type_expression)
|
(input_type : type_expression)
|
||||||
@ -53,7 +105,7 @@ let e_lambda (binder : string)
|
|||||||
(body : block)
|
(body : block)
|
||||||
: expression =
|
: expression =
|
||||||
E_lambda {
|
E_lambda {
|
||||||
binder = (name binder) ;
|
binder = (make_name binder) ;
|
||||||
input_type = input_type ;
|
input_type = input_type ;
|
||||||
output_type = output_type ;
|
output_type = output_type ;
|
||||||
result = (make_e_a result) ;
|
result = (make_e_a result) ;
|
||||||
@ -64,7 +116,7 @@ let e_tuple (lst : ae list) : expression = E_tuple lst
|
|||||||
let ez_e_tuple (lst : expression list) : expression =
|
let ez_e_tuple (lst : expression list) : expression =
|
||||||
e_tuple (List.map make_e_a lst)
|
e_tuple (List.map make_e_a lst)
|
||||||
|
|
||||||
let e_constructor (s : string) (e : ae) : expression = E_constructor (name s, e)
|
let e_constructor (s : string) (e : ae) : expression = E_constructor (make_name s, e)
|
||||||
|
|
||||||
let e_record (lst : (string * ae) list) : expression =
|
let e_record (lst : (string * ae) list) : expression =
|
||||||
let aux prev (k, v) = SMap.add k v prev in
|
let aux prev (k, v) = SMap.add k v prev in
|
||||||
|
@ -71,6 +71,17 @@ let easy_evaluate_typed (entry:string) (program:AST_Typed.program) : AST_Typed.a
|
|||||||
untranspile_value result typed_main.type_annotation in
|
untranspile_value result typed_main.type_annotation in
|
||||||
ok typed_result
|
ok typed_result
|
||||||
|
|
||||||
|
let easy_evaluate_typed_simplified (entry:string) (program:AST_Typed.program) : Ast_simplified.annotated_expression result =
|
||||||
|
let%bind result =
|
||||||
|
let%bind mini_c_main =
|
||||||
|
transpile_entry program entry in
|
||||||
|
Run.Mini_c.run_entry mini_c_main (Mini_c.Combinators.d_unit) in
|
||||||
|
let%bind typed_result =
|
||||||
|
let%bind typed_main = Ast_typed.get_entry program entry in
|
||||||
|
untranspile_value result typed_main.type_annotation in
|
||||||
|
let%bind annotated_result = untype_expression typed_result in
|
||||||
|
ok annotated_result
|
||||||
|
|
||||||
let easy_evaluate_typed = trace_f_2_ez easy_evaluate_typed (thunk "easy evaluate typed")
|
let easy_evaluate_typed = trace_f_2_ez easy_evaluate_typed (thunk "easy evaluate typed")
|
||||||
|
|
||||||
let easy_run_typed
|
let easy_run_typed
|
||||||
@ -105,7 +116,7 @@ let easy_run_typed
|
|||||||
|
|
||||||
let easy_run_typed_simplified
|
let easy_run_typed_simplified
|
||||||
?(debug_mini_c = false) (entry:string)
|
?(debug_mini_c = false) (entry:string)
|
||||||
(program:AST_Typed.program) (input:Ast_simplified.annotated_expression) : AST_Typed.annotated_expression result =
|
(program:AST_Typed.program) (input:Ast_simplified.annotated_expression) : Ast_simplified.annotated_expression result =
|
||||||
let%bind mini_c_main =
|
let%bind mini_c_main =
|
||||||
trace (simple_error "transpile mini_c entry") @@
|
trace (simple_error "transpile mini_c entry") @@
|
||||||
transpile_entry program entry in
|
transpile_entry program entry in
|
||||||
@ -132,7 +143,8 @@ let easy_run_typed_simplified
|
|||||||
| T_function (_, result) -> ok result
|
| T_function (_, result) -> ok result
|
||||||
| _ -> simple_fail "main doesn't have fun type" in
|
| _ -> simple_fail "main doesn't have fun type" in
|
||||||
untranspile_value mini_c_result main_result_type in
|
untranspile_value mini_c_result main_result_type in
|
||||||
ok typed_result
|
let%bind annotated_result = untype_expression typed_result in
|
||||||
|
ok annotated_result
|
||||||
|
|
||||||
let easy_run_main_typed
|
let easy_run_main_typed
|
||||||
?(debug_mini_c = false)
|
?(debug_mini_c = false)
|
||||||
|
@ -2,148 +2,61 @@ open Trace
|
|||||||
open Ligo
|
open Ligo
|
||||||
open Test_helpers
|
open Test_helpers
|
||||||
|
|
||||||
|
open Ast_simplified.Combinators
|
||||||
|
|
||||||
let function_ () : unit result =
|
let function_ () : unit result =
|
||||||
let%bind program = type_file "./contracts/function.ligo" in
|
let%bind program = type_file "./contracts/function.ligo" in
|
||||||
let aux n =
|
let make_expect = fun n -> n in
|
||||||
let open Ast_simplified.Combinators in
|
expect_n_int program "main" make_expect
|
||||||
let input = e_a_int n in
|
|
||||||
let%bind result = easy_run_typed_simplified "main" program input in
|
|
||||||
let expected = Ast_typed.Combinators.e_a_empty_int n in
|
|
||||||
Ast_typed.assert_value_eq (expected , result)
|
|
||||||
in
|
|
||||||
let%bind _ = bind_list
|
|
||||||
@@ List.map aux
|
|
||||||
@@ [0 ; 2 ; 42 ; 163 ; -1] in
|
|
||||||
ok ()
|
|
||||||
|
|
||||||
let complex_function () : unit result =
|
let complex_function () : unit result =
|
||||||
let%bind program = type_file "./contracts/function-complex.ligo" in
|
let%bind program = type_file "./contracts/function-complex.ligo" in
|
||||||
let aux n =
|
let make_expect = fun n -> (3 * n + 2) in
|
||||||
let open AST_Typed.Combinators in
|
expect_n_int program "main" make_expect
|
||||||
let input = e_a_empty_int n in
|
|
||||||
let%bind result = easy_run_main_typed program input in
|
|
||||||
let%bind result' =
|
|
||||||
trace (simple_error "bad result") @@
|
|
||||||
get_a_int result in
|
|
||||||
Assert.assert_equal_int (3 * n + 2) result'
|
|
||||||
in
|
|
||||||
let%bind _ = bind_list
|
|
||||||
@@ List.map aux
|
|
||||||
@@ [0 ; 2 ; 42 ; 163 ; -1] in
|
|
||||||
ok ()
|
|
||||||
|
|
||||||
let closure () : unit result =
|
let closure () : unit result =
|
||||||
let%bind program = type_file "./contracts/closure.ligo" in
|
let%bind program = type_file "./contracts/closure.ligo" in
|
||||||
let%bind _foo = trace (simple_error "test foo") @@
|
let%bind () =
|
||||||
let aux n =
|
let make_expect = fun n -> (2 * n) in
|
||||||
let open AST_Typed.Combinators in
|
expect_n_int program "foo" make_expect
|
||||||
let input = e_a_empty_int n in
|
in
|
||||||
let%bind result = easy_run_typed "foo" program input in
|
let%bind _ =
|
||||||
let expected = e_a_empty_int ( 2 * n ) in
|
let make_expect = fun n -> (4 * n) in
|
||||||
AST_Typed.assert_value_eq (expected, result)
|
expect_n_int program "toto" make_expect
|
||||||
in
|
in
|
||||||
bind_list
|
|
||||||
@@ List.map aux
|
|
||||||
@@ [0 ; 2 ; 42 ; 163 ; -1] in
|
|
||||||
let%bind _toto = trace (simple_error "toto") @@
|
|
||||||
let aux n =
|
|
||||||
let open AST_Typed.Combinators in
|
|
||||||
let input = e_a_empty_int n in
|
|
||||||
let%bind result = easy_run_typed "toto" program input in
|
|
||||||
let expected = e_a_empty_int ( 4 * n ) in
|
|
||||||
AST_Typed.assert_value_eq (expected, result)
|
|
||||||
in
|
|
||||||
bind_list
|
|
||||||
@@ List.map aux
|
|
||||||
@@ [0 ; 2 ; 42 ; 163 ; -1] in
|
|
||||||
ok ()
|
ok ()
|
||||||
|
|
||||||
let shadow () : unit result =
|
let shadow () : unit result =
|
||||||
let%bind program = type_file "./contracts/shadow.ligo" in
|
let%bind program = type_file "./contracts/shadow.ligo" in
|
||||||
let%bind _foo = trace (simple_error "test foo") @@
|
let make_expect = fun _ -> 0 in
|
||||||
let aux n =
|
expect_n_int program "foo" make_expect
|
||||||
let open AST_Typed.Combinators in
|
|
||||||
let input = e_a_empty_int n in
|
|
||||||
let%bind result = easy_run_typed "foo" program input in
|
|
||||||
let expected = e_a_empty_int 0 in
|
|
||||||
AST_Typed.assert_value_eq (expected, result)
|
|
||||||
in
|
|
||||||
bind_list
|
|
||||||
@@ List.map aux
|
|
||||||
@@ [3 ; 2 ; 0 ; 42 ; 163 ; -1] in
|
|
||||||
ok ()
|
|
||||||
|
|
||||||
let higher_order () : unit result =
|
let higher_order () : unit result =
|
||||||
let%bind program = type_file "./contracts/high-order.ligo" in
|
let%bind program = type_file "./contracts/high-order.ligo" in
|
||||||
let%bind _foo = trace (simple_error "test foo") @@
|
let make_expect = fun n -> n in
|
||||||
let aux n =
|
expect_n_int program "foobar" make_expect
|
||||||
let open AST_Typed.Combinators in
|
|
||||||
let input = e_a_empty_int n in
|
|
||||||
let%bind result = easy_run_typed "foobar" program input in
|
|
||||||
let expected = e_a_empty_int ( n ) in
|
|
||||||
AST_Typed.assert_value_eq (expected, result)
|
|
||||||
in
|
|
||||||
bind_list
|
|
||||||
@@ List.map aux
|
|
||||||
@@ [0 ; 2 ; 42 ; 163 ; -1] in
|
|
||||||
ok ()
|
|
||||||
|
|
||||||
let shared_function () : unit result =
|
let shared_function () : unit result =
|
||||||
let%bind program = type_file "./contracts/function-shared.ligo" in
|
let%bind program = type_file "./contracts/function-shared.ligo" in
|
||||||
let%bind _inc = trace (simple_error "test inc") @@
|
let%bind () =
|
||||||
let aux n =
|
let make_expect = fun n -> (n + 1) in
|
||||||
let open AST_Typed.Combinators in
|
expect_n_int program "inc" make_expect
|
||||||
let input = e_a_empty_int n in
|
in
|
||||||
let%bind result = easy_run_typed "inc" program input in
|
let%bind () =
|
||||||
let expected = e_a_empty_int ( n + 1 ) in
|
let make_expect = fun n -> (n + 2) in
|
||||||
AST_Typed.assert_value_eq (expected, result)
|
expect_n_int program "double_inc" make_expect
|
||||||
in
|
in
|
||||||
bind_list
|
let%bind () =
|
||||||
@@ List.map aux
|
let make_expect = fun n -> (2 * n + 3) in
|
||||||
@@ [0 ; 2 ; 42 ; 163 ; -1] in
|
expect_n_int program "foo" make_expect
|
||||||
let%bind _double_inc = trace (simple_error "test double_inc") @@
|
in
|
||||||
let aux n =
|
|
||||||
let open AST_Typed.Combinators in
|
|
||||||
let input = e_a_empty_int n in
|
|
||||||
let%bind result = easy_run_typed "double_inc" program input in
|
|
||||||
let expected = e_a_empty_int ( n + 2 ) in
|
|
||||||
AST_Typed.assert_value_eq (expected, result)
|
|
||||||
in
|
|
||||||
bind_list
|
|
||||||
@@ List.map aux
|
|
||||||
@@ [0 ; 2 ; 42 ; 163 ; -1] in
|
|
||||||
let%bind _foo = trace (simple_error "test foo") @@
|
|
||||||
let aux n =
|
|
||||||
let open AST_Typed.Combinators in
|
|
||||||
let input = e_a_empty_int n in
|
|
||||||
let%bind result = easy_run_typed "foo" program input in
|
|
||||||
let expected = e_a_empty_int ( 2 * n + 3 ) in
|
|
||||||
AST_Typed.assert_value_eq (expected, result)
|
|
||||||
in
|
|
||||||
bind_list
|
|
||||||
@@ List.map aux
|
|
||||||
@@ [0 ; 2 ; 42 ; 163 ; -1] in
|
|
||||||
ok ()
|
ok ()
|
||||||
|
|
||||||
let bool_expression () : unit result =
|
let bool_expression () : unit result =
|
||||||
let%bind program = type_file "./contracts/boolean_operators.ligo" in
|
let%bind program = type_file "./contracts/boolean_operators.ligo" in
|
||||||
let aux (name, f) =
|
let%bind _ =
|
||||||
let aux b =
|
let aux (name , f) = expect_b_bool program name f in
|
||||||
let open AST_Typed.Combinators in
|
bind_map_list aux [
|
||||||
let input = e_a_empty_bool b in
|
|
||||||
let%bind result = easy_run_typed name program input in
|
|
||||||
let%bind result' =
|
|
||||||
trace (simple_error "bad result") @@
|
|
||||||
get_a_bool result in
|
|
||||||
Assert.assert_equal_bool (f b) result'
|
|
||||||
in
|
|
||||||
let%bind _ = bind_list
|
|
||||||
@@ List.map aux [true;false] in
|
|
||||||
ok ()
|
|
||||||
in
|
|
||||||
let%bind _ = bind_list
|
|
||||||
@@ List.map aux
|
|
||||||
@@ [
|
|
||||||
("or_true", fun b -> b || true) ;
|
("or_true", fun b -> b || true) ;
|
||||||
("or_false", fun b -> b || false) ;
|
("or_false", fun b -> b || false) ;
|
||||||
("and_true", fun b -> b && true) ;
|
("and_true", fun b -> b && true) ;
|
||||||
@ -153,64 +66,32 @@ let bool_expression () : unit result =
|
|||||||
|
|
||||||
let arithmetic () : unit result =
|
let arithmetic () : unit result =
|
||||||
let%bind program = type_file "./contracts/arithmetic.ligo" in
|
let%bind program = type_file "./contracts/arithmetic.ligo" in
|
||||||
let aux (name, f) =
|
|
||||||
let aux n =
|
|
||||||
let open AST_Typed.Combinators in
|
|
||||||
let input = if name = "int_op" then e_a_empty_nat n else e_a_empty_int n in
|
|
||||||
let%bind result = easy_run_typed name program input in
|
|
||||||
AST_Typed.assert_value_eq (f n, result)
|
|
||||||
in
|
|
||||||
let%bind _ = bind_list
|
|
||||||
@@ List.map aux [0 ; 42 ; 128] in
|
|
||||||
ok ()
|
|
||||||
in
|
|
||||||
let%bind _ =
|
let%bind _ =
|
||||||
let open AST_Typed.Combinators in
|
let aux (name , f) = expect_n_int program name f in
|
||||||
bind_list
|
bind_map_list aux [
|
||||||
@@ List.map aux
|
("plus_op", fun n -> (n + 42)) ;
|
||||||
@@ [
|
("minus_op", fun n -> (n - 42)) ;
|
||||||
("plus_op", fun n -> e_a_empty_int (n + 42)) ;
|
("times_op", fun n -> (n * 42)) ;
|
||||||
("minus_op", fun n -> e_a_empty_int (n - 42)) ;
|
|
||||||
("times_op", fun n -> e_a_empty_int (n * 42)) ;
|
|
||||||
("int_op", fun n -> e_a_empty_int n) ;
|
|
||||||
] in
|
] in
|
||||||
|
let%bind () = expect_n_pos program "int_op" e_a_nat e_a_int in
|
||||||
ok ()
|
ok ()
|
||||||
|
|
||||||
let unit_expression () : unit result =
|
let unit_expression () : unit result =
|
||||||
let%bind program = type_file "./contracts/unit.ligo" in
|
let%bind program = type_file "./contracts/unit.ligo" in
|
||||||
let open AST_Typed.Combinators in
|
expect_evaluate program "u" e_a_unit
|
||||||
let%bind result = easy_evaluate_typed "u" program in
|
|
||||||
let%bind () =
|
|
||||||
trace (simple_error "result isn't unit") @@
|
|
||||||
get_a_unit result in
|
|
||||||
ok ()
|
|
||||||
|
|
||||||
let include_ () : unit result =
|
let include_ () : unit result =
|
||||||
let%bind program = type_file "./contracts/includer.ligo" in
|
let%bind program = type_file "./contracts/includer.ligo" in
|
||||||
let%bind result = easy_evaluate_typed "bar" program in
|
expect_evaluate program "bar" (e_a_int 144)
|
||||||
let%bind n =
|
|
||||||
trace (simple_error "Include failed") @@
|
|
||||||
AST_Typed.Combinators.get_a_int result in
|
|
||||||
Assert.assert_equal_int 144 n
|
|
||||||
|
|
||||||
let record_ez_int names n =
|
let record_ez_int names n =
|
||||||
let open AST_Typed.Combinators in
|
ez_e_a_record @@ List.map (fun x -> x, e_a_int n) names
|
||||||
ez_e_a_empty_record @@ List.map (fun x -> x, e_a_empty_int n) names
|
|
||||||
|
|
||||||
let multiple_parameters () : unit result =
|
let multiple_parameters () : unit result =
|
||||||
let%bind program = type_file "./contracts/multiple-parameters.ligo" in
|
let%bind program = type_file "./contracts/multiple-parameters.ligo" in
|
||||||
let inputs = [0 ; 2 ; 42 ; 163 ; -1] in
|
let aux ((name : string) , make_input , make_output) =
|
||||||
let aux (name, input_f, output_f) =
|
let make_output' = fun n -> e_a_int @@ make_output n in
|
||||||
let aux n =
|
expect_n program name make_input make_output'
|
||||||
let input = input_f n in
|
|
||||||
let%bind result = easy_run_typed name program input in
|
|
||||||
let%bind result' = AST_Typed.Combinators.get_a_int result in
|
|
||||||
let expected = output_f n in
|
|
||||||
let%bind _ = Assert.assert_equal_int expected result' in
|
|
||||||
ok ()
|
|
||||||
in
|
|
||||||
let%bind _ = bind_list @@ List.map aux inputs in
|
|
||||||
ok ()
|
|
||||||
in
|
in
|
||||||
let%bind _ = bind_list @@ List.map aux [
|
let%bind _ = bind_list @@ List.map aux [
|
||||||
("ab", record_ez_int ["a";"b"], fun n -> 2 * n) ;
|
("ab", record_ez_int ["a";"b"], fun n -> 2 * n) ;
|
||||||
@ -221,336 +102,192 @@ let multiple_parameters () : unit result =
|
|||||||
|
|
||||||
let record () : unit result =
|
let record () : unit result =
|
||||||
let%bind program = type_file "./contracts/record.ligo" in
|
let%bind program = type_file "./contracts/record.ligo" in
|
||||||
let%bind _foobar =
|
let%bind () =
|
||||||
let%bind result = easy_evaluate_typed "fb" program in
|
let expected = record_ez_int ["foo" ; "bar"] 0 in
|
||||||
let expect = record_ez_int ["foo";"bar"] 0 in
|
expect_evaluate program "fb" expected
|
||||||
AST_Typed.assert_value_eq (expect, result)
|
|
||||||
in
|
in
|
||||||
let%bind _projection =
|
let%bind () =
|
||||||
let aux n =
|
let make_input = record_ez_int ["foo" ; "bar"] in
|
||||||
let input = record_ez_int ["foo";"bar"] n in
|
let make_expected = fun n -> e_a_int (2 * n) in
|
||||||
let%bind result = easy_run_typed "projection" program input in
|
expect_n program "projection" make_input make_expected
|
||||||
let expect = AST_Typed.Combinators.e_a_empty_int (2 * n) in
|
|
||||||
AST_Typed.assert_value_eq (expect, result)
|
|
||||||
in
|
|
||||||
bind_list @@ List.map aux [0 ; -42 ; 144]
|
|
||||||
in
|
in
|
||||||
let%bind _big =
|
let%bind () =
|
||||||
let%bind result = easy_evaluate_typed "br" program in
|
let expected = record_ez_int ["a";"b";"c";"d";"e"] 23 in
|
||||||
let expect = record_ez_int ["a";"b";"c";"d";"e"] 23 in
|
expect_evaluate program "br" expected
|
||||||
AST_Typed.assert_value_eq (expect, result)
|
|
||||||
in
|
in
|
||||||
ok ()
|
ok ()
|
||||||
|
|
||||||
let tuple () : unit result =
|
let tuple () : unit result =
|
||||||
let%bind program = type_file "./contracts/tuple.ligo" in
|
let%bind program = type_file "./contracts/tuple.ligo" in
|
||||||
let ez n =
|
let ez n =
|
||||||
let open AST_Typed.Combinators in
|
e_a_tuple (List.map e_a_int n) in
|
||||||
e_a_empty_tuple (List.map e_a_empty_int n) in
|
let%bind () =
|
||||||
let%bind _foobar =
|
let expected = ez [0 ; 0] in
|
||||||
trace (simple_error "foobar") (
|
expect_evaluate program "fb" expected
|
||||||
let%bind result = easy_evaluate_typed "fb" program in
|
|
||||||
let expect = ez [0 ; 0] in
|
|
||||||
AST_Typed.assert_value_eq (expect, result)
|
|
||||||
)
|
|
||||||
in
|
in
|
||||||
let%bind _projection = trace (simple_error "projection") (
|
let%bind () =
|
||||||
let aux n =
|
let make_input = fun n -> ez [n ; n] in
|
||||||
let input = ez [n ; n] in
|
let make_expected = fun n -> e_a_int (2 * n) in
|
||||||
let%bind result = easy_run_typed "projection" program input in
|
expect_n program "projection" make_input make_expected
|
||||||
let expect = AST_Typed.Combinators.e_a_empty_int (2 * n) in
|
|
||||||
AST_Typed.assert_value_eq (expect, result)
|
|
||||||
in
|
|
||||||
bind_list @@ List.map aux [0 ; -42 ; 144]
|
|
||||||
)
|
|
||||||
in
|
in
|
||||||
let%bind _big =
|
let%bind () =
|
||||||
let%bind result = easy_evaluate_typed "br" program in
|
let expected = ez [23 ; 23 ; 23 ; 23 ; 23] in
|
||||||
let expect = ez [23 ; 23 ; 23 ; 23 ; 23] in
|
expect_evaluate program "br" expected
|
||||||
AST_Typed.assert_value_eq (expect, result)
|
|
||||||
in
|
in
|
||||||
ok ()
|
ok ()
|
||||||
|
|
||||||
let option () : unit result =
|
let option () : unit result =
|
||||||
let%bind program = type_file "./contracts/option.ligo" in
|
let%bind program = type_file "./contracts/option.ligo" in
|
||||||
let open AST_Typed.Combinators in
|
let%bind () =
|
||||||
let%bind _some = trace (simple_error "some") @@
|
let expected = e_a_some (e_a_int 42) in
|
||||||
let%bind result = easy_evaluate_typed "s" program in
|
expect_evaluate program "s" expected
|
||||||
let expect = e_a_empty_some (e_a_empty_int 42) in
|
|
||||||
AST_Typed.assert_value_eq (expect, result)
|
|
||||||
in
|
in
|
||||||
let%bind _none = trace (simple_error "none") @@
|
let%bind () =
|
||||||
let%bind result = easy_evaluate_typed "n" program in
|
let expected = e_a_none t_int in
|
||||||
let expect = e_a_empty_none (t_int ()) in
|
expect_evaluate program "n" expected
|
||||||
AST_Typed.assert_value_eq (expect, result)
|
|
||||||
in
|
in
|
||||||
ok ()
|
ok ()
|
||||||
|
|
||||||
let map () : unit result =
|
let map () : unit result =
|
||||||
let%bind program = type_file "./contracts/map.ligo" in
|
let%bind program = type_file "./contracts/map.ligo" in
|
||||||
let ez lst =
|
let ez lst =
|
||||||
let open AST_Typed.Combinators in
|
let open Ast_simplified.Combinators in
|
||||||
let lst' = List.map (fun (x, y) -> e_a_empty_int x, e_a_empty_int y) lst in
|
let lst' = List.map (fun (x, y) -> e_a_int x, e_a_int y) lst in
|
||||||
e_a_empty_map lst' (t_int ()) (t_int ())
|
e_a_map lst' t_int t_int
|
||||||
in
|
in
|
||||||
let%bind _get_force = trace (simple_error "get_force") @@
|
let%bind () =
|
||||||
let aux n =
|
let make_input = fun n -> ez [(23, n) ; (42, 4)] in
|
||||||
let input = ez [(23, n) ; (42, 4)] in
|
let make_expected = e_a_int in
|
||||||
let%bind result = easy_run_typed "gf" program input in
|
expect_n program "gf" make_input make_expected
|
||||||
let expect = AST_Typed.Combinators.(e_a_empty_int n) in
|
in
|
||||||
AST_Typed.assert_value_eq (expect, result)
|
let%bind () =
|
||||||
|
let make_input = fun n -> ez List.(map (fun x -> (x, x)) @@ range n) in
|
||||||
|
let make_expected = e_a_nat in
|
||||||
|
expect_n_strict_pos_small program "size_" make_input make_expected
|
||||||
|
in
|
||||||
|
let%bind () =
|
||||||
|
let expected = ez [(23, 0) ; (42, 0)] in
|
||||||
|
expect_evaluate program "fb" expected
|
||||||
|
in
|
||||||
|
let%bind () =
|
||||||
|
let make_input = fun n ->
|
||||||
|
let m = ez [(23 , 0) ; (42 , 0)] in
|
||||||
|
e_a_tuple [(e_a_int n) ; m]
|
||||||
in
|
in
|
||||||
bind_map_list aux [0 ; 42 ; 51 ; 421 ; -3]
|
let make_expected = fun n -> ez [(23 , n) ; (42 , 0)] in
|
||||||
|
expect_n_pos_small program "set_" make_input make_expected
|
||||||
in
|
in
|
||||||
let%bind _size = trace (simple_error "size") @@
|
let%bind () =
|
||||||
let aux n =
|
let make_input = fun n -> ez [(23, n) ; (42, 4)] in
|
||||||
let input = ez List.(map (fun x -> (x, x)) @@ range n) in
|
let make_expected = fun _ -> e_a_some @@ e_a_int 4 in
|
||||||
let%bind result = easy_run_typed "size_" program input in
|
expect_n program "get" make_input make_expected
|
||||||
let expect = AST_Typed.Combinators.(e_a_empty_nat n) in
|
|
||||||
AST_Typed.assert_value_eq (expect, result)
|
|
||||||
in
|
|
||||||
bind_map_list aux [1 ; 10 ; 3]
|
|
||||||
in
|
in
|
||||||
let%bind _foobar = trace (simple_error "foobar") @@
|
let%bind () =
|
||||||
let%bind result = easy_evaluate_typed "fb" program in
|
let expected = ez @@ List.map (fun x -> (x, 23)) [144 ; 51 ; 42 ; 120 ; 421] in
|
||||||
let expect = ez [(23, 0) ; (42, 0)] in
|
expect_evaluate program "bm" expected
|
||||||
AST_Typed.assert_value_eq (expect, result)
|
|
||||||
in
|
in
|
||||||
let%bind _set = trace (simple_error "set") @@
|
let%bind () =
|
||||||
let aux n =
|
|
||||||
let input =
|
|
||||||
let m = ez [(23, 0) ; (42, 0)] in
|
|
||||||
AST_Typed.Combinators.(e_a_empty_tuple [ e_a_empty_int n ; m ])
|
|
||||||
in
|
|
||||||
let%bind result = easy_run_typed "set_" program input in
|
|
||||||
let expect = ez [(23, n) ; (42, 0)] in
|
|
||||||
AST_Typed.assert_value_eq (expect, result)
|
|
||||||
in
|
|
||||||
bind_map_list aux [1 ; 10 ; 3]
|
|
||||||
in
|
|
||||||
let%bind _get = trace (simple_error "get") @@
|
|
||||||
let aux n =
|
|
||||||
let input = ez [(23, n) ; (42, 4)] in
|
|
||||||
let%bind result = easy_run_typed "get" program input in
|
|
||||||
let expect = AST_Typed.Combinators.(e_a_empty_some @@ e_a_empty_int 4) in
|
|
||||||
AST_Typed.assert_value_eq (expect, result)
|
|
||||||
in
|
|
||||||
bind_map_list aux [0 ; 42 ; 51 ; 421 ; -3]
|
|
||||||
in
|
|
||||||
let%bind _bigmap = trace (simple_error "bigmap") @@
|
|
||||||
let%bind result = easy_evaluate_typed "bm" program in
|
|
||||||
let expect = ez @@ List.map (fun x -> (x, 23)) [144 ; 51 ; 42 ; 120 ; 421] in
|
|
||||||
AST_Typed.assert_value_eq (expect, result)
|
|
||||||
in
|
|
||||||
let%bind _remove = trace (simple_error "rm") @@
|
|
||||||
let input = ez [(23, 23) ; (42, 42)] in
|
let input = ez [(23, 23) ; (42, 42)] in
|
||||||
let%bind result = easy_run_typed "rm" program input in
|
let expected = ez [23, 23] in
|
||||||
let expect = ez [23, 23] in
|
expect program "rm" input expected
|
||||||
AST_Typed.assert_value_eq (expect, result)
|
|
||||||
in
|
in
|
||||||
ok ()
|
ok ()
|
||||||
|
|
||||||
let list () : unit result =
|
let list () : unit result =
|
||||||
let%bind program = type_file "./contracts/list.ligo" in
|
let%bind program = type_file "./contracts/list.ligo" in
|
||||||
let ez lst =
|
let ez lst =
|
||||||
let open AST_Typed.Combinators in
|
let lst' = List.map e_a_int lst in
|
||||||
let lst' = List.map e_a_empty_int lst in
|
e_a_list lst' t_int
|
||||||
e_a_empty_list lst' (t_int ())
|
|
||||||
in
|
in
|
||||||
let%bind _size = trace (simple_error "size") @@
|
let%bind () =
|
||||||
let aux n =
|
let make_input = fun n -> (ez @@ List.range n) in
|
||||||
let input = ez (List.range n) in
|
let make_expected = e_a_nat in
|
||||||
let%bind result = easy_run_typed "size_" program input in
|
expect_n_strict_pos_small program "size_" make_input make_expected
|
||||||
let expect = AST_Typed.Combinators.(e_a_empty_nat n) in
|
|
||||||
AST_Typed.assert_value_eq (expect, result)
|
|
||||||
in
|
|
||||||
bind_map_list aux [1 ; 10 ; 3]
|
|
||||||
in
|
in
|
||||||
let%bind _foobar = trace (simple_error "foobar") @@
|
let%bind () =
|
||||||
let%bind result = easy_evaluate_typed "fb" program in
|
let expected = ez [23 ; 42] in
|
||||||
let expect = ez [23 ; 42] in
|
expect_evaluate program "fb" expected
|
||||||
AST_Typed.assert_value_eq (expect, result)
|
|
||||||
in
|
in
|
||||||
let%bind _biglist = trace (simple_error "biglist") @@
|
let%bind () =
|
||||||
let%bind result = easy_evaluate_typed "bl" program in
|
let expected = ez [144 ; 51 ; 42 ; 120 ; 421] in
|
||||||
let expect = ez [144 ; 51 ; 42 ; 120 ; 421] in
|
expect_evaluate program "bl" expected
|
||||||
AST_Typed.assert_value_eq (expect, result)
|
|
||||||
in
|
in
|
||||||
ok ()
|
ok ()
|
||||||
|
|
||||||
let condition () : unit result =
|
let condition () : unit result =
|
||||||
let%bind program = type_file "./contracts/condition.ligo" in
|
let%bind program = type_file "./contracts/condition.ligo" in
|
||||||
let aux n =
|
let make_input = e_a_int in
|
||||||
let open AST_Typed.Combinators in
|
let make_expected = fun n -> e_a_int (if n = 2 then 42 else 0) in
|
||||||
let input = e_a_empty_int n in
|
expect_n program "main" make_input make_expected
|
||||||
let%bind result = easy_run_main_typed program input in
|
|
||||||
let%bind result' =
|
|
||||||
trace (simple_error "bad result") @@
|
|
||||||
get_a_int result in
|
|
||||||
Assert.assert_equal_int (if n = 2 then 42 else 0) result'
|
|
||||||
in
|
|
||||||
let%bind _ = bind_list
|
|
||||||
@@ List.map aux
|
|
||||||
@@ [0 ; 2 ; 42 ; 163 ; -1] in
|
|
||||||
ok ()
|
|
||||||
|
|
||||||
let loop () : unit result =
|
let loop () : unit result =
|
||||||
let%bind program = type_file "./contracts/loop.ligo" in
|
let%bind program = type_file "./contracts/loop.ligo" in
|
||||||
let%bind _dummy = trace (simple_error "dummy") @@
|
let%bind () =
|
||||||
let aux n =
|
let make_input = e_a_nat in
|
||||||
let open AST_Typed.Combinators in
|
let make_expected = e_a_nat in
|
||||||
let input = e_a_empty_nat n in
|
expect_n_pos program "dummy" make_input make_expected
|
||||||
let%bind result = easy_run_typed "dummy" program input in
|
|
||||||
let expected = e_a_empty_nat n in
|
|
||||||
AST_Typed.assert_value_eq (expected, result)
|
|
||||||
in
|
|
||||||
let%bind _ = bind_list
|
|
||||||
@@ List.map aux
|
|
||||||
@@ [0 ; 2 ; 42 ; 163] in
|
|
||||||
ok ()
|
|
||||||
in
|
in
|
||||||
let%bind _counter = trace (simple_error "counter") @@
|
let%bind () =
|
||||||
let aux n =
|
let make_input = e_a_nat in
|
||||||
let open AST_Typed.Combinators in
|
let make_expected = e_a_nat in
|
||||||
let input = e_a_empty_nat n in
|
expect_n_pos_mid program "counter" make_input make_expected
|
||||||
let%bind result = easy_run_typed "counter" program input in
|
|
||||||
let expected = e_a_empty_nat n in
|
|
||||||
AST_Typed.assert_value_eq (expected, result)
|
|
||||||
in
|
|
||||||
let%bind _ = bind_list
|
|
||||||
@@ List.map aux
|
|
||||||
@@ [0 ; 2 ; 42 ; 12] in
|
|
||||||
ok ()
|
|
||||||
in
|
in
|
||||||
let%bind _sum = trace (simple_error "sum") @@
|
let%bind () =
|
||||||
let aux n =
|
let make_input = e_a_nat in
|
||||||
let open AST_Typed.Combinators in
|
let make_expected = fun n -> e_a_nat (n * (n + 1) / 2) in
|
||||||
let input = e_a_empty_nat n in
|
expect_n_pos_mid program "sum" make_input make_expected
|
||||||
let%bind result = easy_run_typed "sum" program input in
|
|
||||||
let expected = e_a_empty_nat (n * (n + 1) / 2) in
|
|
||||||
AST_Typed.assert_value_eq (expected, result)
|
|
||||||
in
|
|
||||||
let%bind _ = bind_list
|
|
||||||
@@ List.map aux
|
|
||||||
@@ [0 ; 2 ; 42 ; 12] in
|
|
||||||
ok ()
|
|
||||||
in
|
in
|
||||||
ok()
|
ok()
|
||||||
|
|
||||||
|
|
||||||
let matching () : unit result =
|
let matching () : unit result =
|
||||||
let%bind program = type_file "./contracts/match.ligo" in
|
let%bind program = type_file "./contracts/match.ligo" in
|
||||||
let%bind _bool =
|
let%bind () =
|
||||||
let aux n =
|
let make_input = e_a_int in
|
||||||
let open AST_Typed.Combinators in
|
let make_expected = fun n -> e_a_int (if n = 2 then 42 else 0) in
|
||||||
let input = e_a_empty_int n in
|
expect_n program "match_bool" make_input make_expected
|
||||||
let%bind result = easy_run_typed "match_bool" program input in
|
|
||||||
let%bind result' =
|
|
||||||
trace (simple_error "bad result") @@
|
|
||||||
get_a_int result in
|
|
||||||
Assert.assert_equal_int (if n = 2 then 42 else 0) result'
|
|
||||||
in
|
|
||||||
let%bind _ = bind_list
|
|
||||||
@@ List.map aux
|
|
||||||
@@ [0 ; 2 ; 42 ; 163 ; -1] in
|
|
||||||
ok ()
|
|
||||||
in
|
in
|
||||||
let%bind _expr_bool =
|
let%bind () =
|
||||||
let aux n =
|
let make_input = e_a_int in
|
||||||
let open AST_Typed.Combinators in
|
let make_expected = fun n-> e_a_int (if n = 2 then 42 else 0) in
|
||||||
let input = e_a_empty_int n in
|
expect_n program "match_expr_bool" make_input make_expected
|
||||||
let%bind result = easy_run_typed "match_expr_bool" program input in
|
|
||||||
let%bind result' =
|
|
||||||
trace (simple_error "bad result") @@
|
|
||||||
get_a_int result in
|
|
||||||
Assert.assert_equal_int (if n = 2 then 42 else 0) result'
|
|
||||||
in
|
|
||||||
let%bind _ = bind_list
|
|
||||||
@@ List.map aux
|
|
||||||
@@ [0 ; 2 ; 42 ; 163 ; -1] in
|
|
||||||
ok ()
|
|
||||||
in
|
in
|
||||||
let%bind _option =
|
let%bind () =
|
||||||
let aux n =
|
let aux n =
|
||||||
let open AST_Typed.Combinators in
|
|
||||||
let input = match n with
|
let input = match n with
|
||||||
| Some s -> e_a_empty_some (e_a_empty_int s)
|
| Some s -> e_a_some (e_a_int s)
|
||||||
| None -> e_a_empty_none (t_int ()) in
|
| None -> e_a_none t_int in
|
||||||
let%bind result = easy_run_typed "match_option" program input in
|
let expected = e_a_int 23 in
|
||||||
let%bind result' =
|
expect program "match_option" input expected
|
||||||
trace (simple_error "bad result") @@
|
|
||||||
get_a_int result in
|
|
||||||
Assert.assert_equal_int 23 result'
|
|
||||||
(* Assert.assert_equal_int (match n with None -> 23 | Some s -> s) result' *)
|
|
||||||
in
|
in
|
||||||
let%bind _ = bind_list
|
bind_iter_list aux
|
||||||
@@ List.map aux
|
[Some 0 ; Some 2 ; Some 42 ; Some 163 ; Some (-1) ; None]
|
||||||
@@ [Some 0 ; Some 2 ; Some 42 ; Some 163 ; Some (-1) ; None] in
|
|
||||||
ok ()
|
|
||||||
in
|
in
|
||||||
ok ()
|
ok ()
|
||||||
|
|
||||||
let declarations () : unit result =
|
let declarations () : unit result =
|
||||||
let%bind program = type_file "./contracts/declarations.ligo" in
|
let%bind program = type_file "./contracts/declarations.ligo" in
|
||||||
let aux n =
|
let make_input = e_a_int in
|
||||||
let open AST_Typed.Combinators in
|
let make_expected = fun n -> e_a_int (42 + n) in
|
||||||
let input = e_a_empty_int n in
|
expect_n program "main" make_input make_expected
|
||||||
let%bind result = easy_run_main_typed program input in
|
|
||||||
let%bind result' =
|
|
||||||
trace (simple_error "bad result") @@
|
|
||||||
get_a_int result in
|
|
||||||
Assert.assert_equal_int (42 + n) result'
|
|
||||||
in
|
|
||||||
let%bind _ = bind_list
|
|
||||||
@@ List.map aux
|
|
||||||
@@ [0 ; 2 ; 42 ; 163 ; -1] in
|
|
||||||
ok ()
|
|
||||||
|
|
||||||
let quote_declaration () : unit result =
|
let quote_declaration () : unit result =
|
||||||
let%bind program = type_file "./contracts/quote-declaration.ligo" in
|
let%bind program = type_file "./contracts/quote-declaration.ligo" in
|
||||||
let aux n =
|
let make_input = e_a_int in
|
||||||
let open AST_Typed.Combinators in
|
let make_expected = fun n -> e_a_int (42 + 2 * n) in
|
||||||
let input = e_a_empty_int n in
|
expect_n program "main" make_input make_expected
|
||||||
let%bind result = easy_run_main_typed program input in
|
|
||||||
let%bind result' =
|
|
||||||
trace (simple_error "bad result") @@
|
|
||||||
get_a_int result in
|
|
||||||
Assert.assert_equal_int result' (42 + 2 * n)
|
|
||||||
in
|
|
||||||
let%bind _ = bind_list
|
|
||||||
@@ List.map aux
|
|
||||||
@@ [0 ; 2 ; 42 ; 163 ; -1] in
|
|
||||||
ok ()
|
|
||||||
|
|
||||||
let quote_declarations () : unit result =
|
let quote_declarations () : unit result =
|
||||||
let%bind program = type_file "./contracts/quote-declarations.ligo" in
|
let%bind program = type_file "./contracts/quote-declarations.ligo" in
|
||||||
let aux n =
|
let make_input = e_a_int in
|
||||||
let open AST_Typed.Combinators in
|
let make_expected = fun n -> e_a_int (74 + 2 * n) in
|
||||||
let input = e_a_empty_int n in
|
expect_n program "main" make_input make_expected
|
||||||
let%bind result = easy_run_main_typed program input in
|
|
||||||
let%bind result' =
|
|
||||||
trace (simple_error "bad result") @@
|
|
||||||
get_a_int result in
|
|
||||||
Assert.assert_equal_int result' (74 + 2 * n)
|
|
||||||
in
|
|
||||||
let%bind _ = bind_list
|
|
||||||
@@ List.map aux
|
|
||||||
@@ [0 ; 2 ; 42 ; 163 ; -1] in
|
|
||||||
ok ()
|
|
||||||
|
|
||||||
let counter_contract () : unit result =
|
let counter_contract () : unit result =
|
||||||
let%bind program = type_file "./contracts/counter.ligo" in
|
let%bind program = type_file "./contracts/counter.ligo" in
|
||||||
let aux n =
|
let make_input = fun n-> e_a_pair (e_a_int n) (e_a_int 42) in
|
||||||
let open AST_Typed.Combinators in
|
let make_expected = fun n -> e_a_pair (e_a_list [] (t_int)) (e_a_int (42 + n)) in
|
||||||
let input = e_a_empty_pair (e_a_empty_int n) (e_a_empty_int 42) in
|
expect_n program "main" make_input make_expected
|
||||||
let%bind result = easy_run_main_typed program input in
|
|
||||||
let expected = e_a_empty_pair (e_a_empty_list [] (t_int ())) (e_a_empty_int (42 + n)) in
|
|
||||||
AST_Typed.assert_value_eq (result, expected)
|
|
||||||
in
|
|
||||||
let%bind _ = bind_list
|
|
||||||
@@ List.map aux
|
|
||||||
@@ [0 ; 2 ; 42 ; 163 ; -1] in
|
|
||||||
ok ()
|
|
||||||
|
|
||||||
let main = "Integration (End to End)", [
|
let main = "Integration (End to End)", [
|
||||||
test "function" function_ ;
|
test "function" function_ ;
|
||||||
|
@ -10,3 +10,55 @@ let test name f =
|
|||||||
| Errors errs ->
|
| Errors errs ->
|
||||||
Format.printf "Errors : {\n%a}\n%!" errors_pp (List.rev (List.rev_map (fun f -> f ()) errs)) ;
|
Format.printf "Errors : {\n%a}\n%!" errors_pp (List.rev (List.rev_map (fun f -> f ()) errs)) ;
|
||||||
raise Alcotest.Test_error
|
raise Alcotest.Test_error
|
||||||
|
|
||||||
|
open Ast_simplified.Combinators
|
||||||
|
|
||||||
|
let expect program entry_point input expected =
|
||||||
|
let error =
|
||||||
|
let title () = "expect run" in
|
||||||
|
let content () = Format.asprintf "Entry_point: %s" entry_point in
|
||||||
|
error title content in
|
||||||
|
trace error @@
|
||||||
|
let%bind result = Ligo.easy_run_typed_simplified entry_point program input in
|
||||||
|
Ast_simplified.assert_value_eq (expected , result)
|
||||||
|
|
||||||
|
let expect_evaluate program entry_point expected =
|
||||||
|
let error =
|
||||||
|
let title () = "expect evaluate" in
|
||||||
|
let content () = Format.asprintf "Entry_point: %s" entry_point in
|
||||||
|
error title content in
|
||||||
|
trace error @@
|
||||||
|
let%bind result = Ligo.easy_evaluate_typed_simplified entry_point program in
|
||||||
|
Ast_simplified.assert_value_eq (expected , result)
|
||||||
|
|
||||||
|
let expect_n_aux lst program entry_point make_input make_expected =
|
||||||
|
let aux n =
|
||||||
|
let input = make_input n in
|
||||||
|
let expected = make_expected n in
|
||||||
|
expect program entry_point input expected
|
||||||
|
in
|
||||||
|
let%bind _ = bind_map_list aux lst in
|
||||||
|
ok ()
|
||||||
|
|
||||||
|
let expect_n = expect_n_aux [0 ; 2 ; 42 ; 163 ; -1]
|
||||||
|
let expect_n_pos = expect_n_aux [0 ; 2 ; 42 ; 163]
|
||||||
|
let expect_n_strict_pos = expect_n_aux [2 ; 42 ; 163]
|
||||||
|
let expect_n_pos_small = expect_n_aux [0 ; 2 ; 10]
|
||||||
|
let expect_n_strict_pos_small = expect_n_aux [2 ; 10]
|
||||||
|
let expect_n_pos_mid = expect_n_aux [0 ; 2 ; 10 ; 33]
|
||||||
|
|
||||||
|
let expect_b program entry_point make_expected =
|
||||||
|
let aux b =
|
||||||
|
let input = e_a_bool b in
|
||||||
|
let expected = make_expected b in
|
||||||
|
expect program entry_point input expected
|
||||||
|
in
|
||||||
|
let%bind _ = bind_map_list aux [false ; true] in
|
||||||
|
ok ()
|
||||||
|
|
||||||
|
let expect_n_int a b c =
|
||||||
|
expect_n a b e_a_int (fun n -> e_a_int (c n))
|
||||||
|
|
||||||
|
let expect_b_bool a b c =
|
||||||
|
let open Ast_simplified.Combinators in
|
||||||
|
expect_b a b (fun bool -> e_a_bool (c bool))
|
||||||
|
Loading…
Reference in New Issue
Block a user