ligo/src/test/contracts/match.ligo

38 lines
743 B
Plaintext
Raw Normal View History

// Test the pattern matching functionality of PascaLIGO
2019-05-12 20:56:22 +00:00
function match_bool (const i : int) : int is
block {
var result : int := 23;
case i = 2 of
True -> result := 42
| False -> result := 0
end
} with result
2019-05-12 20:56:22 +00:00
function match_option (const o : option (int)) : int is
block {
var result : int := 23;
case o of
None -> skip
| Some (s) -> result := s
end
} with result
2019-05-12 20:56:22 +00:00
function match_expr_bool (const i : int) : int is
case i = 2 of
True -> 42
2019-05-12 20:56:22 +00:00
| False -> 0
end
function match_expr_option (const o : option (int)) : int is
2019-05-12 20:56:22 +00:00
case o of
None -> 42
| Some (s) -> s
2019-05-12 20:56:22 +00:00
end
2019-09-21 11:30:41 +02:00
function match_expr_list (const l : list (int)) : int is
2019-09-21 11:30:41 +02:00
case l of
nil -> -1
2019-09-21 11:30:41 +02:00
| hd # tl -> hd
end