From f62481fb0a1c86dd47c475f6467272f961f77ade Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Mon, 28 Oct 2019 21:38:29 -0700 Subject: [PATCH] Add list match test to CameLIGO --- src/test/contracts/match.mligo | 22 ++++++++++++++++++++++ src/test/integration_tests.ml | 20 +++++++++++++++----- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/test/contracts/match.mligo b/src/test/contracts/match.mligo index 1665e9f27..bfe334546 100644 --- a/src/test/contracts/match.mligo +++ b/src/test/contracts/match.mligo @@ -11,3 +11,25 @@ let%entry main (p : param) storage = Add n -> n | Sub n -> 0-n) in (([] : operation list), storage) + +let match_list (l: int list) : int = + match l with + hd :: tl -> hd + | [] -> 10 + +(* TODO: Add support for matching options + +type option_param = + Add of int option +| Sub of int option + +let match_option (p : option_param) storage = + let storage = + storage + + (match p with + Some (Add n) -> n + | Some (Sub n) -> 0 - n + | None -> 0) + in (([] : operation list) , storage) + +*) diff --git a/src/test/integration_tests.ml b/src/test/integration_tests.ml index 509b1f0d6..b03b9a51e 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -864,11 +864,21 @@ let let_in_mligo () : unit result = let match_variant () : unit result = let%bind program = mtype_file "./contracts/match.mligo" in - let make_input n = - e_pair (e_constructor "Sub" (e_int n)) (e_int 3) in - let make_expected n = - e_pair (e_typed_list [] t_operation) (e_int (3-n)) - in expect_eq_n program "main" make_input make_expected + let%bind () = + let make_input n = + e_pair (e_constructor "Sub" (e_int n)) (e_int 3) in + let make_expected n = + e_pair (e_typed_list [] t_operation) (e_int (3-n)) + in expect_eq_n program "main" make_input make_expected in + let%bind () = + let input = e_list [e_int 3] in + let expected = e_int 3 in + expect_eq program "match_list" input expected in + let%bind () = + let input = e_typed_list [] t_int in + let expected = e_int 10 in + expect_eq program "match_list" input expected in + ok () let match_matej () : unit result = let%bind program = mtype_file "./contracts/match_bis.mligo" in