ligo/src/test/compiler_tests.ml

35 lines
1.0 KiB
OCaml
Raw Normal View History

2019-05-13 00:56:22 +04:00
open Trace
2019-09-18 20:49:33 +04:00
open Mini_c
2019-05-13 00:56:22 +04:00
open Combinators
open Test_helpers
2019-09-19 03:34:37 +04:00
let run_entry_int e (n:int) : int result =
2019-05-13 00:56:22 +04:00
let param : value = D_int n in
2019-09-19 14:59:07 +04:00
let%bind result = Run.Of_mini_c.run_function_value e param t_int in
2019-05-13 00:56:22 +04:00
match result with
| D_int n -> ok n
| _ -> simple_fail "result is not an int"
let identity () : unit result =
2019-05-20 20:17:26 +04:00
let%bind f = basic_int_quote (e_var_int "input") in
2019-05-13 00:56:22 +04:00
let%bind result = run_entry_int f 42 in
let%bind _ = Assert.assert_equal_int ~msg:__LOC__ 42 result in
ok ()
let multiple_vars () : unit result =
2019-05-20 20:17:26 +04:00
let expr =
2019-09-19 03:34:37 +04:00
e_let_in "a" t_int (e_var_int "input") @@
e_let_in "b" t_int (e_var_int "input") @@
e_let_in "c" t_int (e_var_int "a") @@
e_let_in "output" t_int (e_var_int "c") @@
2019-05-20 20:17:26 +04:00
e_var_int "output" in
let%bind f = basic_int_quote expr in
2019-05-13 00:56:22 +04:00
let%bind result = run_entry_int f 42 in
let%bind _ = Assert.assert_equal_int ~msg:__LOC__ 42 result in
ok ()
2019-06-05 10:43:33 +04:00
let main = test_suite "Compiler (from Mini_C)" [
2019-05-13 00:56:22 +04:00
test "identity" identity ;
test "multiple_vars" multiple_vars ;
]