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.zig50
1 files changed, 50 insertions, 0 deletions
diff --git a/test/behavior/array.zig b/test/behavior/array.zig
index 3ff339b140..c9c376be87 100644
--- a/test/behavior/array.zig
+++ b/test/behavior/array.zig
@@ -164,3 +164,53 @@ test "read/write through global variable array of struct fields initialized via
};
try S.doTheTest();
}
+
+test "single-item pointer to array indexing and slicing" {
+ try testSingleItemPtrArrayIndexSlice();
+ comptime try testSingleItemPtrArrayIndexSlice();
+}
+
+fn testSingleItemPtrArrayIndexSlice() !void {
+ {
+ var array: [4]u8 = "aaaa".*;
+ doSomeMangling(&array);
+ try expect(mem.eql(u8, "azya", &array));
+ }
+ {
+ var array = "aaaa".*;
+ doSomeMangling(&array);
+ try expect(mem.eql(u8, "azya", &array));
+ }
+}
+
+fn doSomeMangling(array: *[4]u8) void {
+ array[1] = 'z';
+ array[2..3][0] = 'y';
+}
+
+test "implicit cast zero sized array ptr to slice" {
+ {
+ var b = "".*;
+ const c: []const u8 = &b;
+ try expect(c.len == 0);
+ }
+ {
+ var b: [0]u8 = "".*;
+ const c: []const u8 = &b;
+ try expect(c.len == 0);
+ }
+}
+
+test "anonymous list literal syntax" {
+ const S = struct {
+ fn doTheTest() !void {
+ var array: [4]u8 = .{ 1, 2, 3, 4 };
+ try expect(array[0] == 1);
+ try expect(array[1] == 2);
+ try expect(array[2] == 3);
+ try expect(array[3] == 4);
+ }
+ };
+ try S.doTheTest();
+ comptime try S.doTheTest();
+}