v2 / vlib / v / tests / options / option_fn_test.v
47 lines · 41 sloc · 791 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1type HandlerFn = fn ()
2
3fn new_static_router(route_not_found_handler ?fn ()) fn () {
4 return route_not_found_handler or {
5 fn () {}
6 }
7}
8
9fn new_static_router2(route_not_found_handler ?HandlerFn) fn () {
10 return route_not_found_handler or {
11 fn () {}
12 }
13}
14
15fn test_option_fn_alias_decl_with_none() {
16 b := new_static_router2(none)
17 $if b is $function {
18 assert true
19 } $else {
20 assert false
21 }
22}
23
24fn test_option_fn_decl_with_none() {
25 a := new_static_router(none)
26 $if a is $function {
27 assert true
28 } $else {
29 assert false
30 }
31}
32
33fn test_option_fn_passing_normal() {
34 anon_1 := fn () {
35 println(1)
36 }
37 c := new_static_router(anon_1)
38 assert c == anon_1
39}
40
41fn test_option_fn_passing_to_alias() {
42 anon_2 := fn () {
43 println(2)
44 }
45 d := new_static_router(anon_2)
46 assert d == anon_2
47}
48