Add (commented out) for loop test & working procedure test

Also clean up typo in unsupported for loop error message
This commit is contained in:
John David Pressman 2019-09-24 15:47:04 -07:00
parent a8def8c269
commit ada8a2b703
5 changed files with 46 additions and 4 deletions

View File

@ -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;

View File

@ -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

View File

@ -0,0 +1,6 @@
// Test a trivial PascaLIGO procedure
procedure main (const i : int) : int is
begin
skip
end with i

View File

@ -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)

View File

@ -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 ;