From c2c774ba756e7578cea293bb30015aa4d08d992c Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Thu, 21 Nov 2019 06:02:47 -0800 Subject: [PATCH] Add closure test to CameLIGO --- src/test/contracts/closure.mligo | 9 +++++++++ src/test/integration_tests.ml | 10 ++++++++++ 2 files changed, 19 insertions(+) create mode 100644 src/test/contracts/closure.mligo diff --git a/src/test/contracts/closure.mligo b/src/test/contracts/closure.mligo new file mode 100644 index 000000000..ee5f616ae --- /dev/null +++ b/src/test/contracts/closure.mligo @@ -0,0 +1,9 @@ +(* Test whether closures retain values in CameLIGO *) + +let test (k: int) : int = + let j: int = k + 5 in + let close: (int -> int) = + fun (i: int) -> i + j + in + let j: int = 20 in (* Shadow original variable to see if value close'd *) + close 20 diff --git a/src/test/integration_tests.ml b/src/test/integration_tests.ml index 2a7370845..8db3a0a2c 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -134,6 +134,15 @@ let closure () : unit result = in ok () +let closure_mligo () : unit result = + let%bind program = mtype_file "./contracts/closure.mligo" in + let%bind _ = + let input = e_int 0 in + let expected = e_int 25 in + expect_eq program "test" input expected + in + ok () + let shadow () : unit result = let%bind program = type_file "./contracts/shadow.ligo" in let make_expect = fun _ -> 0 in @@ -1269,6 +1278,7 @@ let main = test_suite "Integration (End to End)" [ test "anon function" anon_function ; test "various applications" application ; test "closure" closure ; + test "closure (mligo)" closure_mligo ; test "shared function" shared_function ; test "shared function (mligo)" shared_function_mligo ; test "higher order" higher_order ;