Add closure test to CameLIGO
This commit is contained in:
parent
ae7c92844c
commit
c2c774ba75
9
src/test/contracts/closure.mligo
Normal file
9
src/test/contracts/closure.mligo
Normal file
@ -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
|
@ -134,6 +134,15 @@ let closure () : unit result =
|
|||||||
in
|
in
|
||||||
ok ()
|
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 shadow () : unit result =
|
||||||
let%bind program = type_file "./contracts/shadow.ligo" in
|
let%bind program = type_file "./contracts/shadow.ligo" in
|
||||||
let make_expect = fun _ -> 0 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 "anon function" anon_function ;
|
||||||
test "various applications" application ;
|
test "various applications" application ;
|
||||||
test "closure" closure ;
|
test "closure" closure ;
|
||||||
|
test "closure (mligo)" closure_mligo ;
|
||||||
test "shared function" shared_function ;
|
test "shared function" shared_function ;
|
||||||
test "shared function (mligo)" shared_function_mligo ;
|
test "shared function (mligo)" shared_function_mligo ;
|
||||||
test "higher order" higher_order ;
|
test "higher order" higher_order ;
|
||||||
|
Loading…
Reference in New Issue
Block a user