blob: bef34a404aa2e503ec8a8ce007a3fa3619b68887 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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'
}
|