aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/array.zig
diff options
context:
space:
mode:
Diffstat (limited to 'test/behavior/array.zig')
-rw-r--r--test/behavior/array.zig28
1 files changed, 28 insertions, 0 deletions
diff --git a/test/behavior/array.zig b/test/behavior/array.zig
index c59a7e813a..7c2ab29280 100644
--- a/test/behavior/array.zig
+++ b/test/behavior/array.zig
@@ -1,4 +1,5 @@
const std = @import("std");
+const builtin = @import("builtin");
const testing = std.testing;
const mem = std.mem;
const expect = testing.expect;
@@ -76,3 +77,30 @@ test "array len field" {
try expect(ptr.len == 4);
comptime try expect(ptr.len == 4);
}
+
+test "array with sentinels" {
+ const S = struct {
+ fn doTheTest(is_ct: bool) !void {
+ if (is_ct or builtin.zig_is_stage2) {
+ var zero_sized: [0:0xde]u8 = [_:0xde]u8{};
+ // Stage1 test coverage disabled at runtime because of
+ // https://github.com/ziglang/zig/issues/4372
+ try expect(zero_sized[0] == 0xde);
+ var reinterpreted = @ptrCast(*[1]u8, &zero_sized);
+ try expect(reinterpreted[0] == 0xde);
+ }
+ var arr: [3:0x55]u8 = undefined;
+ // Make sure the sentinel pointer is pointing after the last element.
+ if (!is_ct) {
+ const sentinel_ptr = @ptrToInt(&arr[3]);
+ const last_elem_ptr = @ptrToInt(&arr[2]);
+ try expect((sentinel_ptr - last_elem_ptr) == 1);
+ }
+ // Make sure the sentinel is writeable.
+ arr[3] = 0x55;
+ }
+ };
+
+ try S.doTheTest(false);
+ comptime try S.doTheTest(true);
+}