v2 / vlib / v / tests / conditions / matches / match_expr_nested_test.v
35 lines · 29 sloc · 434 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1struct Abc {}
2
3type Test = Abc | bool | int
4
5fn test(a Test) Test {
6 return match a {
7 Abc {
8 20
9 }
10 int {
11 match a {
12 1 { true }
13 2 { false }
14 else { -1 }
15 }
16 }
17 bool {
18 1
19 }
20 }
21}
22
23fn test_nested_match_expr() {
24 println(test(1))
25 assert test(1) == Test(true)
26
27 println(test(2))
28 assert test(2) == Test(false)
29
30 println(test(3))
31 assert test(3) == Test(-1)
32
33 println(test(true))
34 assert test(true) == Test(1)
35}
36