| author | |
| committer | |
| log | cb77bd672c3b398e3c5f6be80af03243bf8638e3 |
| tree | 3941236c60db642437683f492badae8209790ed0 |
| parent | f71f27bcb0ceb851a7c95f3970d644623b8d67ba |
2 files changed, 14 insertions(+), 0 deletions(-)
doc/langref/test_arrays.zig+7| ... | ... | @@ -5,6 +5,13 @@ const mem = @import("std").mem; |
| 5 | 5 | // array literal |
| 6 | 6 | const message = [_]u8{ 'h', 'e', 'l', 'l', 'o' }; |
| 7 | 7 | |
| 8 | // alternative initialization using result location | |
| 9 | const alt_message: [5]u8 = .{ 'h', 'e', 'l', 'l', 'o' }; | |
| 10 | ||
| 11 | comptime { | |
| 12 | assert(mem.eql(u8, &message, &alt_message)); | |
| 13 | } | |
| 14 | ||
| 8 | 15 | // get the size of an array |
| 9 | 16 | comptime { |
| 10 | 17 | assert(message.len == 5); |
doc/langref/test_basic_slices.zig+7| ... | ... | @@ -1,10 +1,17 @@ |
| 1 | 1 | const expect = @import("std").testing.expect; |
| 2 | const expectEqualSlices = @import("std").testing.expectEqualSlices; | |
| 2 | 3 | |
| 3 | 4 | test "basic slices" { |
| 4 | 5 | var array = [_]i32{ 1, 2, 3, 4 }; |
| 5 | 6 | var known_at_runtime_zero: usize = 0; |
| 6 | 7 | _ = &known_at_runtime_zero; |
| 7 | 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 | 15 | try expect(@TypeOf(slice) == []i32); |
| 9 | 16 | try expect(&slice[0] == &array[0]); |
| 10 | 17 | try expect(slice.len == array.len); |