aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-12-19 01:11:35 -0500
committerGitHub <noreply@github.com>2022-12-19 01:11:35 -0500
commit3bfae2a0d9503dbd832774c3b39a74dbd55e8b6e (patch)
tree241f91342fc5c646939ee7ed9d8446c4b6a14433 /test
parentd1f61f2d6801240c593bcf5a3219020ecae0e736 (diff)
parent6018a3ad397ad2104762b1c548866c2c2df2ac77 (diff)
downloadzig-3bfae2a0d9503dbd832774c3b39a74dbd55e8b6e.tar.gz
zig-3bfae2a0d9503dbd832774c3b39a74dbd55e8b6e.zip
Merge pull request #13997 from ziglang/stage1-test-coverage
add behavior test coverage
Diffstat (limited to 'test')
-rw-r--r--test/behavior/error.zig21
-rw-r--r--test/behavior/ptrcast.zig31
2 files changed, 52 insertions, 0 deletions
diff --git a/test/behavior/error.zig b/test/behavior/error.zig
index ae1445dd9e..f5bf6493d8 100644
--- a/test/behavior/error.zig
+++ b/test/behavior/error.zig
@@ -287,6 +287,27 @@ test "inferred empty error set comptime catch" {
S.foo() catch @compileError("fail");
}
+test "error inference with an empty set" {
+ const S = struct {
+ const Struct = struct {
+ pub fn func() (error{})!usize {
+ return 0;
+ }
+ };
+
+ fn AnotherStruct(comptime SubStruct: type) type {
+ return struct {
+ fn anotherFunc() !void {
+ try expect(0 == (try SubStruct.func()));
+ }
+ };
+ }
+ };
+
+ const GeneratedStruct = S.AnotherStruct(S.Struct);
+ try GeneratedStruct.anotherFunc();
+}
+
test "error union peer type resolution" {
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
diff --git a/test/behavior/ptrcast.zig b/test/behavior/ptrcast.zig
index 982a0b862f..f25161ece8 100644
--- a/test/behavior/ptrcast.zig
+++ b/test/behavior/ptrcast.zig
@@ -203,6 +203,37 @@ test "comptime ptrcast keeps larger alignment" {
}
}
+test "ptrcast of const integer has the correct object size" {
+ const is_value = ~@intCast(isize, std.math.minInt(isize));
+ const is_bytes = @ptrCast([*]const u8, &is_value)[0..@sizeOf(isize)];
+ if (@sizeOf(isize) == 8) {
+ switch (native_endian) {
+ .Little => {
+ try expect(is_bytes[0] == 0xff);
+ try expect(is_bytes[1] == 0xff);
+ try expect(is_bytes[2] == 0xff);
+ try expect(is_bytes[3] == 0xff);
+
+ try expect(is_bytes[4] == 0xff);
+ try expect(is_bytes[5] == 0xff);
+ try expect(is_bytes[6] == 0xff);
+ try expect(is_bytes[7] == 0x7f);
+ },
+ .Big => {
+ try expect(is_bytes[0] == 0x7f);
+ try expect(is_bytes[1] == 0xff);
+ try expect(is_bytes[2] == 0xff);
+ try expect(is_bytes[3] == 0xff);
+
+ try expect(is_bytes[4] == 0xff);
+ try expect(is_bytes[5] == 0xff);
+ try expect(is_bytes[6] == 0xff);
+ try expect(is_bytes[7] == 0xff);
+ },
+ }
+ }
+}
+
test "implicit optional pointer to optional anyopaque pointer" {
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO