From a8def8c2694a2a96fd6d219529aa28bcfe5a384d Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Tue, 24 Sep 2019 12:18:07 -0700 Subject: [PATCH 1/3] Add test for boolean not --- src/contracts/boolean_operators.ligo | 3 +++ src/test/integration_tests.ml | 1 + 2 files changed, 4 insertions(+) diff --git a/src/contracts/boolean_operators.ligo b/src/contracts/boolean_operators.ligo index 4b53ff2d5..0d88c0f03 100644 --- a/src/contracts/boolean_operators.ligo +++ b/src/contracts/boolean_operators.ligo @@ -11,3 +11,6 @@ function and_true (const b : bool) : bool is function and_false (const b : bool) : bool is begin skip end with b and False + +function not_bool (const b: bool) : bool is + begin skip end with not b diff --git a/src/test/integration_tests.ml b/src/test/integration_tests.ml index baea8d256..9582122d4 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -127,6 +127,7 @@ let bool_expression () : unit result = ("or_false", fun b -> b || false) ; ("and_true", fun b -> b && true) ; ("and_false", fun b -> b && false) ; + ("not_bool", fun b -> not b) ; ] in ok () From ada8a2b70360619ef0844d75d7aa8edf5c030819 Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Tue, 24 Sep 2019 15:47:04 -0700 Subject: [PATCH 2/3] Add (commented out) for loop test & working procedure test Also clean up typo in unsupported for loop error message --- src/contracts/for_fail.ligo | 11 +++++++++++ src/contracts/loop.ligo | 9 ++++++++- src/contracts/procedure.ligo | 6 ++++++ src/simplify/pascaligo.ml | 2 +- src/test/integration_tests.ml | 22 ++++++++++++++++++++-- 5 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 src/contracts/for_fail.ligo create mode 100644 src/contracts/procedure.ligo diff --git a/src/contracts/for_fail.ligo b/src/contracts/for_fail.ligo new file mode 100644 index 000000000..0a177bca1 --- /dev/null +++ b/src/contracts/for_fail.ligo @@ -0,0 +1,11 @@ +// This was meant to test the for loop in PascaLIGO +// But for whatever reason, the LIGO compiler currently thinks this is a 'complex loop' +// even though it isn't. +// See this error: +// $ ligo dry-run for.ligo main 0 0 +// bounded iterators: only simple for loops are supported yet +// {"loop_loc":"in file \"for.ligo\", line 4, characters 10-42"} + + +function main (const a: int) : int is + block { for i := 0 to 100 block { skip } } with i; diff --git a/src/contracts/loop.ligo b/src/contracts/loop.ligo index fcba9fda7..13c47983c 100644 --- a/src/contracts/loop.ligo +++ b/src/contracts/loop.ligo @@ -7,7 +7,7 @@ function counter (var n : nat) : nat is block { } } with i -function sum (var n : nat) : nat is block { +function while_sum (var n : nat) : nat is block { var i : nat := 0n ; var r : nat := 0n ; while (i < n) block { @@ -16,6 +16,13 @@ function sum (var n : nat) : nat is block { } } with r +function for_sum (var n : nat) : nat is block { + for i := 1 to 100 + begin + n := n + 1; + end } + with n + function dummy (const n : nat) : nat is block { while (False) block { skip } } with n diff --git a/src/contracts/procedure.ligo b/src/contracts/procedure.ligo new file mode 100644 index 000000000..fe63d191b --- /dev/null +++ b/src/contracts/procedure.ligo @@ -0,0 +1,6 @@ +// Test a trivial PascaLIGO procedure + +procedure main (const i : int) : int is + begin + skip + end with i diff --git a/src/simplify/pascaligo.ml b/src/simplify/pascaligo.ml index 4aeab4d2a..4b736e068 100644 --- a/src/simplify/pascaligo.ml +++ b/src/simplify/pascaligo.ml @@ -145,7 +145,7 @@ module Errors = struct let unsupported_for_loops region = let title () = "bounded iterators" in let message () = - Format.asprintf "only simple for loops are supported yet" in + Format.asprintf "only simple for loops are supported for now" in let data = [ ("loop_loc", fun () -> Format.asprintf "%a" Location.pp_lift @@ region) diff --git a/src/test/integration_tests.ml b/src/test/integration_tests.ml index 9582122d4..2382b8719 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -16,6 +16,11 @@ let function_ () : unit result = let make_expect = fun n -> n in expect_eq_n_int program "main" make_expect +let procedure () : unit result = + let%bind program = type_file "./contracts/procedure.ligo" in + let make_expect = fun n -> n in + expect_eq_n_int program "main" make_expect + let assign () : unit result = let%bind program = type_file "./contracts/assign.ligo" in let make_expect = fun n -> n + 1 in @@ -459,10 +464,22 @@ let loop () : unit result = let%bind () = let make_input = e_nat in let make_expected = fun n -> e_nat (n * (n + 1) / 2) in - expect_eq_n_pos_mid program "sum" make_input make_expected - in + expect_eq_n_pos_mid program "while_sum" make_input make_expected + in(* For loop is currently unsupported + + let%bind () = + let make_input = e_nat in + let make_expected = fun n -> e_nat (n * (n + 1) / 2) in + expect_eq_n_pos_mid program "for_sum" make_input make_expected + in *) ok () +(* Don't know how to assert parse error happens in this test framework +let for_fail () : unit result = + let%bind program = type_file "./contracts/for_fail.ligo" in + let%bind () = expect_fail program "main" (e_nat 0) + in ok () *) + let matching () : unit result = let%bind program = type_file "./contracts/match.ligo" in let%bind () = @@ -666,6 +683,7 @@ let website2_ligo () : unit result = let main = test_suite "Integration (End to End)" [ test "type alias" type_alias ; test "function" function_ ; + test "procedure" procedure ; test "assign" assign ; test "declaration local" declaration_local ; test "complex function" complex_function ; From 9bb0d3aa9f4167d0aa798ac82a10c137bc69aff7 Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Tue, 24 Sep 2019 16:20:52 -0700 Subject: [PATCH 3/3] Disable tests for procedures and for loops, which are unsupported --- src/contracts/loop.ligo | 4 ++-- src/contracts/procedure.ligo | 11 ++++++++--- src/test/integration_tests.ml | 9 +++++---- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/contracts/loop.ligo b/src/contracts/loop.ligo index 13c47983c..03cc751a7 100644 --- a/src/contracts/loop.ligo +++ b/src/contracts/loop.ligo @@ -16,12 +16,12 @@ function while_sum (var n : nat) : nat is block { } } with r -function for_sum (var n : nat) : nat is block { +(* function for_sum (var n : nat) : nat is block { for i := 1 to 100 begin n := n + 1; end } - with n + with n *) function dummy (const n : nat) : nat is block { while (False) block { skip } diff --git a/src/contracts/procedure.ligo b/src/contracts/procedure.ligo index fe63d191b..a0f6664c6 100644 --- a/src/contracts/procedure.ligo +++ b/src/contracts/procedure.ligo @@ -1,6 +1,11 @@ // Test a trivial PascaLIGO procedure -procedure main (const i : int) : int is +procedure sub (const j: int) is begin - skip - end with i + i := i + 1 + end + +function main (const i: int) : int is + begin + sub(i) + end with i diff --git a/src/test/integration_tests.ml b/src/test/integration_tests.ml index 2382b8719..79b62a0c3 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -16,10 +16,11 @@ let function_ () : unit result = let make_expect = fun n -> n in expect_eq_n_int program "main" make_expect -let procedure () : unit result = +(* Procedures are not supported yet + let procedure () : unit result = let%bind program = type_file "./contracts/procedure.ligo" in - let make_expect = fun n -> n in - expect_eq_n_int program "main" make_expect + let make_expect = fun n -> n + 1 in + expect_eq_n_int program "main" make_expect *) let assign () : unit result = let%bind program = type_file "./contracts/assign.ligo" in @@ -683,7 +684,7 @@ let website2_ligo () : unit result = let main = test_suite "Integration (End to End)" [ test "type alias" type_alias ; test "function" function_ ; - test "procedure" procedure ; + (* test "procedure" procedure ; *) test "assign" assign ; test "declaration local" declaration_local ; test "complex function" complex_function ;