better test

This commit is contained in:
Galfour 2019-03-26 07:28:01 +00:00
parent 10bcecc490
commit 043387ec14
3 changed files with 37 additions and 9 deletions

View File

@ -355,4 +355,11 @@ module Combinators = struct
Record map Record map
let int n : expression = Literal (Int n) let int n : expression = Literal (Int n)
let a_int n = annotated_expression (int n) make_t_int
let get_a_int (t:annotated_expression) =
match t.expression with
| Literal (Int n) -> ok n
| _ -> simple_fail "not an int"
end end

View File

@ -91,29 +91,36 @@ let transpile_value ?(env:Mini_c.Environment.t = Mini_c.Environment.empty)
let untranspile_value (v : Mini_c.value) (e:AST_Typed.type_value) : AST_Typed.annotated_expression result = let untranspile_value (v : Mini_c.value) (e:AST_Typed.type_value) : AST_Typed.annotated_expression result =
Transpiler.untranspile v e Transpiler.untranspile v e
let easy_run_main (path:string) (input:string) : AST_Typed.annotated_expression result = let type_file (path:string) : AST_Typed.program result =
let%bind raw = parse_file path in let%bind raw = parse_file path in
let%bind simpl = simplify raw in let%bind simpl = simplify raw in
let%bind typed = let%bind typed =
trace (simple_error "typing") @@ trace (simple_error "typing") @@
type_ simpl in type_ simpl in
ok typed
let easy_run_main_typed (program:AST_Typed.program) (input:AST_Typed.annotated_expression) : AST_Typed.annotated_expression result =
let%bind mini_c_main = let%bind mini_c_main =
trace (simple_error "transpile mini_c main") @@ trace (simple_error "transpile mini_c main") @@
transpile_entry typed "main" in transpile_entry program "main" in
let%bind mini_c_value = transpile_value input in
let%bind raw_expr = parse_expression input in
let%bind simpl_expr = simplify_expr raw_expr in
let%bind typed_expr = type_expression simpl_expr in
let%bind mini_c_value = transpile_value typed_expr in
let%bind mini_c_result = let%bind mini_c_result =
trace (simple_error "run mini_c") @@ trace (simple_error "run mini_c") @@
Mini_c.Run.run_entry mini_c_main mini_c_value in Mini_c.Run.run_entry mini_c_main mini_c_value in
let%bind typed_result = let%bind typed_result =
let%bind main_result_type = let%bind main_result_type =
let%bind typed_main = Ast_typed.get_entry typed "main" in let%bind typed_main = Ast_typed.get_entry program "main" in
match (snd typed_main).type_value with match (snd typed_main).type_value with
| Type_function (_, result) -> ok result | Type_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 ok typed_result
let easy_run_main (path:string) (input:string) : AST_Typed.annotated_expression result =
let%bind typed = type_file path in
let%bind raw_expr = parse_expression input in
let%bind simpl_expr = simplify_expr raw_expr in
let%bind typed_expr = type_expression simpl_expr in
easy_run_main_typed typed typed_expr

View File

@ -26,7 +26,21 @@ let function_ () : unit result =
ok () ok ()
let declarations () : unit result = let declarations () : unit result =
let%bind _ = easy_run_main "./contracts/declarations.ligo" "2" in let%bind program = type_file "./contracts/declarations.ligo" in
Format.printf "toto\n%!" ;
Printf.printf "toto\n%!" ;
let aux n =
let open AST_Typed.Combinators in
let input = a_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 result' (42 + n)
in
let%bind _ = bind_list
@@ List.map aux
@@ [0 ; 2 ; 42 ; 163 ; -1] in
ok () ok ()
let main = "Integration (End to End)", [ let main = "Integration (End to End)", [