Add option and boolean match tests to CameLIGO

This commit is contained in:
John David Pressman 2019-10-28 22:01:31 -07:00
parent f62481fb0a
commit c004fd24cd
2 changed files with 21 additions and 16 deletions

View File

@ -12,24 +12,17 @@ let%entry main (p : param) storage =
| Sub n -> 0-n) | Sub n -> 0-n)
in (([] : operation list), storage) in (([] : operation list), storage)
let match_bool (b: bool) : int =
match b with
true -> 10
| false -> 0
let match_list (l: int list) : int = let match_list (l: int list) : int =
match l with match l with
hd :: tl -> hd hd :: tl -> hd
| [] -> 10 | [] -> 10
(* TODO: Add support for matching options let match_option (i : int option) : int =
match i with
type option_param = Some n -> n
Add of int option | None -> 0
| 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)
*)

View File

@ -870,6 +870,14 @@ let match_variant () : unit result =
let make_expected n = let make_expected n =
e_pair (e_typed_list [] t_operation) (e_int (3-n)) e_pair (e_typed_list [] t_operation) (e_int (3-n))
in expect_eq_n program "main" make_input make_expected in 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%bind () =
let input = e_list [e_int 3] in let input = e_list [e_int 3] in
let expected = 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 input = e_typed_list [] t_int in
let expected = e_int 10 in let expected = e_int 10 in
expect_eq program "match_list" input expected 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 () ok ()
let match_matej () : unit result = let match_matej () : unit result =