v2 / vlib / v / tests / conditions / matches / match_expr_result_test.v
25 lines · 21 sloc · 392 bytes · 8e35f4d9848f7ad35d857a187dddbfd2eca5e19d
Raw
1fn try(this string) !bool {
2 return true
3}
4
5fn test_case1() {
6 a, b := match true {
7 try('foo')! { 'a', 'b' }
8 try('bar')! { 'c', 'd' }
9 else { 'e', 'f' }
10 }
11
12 assert a == 'a'
13 assert b == 'b'
14}
15
16fn test_case2() {
17 a, b := match true {
18 try('foo')! && try('foo') or { false } { 'a', 'b' }
19 try('bar') or { false } { 'c', 'd' }
20 else { 'e', 'f' }
21 }
22
23 assert a == 'a'
24 assert b == 'b'
25}
26