v2 / vlib / v / tests / options / option_match_expr_test.v
32 lines · 26 sloc · 463 bytes · 8e35f4d9848f7ad35d857a187dddbfd2eca5e19d
Raw
1pub struct ParamPrecos {
2pub:
3 code string @[required]
4 table_ref ?i64
5}
6
7fn test_none() {
8 pp := ParamPrecos{
9 code: 'V'
10 }
11
12 tx_ref := match pp.table_ref {
13 none { 'num: none' }
14 else { 'num: ${pp.table_ref?}' }
15 }
16
17 assert tx_ref == 'num: none'
18}
19
20fn test_not_none() {
21 pp := ParamPrecos{
22 code: 'V'
23 table_ref: 123
24 }
25
26 tx_ref := match pp.table_ref {
27 none { 'num: none' }
28 else { 'num: ${pp.table_ref?}' }
29 }
30
31 assert tx_ref == 'num: 123'
32}
33