From c004fd24cdb6907c03a0e5ec5a13059ea5575f64 Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Mon, 28 Oct 2019 22:01:31 -0700 Subject: [PATCH] Add option and boolean match tests to CameLIGO --- src/test/contracts/match.mligo | 25 +++++++++---------------- src/test/integration_tests.ml | 12 ++++++++++++ 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/test/contracts/match.mligo b/src/test/contracts/match.mligo index bfe334546..394925538 100644 --- a/src/test/contracts/match.mligo +++ b/src/test/contracts/match.mligo @@ -12,24 +12,17 @@ let%entry main (p : param) storage = | Sub n -> 0-n) in (([] : operation list), storage) +let match_bool (b: bool) : int = + match b with + true -> 10 + | false -> 0 + 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) - -*) +let match_option (i : int option) : int = + match i with + Some n -> n + | None -> 0 diff --git a/src/test/integration_tests.ml b/src/test/integration_tests.ml index b03b9a51e..384f726f0 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -870,6 +870,14 @@ let match_variant () : unit result = 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_bool true in + let expected = e_int 10 in + expect_eq program "match_bool" input expected in + let%bind () = + let input = e_bool false in + let expected = e_int 0 in + expect_eq program "match_bool" input expected in let%bind () = let input = e_list [e_int 3] in let expected = e_int 3 in @@ -878,6 +886,10 @@ let match_variant () : unit result = let input = e_typed_list [] t_int in let expected = e_int 10 in expect_eq program "match_list" input expected in + let%bind () = + let make_input n = e_some (e_int n) in + let make_expected n = e_int n in + expect_eq_n program "match_option" make_input make_expected in ok () let match_matej () : unit result =