v2 / vlib / v / tests / options / var_option_comptime_test.v
25 lines · 23 sloc · 308 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1struct Test {
2 a ?string
3}
4
5fn foo(a ?string) ? {
6 println(a?)
7 if a == none {
8 assert false
9 }
10}
11
12fn test_main() {
13 v := Test{}
14 $for f in Test.fields {
15 mut t := v.$(f.name)
16 assert t == none
17 z := t or { '' }
18 assert z == ''
19 foo(t)
20 t = 'foo'
21 assert t != none
22 foo(t)
23 assert t? == 'foo'
24 }
25}
26