v2 / vlib / v / tests / options / option_fn_voidptr_test.v
23 lines · 20 sloc · 353 bytes · d5e50c2f20c29f532e119d642e9a6f48e8decdfc
Raw
1struct Foo {
2mut:
3 func ?fn (voidptr) ?bool = unsafe { nil }
4}
5
6fn callback(foo &Foo) ?bool {
7 return foo.func? == callback
8}
9
10fn test_main() {
11 t := Foo{
12 func: callback
13 }
14 assert t.func? == callback
15 call_fn := t.func?
16 assert call_fn(&t)?
17
18 mut a := Foo{}
19 a.func = callback
20 assert a.func? == callback
21 call_fn2 := a.func?
22 assert call_fn2(&a)?
23}
24