v2 / vlib / v / tests / generics / generic_fn_infer_map_test.v
36 lines · 30 sloc · 494 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1fn print_map[K, V](x map[K]V) string {
2 println(x)
3 return '${x}'
4}
5
6fn test_generics_infer_map_type() {
7 m1 := {
8 'one': 1
9 }
10 assert print_map(m1) == "{'one': 1}"
11
12 m2 := {
13 'one': 1.1
14 }
15 assert print_map(m2) == "{'one': 1.1}"
16
17 m3 := {
18 'one': 'a'
19 }
20 assert print_map(m3) == "{'one': 'a'}"
21
22 m4 := {
23 1: 'one'
24 }
25 assert print_map(m4) == "{1: 'one'}"
26
27 m5 := {
28 1.1: 'one'
29 }
30 assert print_map(m5) == "{1.1: 'one'}"
31
32 m6 := {
33 'a': 'one'
34 }
35 assert print_map(m6) == "{'a': 'one'}"
36}
37