Add list match test to CameLIGO

This commit is contained in:
John David Pressman 2019-10-28 21:38:29 -07:00
parent 8cfa583d55
commit f62481fb0a
2 changed files with 37 additions and 5 deletions

View File

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

View File

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