Skip to content

add behavior test coverage #13997

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions test/behavior/error.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions test/behavior/ptrcast.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down