v2 / vlib / v / tests / builtin_arrays / fixed_array_2_test.v
52 lines · 43 sloc · 864 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1struct Test {}
2
3fn (t Test) conversion_error(value u16) [4]u8 {
4 return conversion_error(value)
5}
6
7fn arr_opt() ?[2]int {
8 return [1, 2]!
9}
10
11fn conversion_error(value u16) [4]u8 {
12 mut return_value := [4]u8{}
13 for i := 0; i < 4; i++ {
14 return_value[i] = u8(value)
15 }
16 return return_value
17}
18
19fn test_assign() {
20 // -- Block below works fine
21 value := conversion_error(42)
22 println(value)
23}
24
25fn test_assign_method() {
26 value2 := Test{}.conversion_error(42)
27 println(value2)
28}
29
30fn test_ret() {
31 // -- Block above works fine
32 println(conversion_error(42))
33 println(Test{}.conversion_error(42))
34}
35
36fn test_assign_dump() {
37 y := dump(conversion_error(42))
38 dump(y)
39 y2 := dump(Test{}.conversion_error(42))
40 dump(y2)
41}
42
43fn test_assert() {
44 a := [1, 2]!
45 assert dump(a) == [1, 2]!
46}
47
48fn test_call() {
49 conversion_error(42)
50 Test{}.conversion_error(42)
51 dump(arr_opt())
52}
53