aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/array.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-12-27 22:04:21 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-12-27 22:06:23 -0700
commit85d4c8620f602726b159efe1fe2ea0e07e3c5b59 (patch)
tree73399f38f3a9782a9ecf067eec3cc612d79a4591 /test/behavior/array.zig
parent042b770d6272391a9c25f3444991b439ae07a1b5 (diff)
downloadzig-85d4c8620f602726b159efe1fe2ea0e07e3c5b59.tar.gz
zig-85d4c8620f602726b159efe1fe2ea0e07e3c5b59.zip
Sema: implement array coercion
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();
+}