Add list match test to CameLIGO
This commit is contained in:
parent
8cfa583d55
commit
f62481fb0a
@ -11,3 +11,25 @@ let%entry main (p : param) storage =
|
|||||||
Add n -> n
|
Add n -> n
|
||||||
| Sub n -> 0-n)
|
| Sub n -> 0-n)
|
||||||
in (([] : operation list), storage)
|
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)
|
||||||
|
|
||||||
|
*)
|
||||||
|
@ -864,11 +864,21 @@ let let_in_mligo () : unit result =
|
|||||||
|
|
||||||
let match_variant () : unit result =
|
let match_variant () : unit result =
|
||||||
let%bind program = mtype_file "./contracts/match.mligo" in
|
let%bind program = mtype_file "./contracts/match.mligo" in
|
||||||
|
let%bind () =
|
||||||
let make_input n =
|
let make_input n =
|
||||||
e_pair (e_constructor "Sub" (e_int n)) (e_int 3) in
|
e_pair (e_constructor "Sub" (e_int n)) (e_int 3) in
|
||||||
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 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 match_matej () : unit result =
|
||||||
let%bind program = mtype_file "./contracts/match_bis.mligo" in
|
let%bind program = mtype_file "./contracts/match_bis.mligo" in
|
||||||
|
Loading…
Reference in New Issue
Block a user