v2 / vlib / v / tests / fns / fn_with_fixed_array_args_test.v
44 lines · 34 sloc · 806 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1struct Test1 {
2mut:
3 value [4]int
4}
5
6fn (mut t Test1) set(new_value [4]int) {
7 t.value = new_value
8}
9
10fn test_fn_with_fixed_array_argument_1() {
11 mut t := Test1{}
12
13 println(t)
14 assert '${t.value}' == '[0, 0, 0, 0]'
15
16 t.set([1, 2, 3, 4]!)
17
18 println(t)
19 assert '${t.value}' == '[1, 2, 3, 4]'
20}
21
22struct Test2 {
23mut:
24 fixed_value [2][4]int
25 dynamic_value [][4]int
26}
27
28fn (mut t Test2) set(index int, new_value [4]int) {
29 t.fixed_value[index] = new_value
30 t.dynamic_value << new_value
31}
32
33fn test_fn_with_fixed_array_argument_2() {
34 mut t := Test2{}
35
36 println(t)
37 assert '${t.fixed_value}' == '[[0, 0, 0, 0], [0, 0, 0, 0]]'
38 assert '${t.dynamic_value}' == '[]'
39
40 t.set(0, [1, 2, 3, 4]!)
41 println(t)
42 assert '${t.fixed_value}' == '[[1, 2, 3, 4], [0, 0, 0, 0]]'
43 assert '${t.dynamic_value}' == '[[1, 2, 3, 4]]'
44}
45