| ... | @@ -1,10 +1,17 @@ | ... | @@ -1,10 +1,17 @@ |
| 1 | const expect = @import("std").testing.expect; | 1 | const expect = @import("std").testing.expect; |
| | 2 | const expectEqualSlices = @import("std").testing.expectEqualSlices; |
| 2 | | 3 | |
| 3 | test "basic slices" { | 4 | test "basic slices" { |
| 4 | var array = [_]i32{ 1, 2, 3, 4 }; | 5 | var array = [_]i32{ 1, 2, 3, 4 }; |
| 5 | var known_at_runtime_zero: usize = 0; | 6 | var known_at_runtime_zero: usize = 0; |
| 6 | _ = &known_at_runtime_zero; | 7 | _ = &known_at_runtime_zero; |
| 7 | const slice = array[known_at_runtime_zero..array.len]; | 8 | const slice = array[known_at_runtime_zero..array.len]; |
| | 9 | |
| | 10 | // alternative initialization using result location |
| | 11 | const alt_slice: []const i32 = &.{ 1, 2, 3, 4 }; |
| | 12 | |
| | 13 | try expectEqualSlices(i32, slice, alt_slice); |
| | 14 | |
| 8 | try expect(@TypeOf(slice) == []i32); | 15 | try expect(@TypeOf(slice) == []i32); |
| 9 | try expect(&slice[0] == &array[0]); | 16 | try expect(&slice[0] == &array[0]); |
| 10 | try expect(slice.len == array.len); | 17 | try expect(slice.len == array.len); |