v2 / vlib / v / tests / options / option_var_2_test.v
26 lines · 22 sloc · 350 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1struct Foo {
2 name ?string
3}
4
5fn test_option_var() {
6 foo := Foo{}
7 other := foo.name
8
9 println(typeof(other).name)
10 if name := other {
11 println('with name: ${name}')
12 assert false
13 } else {
14 println('without name')
15 assert true
16 }
17
18 mut counter := 0
19 val := other or {
20 counter++
21 'default'
22 }
23
24 assert val == 'default'
25 assert counter == 1
26}
27