| 1 | struct Test1 { |
| 2 | mut: |
| 3 | value [4]int |
| 4 | } |
| 5 | |
| 6 | fn (mut t Test1) set(new_value [4]int) { |
| 7 | t.value = new_value |
| 8 | } |
| 9 | |
| 10 | fn 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 | |
| 22 | struct Test2 { |
| 23 | mut: |
| 24 | fixed_value [2][4]int |
| 25 | dynamic_value [][4]int |
| 26 | } |
| 27 | |
| 28 | fn (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 | |
| 33 | fn 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 | |