v2 / vlib / v / tests / generics / generics_with_empty_array_arg_test.v
29 lines · 23 sloc · 587 bytes · 1a9dab29c6929b07afb4f02ac2029392cd25f84c
Raw
1fn count_str(array []string) int {
2 return array.len
3}
4
5fn count_int(array []int) int {
6 return array.len
7}
8
9fn count[T](array []T) int {
10 return array.len
11}
12
13fn test_generics_with_empty_array_arg() {
14 assert count_str(['one', 'two']) == 2
15 assert count_str([]string{}) == 0
16 assert count_str([]) == 0
17
18 assert count_int([1, 2]) == 2
19 assert count_int([]int{}) == 0
20 assert count_int([]) == 0
21
22 assert count[f64]([1.0, 2.0]) == 2
23 assert count[f64]([]f64{}) == 0
24 assert count[f64]([]) == 0
25
26 assert count[int]([1, 2]) == 2
27 assert count[int]([]int{}) == 0
28 assert count[int]([]) == 0
29}
30