mirror of
https://github.com/ziglang/zig.git
synced 2026-02-14 13:30:45 +00:00
Merge pull request #14091 from ziglang/stage1-test-coverage
add more behavior test coverage
This commit is contained in:
commit
3f1cfcbea8
@ -61,6 +61,7 @@ test "array concat with undefined" {
|
||||
}
|
||||
|
||||
test "array concat with tuple" {
|
||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
|
||||
|
||||
|
||||
@ -14,6 +14,7 @@ const Entry = packed struct {
|
||||
test {
|
||||
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
||||
|
||||
const frame = Frame{ .num = 0x7FDE };
|
||||
var entry = Entry{ .other = 0, .frame = .{ .num = 0xFFFFF } };
|
||||
|
||||
@ -889,3 +889,16 @@ test "field access of anyerror results in smaller error set" {
|
||||
try expect(@TypeOf(E2.A) == E2);
|
||||
try expect(@TypeOf(@field(anyerror, "NotFound")) == error{NotFound});
|
||||
}
|
||||
|
||||
test "optional error union return type" {
|
||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
||||
|
||||
const S = struct {
|
||||
fn foo() ?anyerror!u32 {
|
||||
var x: u32 = 1234;
|
||||
return @as(anyerror!u32, x);
|
||||
}
|
||||
};
|
||||
try expect(1234 == try S.foo().?);
|
||||
}
|
||||
|
||||
@ -457,3 +457,30 @@ test "method call with optional and error union first param" {
|
||||
try s.opt();
|
||||
try s.errUnion();
|
||||
}
|
||||
|
||||
test "using @ptrCast on function pointers" {
|
||||
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
||||
|
||||
const S = struct {
|
||||
const A = struct { data: [4]u8 };
|
||||
|
||||
fn at(arr: *const A, index: usize) *const u8 {
|
||||
return &arr.data[index];
|
||||
}
|
||||
|
||||
fn run() !void {
|
||||
const a = A{ .data = "abcd".* };
|
||||
const casted_fn = @ptrCast(*const fn (*const anyopaque, usize) *const u8, &at);
|
||||
const casted_impl = @ptrCast(*const anyopaque, &a);
|
||||
const ptr = casted_fn(casted_impl, 2);
|
||||
try expect(ptr.* == 'c');
|
||||
}
|
||||
};
|
||||
|
||||
try S.run();
|
||||
// https://github.com/ziglang/zig/issues/2626
|
||||
// try comptime S.run();
|
||||
}
|
||||
|
||||
@ -257,3 +257,16 @@ test "@ptrCast slice to slice" {
|
||||
try expect(buf[1] == 42);
|
||||
try expect(alias.len == 4);
|
||||
}
|
||||
|
||||
test "comptime @ptrCast a subset of an array, then write through it" {
|
||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
||||
|
||||
comptime {
|
||||
var buff: [16]u8 align(4) = undefined;
|
||||
const len_bytes = @ptrCast(*u32, &buff);
|
||||
len_bytes.* = 16;
|
||||
std.mem.copy(u8, buff[4..], "abcdef");
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user