v2 / vlib / v / tests / options / option_unwrap_ifexpr_test.v
28 lines · 26 sloc · 415 bytes · 45fd7ebcde30b5047d115b93136b301ed7546efa
Raw
1type TestSmart = ?string | int
2
3fn test_simple_case() {
4 o := ?string('abc')
5 dump(o)
6 a := if o == none {
7 'none'
8 } else {
9 '${o} exists'
10 }
11 dump(a)
12 assert a == 'abc exists'
13}
14
15fn test_comptime_smartcast() {
16 t := TestSmart(?string('foobar'))
17 $for v in TestSmart.variants {
18 if t is v {
19 $if t is ?string {
20 if t == none {
21 panic('error')
22 } else {
23 assert t == 'foobar'
24 }
25 }
26 }
27 }
28}
29