v2 / vlib / v / tests / fns / anon_fn_option_test.v
26 lines · 25 sloc · 301 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1struct Foo {
2 bar ?fn ()
3}
4
5fn test_main() {
6 foo1 := Foo{
7 bar: || println('foo1')
8 }
9 foo2 := Foo{
10 bar: fn () {
11 println('foo2')
12 }
13 }
14 if bar_fn := foo1.bar {
15 bar_fn()
16 assert true
17 } else {
18 assert false
19 }
20 if bar_fn := foo2.bar {
21 bar_fn()
22 assert true
23 } else {
24 assert false
25 }
26}
27