| 1 | fn fixed() [4]int { |
| 2 | return [1, 2, 3, 4]! |
| 3 | } |
| 4 | |
| 5 | fn fixed_opt() ?[4]int { |
| 6 | return [1, 2, 3, 4]! |
| 7 | } |
| 8 | |
| 9 | fn multi_ret() ([4]int, bool) { |
| 10 | return [1, 2, 3, 4]!, true |
| 11 | } |
| 12 | |
| 13 | fn multi_ret_opt() (?[4]int, bool) { |
| 14 | return [1, 2, 3, 4]!, true |
| 15 | } |
| 16 | |
| 17 | fn multi_ret_opt_none() (?[4]int, bool) { |
| 18 | return none, true |
| 19 | } |
| 20 | |
| 21 | fn test_simple() { |
| 22 | a := fixed() |
| 23 | assert a.len == 4 |
| 24 | } |
| 25 | |
| 26 | fn test_simple_option() { |
| 27 | b := fixed_opt() |
| 28 | assert b?.len == 4 |
| 29 | } |
| 30 | |
| 31 | fn test_mr_fixed() { |
| 32 | w, y := multi_ret() |
| 33 | assert w.len == 4 |
| 34 | assert y == true |
| 35 | } |
| 36 | |
| 37 | fn test_mr_fixed_opt() { |
| 38 | w1, y1 := multi_ret_opt() |
| 39 | assert w1?.len == 4 |
| 40 | assert y1 == true |
| 41 | } |
| 42 | |
| 43 | fn test_mr_fixed_opt_none() { |
| 44 | w2, y2 := multi_ret_opt_none() |
| 45 | assert w2 == none |
| 46 | assert y2 == true |
| 47 | } |
| 48 | |
| 49 | fn four(a [4]int) [4]int { |
| 50 | assert a.len == 4 |
| 51 | return a |
| 52 | } |
| 53 | |
| 54 | fn test_passing_arg() { |
| 55 | a := [1, 2, 3, 4]! |
| 56 | b := four(a) |
| 57 | assert b.len == 4 |
| 58 | c := four(b) |
| 59 | assert c.len == 4 |
| 60 | } |
| 61 | |
| 62 | fn test_passing_opt_arg() { |
| 63 | a := fixed_opt() |
| 64 | four(a?) |
| 65 | } |
| 66 | |
| 67 | fn test_assign() { |
| 68 | mut a := [1, 2, 3, 4]! |
| 69 | a = four(a) |
| 70 | assert a.len == 4 |
| 71 | a = fixed_opt()? |
| 72 | assert a.len == 4 |
| 73 | b := a |
| 74 | assert b.len == 4 |
| 75 | } |
| 76 | |
| 77 | fn gn_fixed[T](a [4]T) [4]T { |
| 78 | return a |
| 79 | } |
| 80 | |
| 81 | fn test_generic() { |
| 82 | b := [1, 2, 3, 4]! |
| 83 | a := gn_fixed(b) |
| 84 | c := gn_fixed(a) |
| 85 | } |
| 86 | |
| 87 | fn test_inline() { |
| 88 | mut a := [1, 2, 3, 4]! |
| 89 | assert four(a)[1] == 2 |
| 90 | } |
| 91 | |
| 92 | fn f() [4]int { |
| 93 | return [1, 2, 3, 4]! |
| 94 | } |
| 95 | |
| 96 | fn test_simple_ret() { |
| 97 | zzz := f() |
| 98 | dump(zzz) |
| 99 | dump(zzz[0]) |
| 100 | } |
| 101 | |
| 102 | fn g(a [4]int) { |
| 103 | } |
| 104 | |
| 105 | fn test_arg_fixed() { |
| 106 | zzz := f() |
| 107 | g(zzz) |
| 108 | g(f()) |
| 109 | } |
| 110 | |
| 111 | fn test_dump_ret() { |
| 112 | zzz := f() |
| 113 | a := dump(zzz) |
| 114 | b := dump(zzz[0]) |
| 115 | } |
| 116 | |