v2 / vlib / v / tests / options / option_fn_var_test.v
27 lines · 22 sloc · 414 bytes · 4f39bac1fd4afeb3df84ecaee0f2acb10858d224
Raw
1module main
2
3type DataFn = fn (name string) string
4
5fn which_lang(name string) string {
6 return name
7}
8
9fn find_func(name string) ?DataFn {
10 return match name {
11 'vlang' { which_lang }
12 else { none }
13 }
14}
15
16fn test_main() {
17 req := find_func('vlang')?
18 fun := req('options')
19 println(fun)
20 assert fun == 'options'
21}
22
23fn test_ifguard() {
24 if req2 := find_func('vlang') {
25 assert req2('options') == 'options'
26 }
27}
28