Add option and boolean match tests to CameLIGO
This commit is contained in:
parent
f62481fb0a
commit
c004fd24cd
@ -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
|
||||
|
@ -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 =
|
||||
|
Loading…
Reference in New Issue
Block a user