diff options
Diffstat (limited to 'v_windows/v/old/vlib/v/tests/fn_index_direct_call_test.v')
-rw-r--r-- | v_windows/v/old/vlib/v/tests/fn_index_direct_call_test.v | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/v_windows/v/old/vlib/v/tests/fn_index_direct_call_test.v b/v_windows/v/old/vlib/v/tests/fn_index_direct_call_test.v new file mode 100644 index 0000000..bef34a4 --- /dev/null +++ b/v_windows/v/old/vlib/v/tests/fn_index_direct_call_test.v @@ -0,0 +1,33 @@ +struct Placeholder { + name string +} + +struct FnStruct { +mut: + array_of_fn []fn (int, &Placeholder, string) bool +} + +fn test_fn_array_direct_call() { + mut fs := FnStruct{} + fs.array_of_fn << fn (x int, y &Placeholder, z string) bool { + return false + } + + println(fs.array_of_fn[0](1, &Placeholder{ name: 'Bob' }, 'Builder')) + assert fs.array_of_fn[0](1, &Placeholder{ name: 'Bob' }, 'Builder') == false +} + +fn test_fn_map_direct_call() { + a := map{ + 'aaa': fn () string { + return 'aaa' + } + 'bbb': fn () string { + return 'bbb' + } + } + println(a['aaa']()) + println(a['bbb']()) + assert a['aaa']() == 'aaa' + assert a['bbb']() == 'bbb' +} |