Skip to content

Commit 3bfae2a

Browse files
authored
Merge pull request #13997 from ziglang/stage1-test-coverage
add behavior test coverage
2 parents d1f61f2 + 6018a3a commit 3bfae2a

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

test/behavior/error.zig

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,27 @@ test "inferred empty error set comptime catch" {
287287
S.foo() catch @compileError("fail");
288288
}
289289

290+
test "error inference with an empty set" {
291+
const S = struct {
292+
const Struct = struct {
293+
pub fn func() (error{})!usize {
294+
return 0;
295+
}
296+
};
297+
298+
fn AnotherStruct(comptime SubStruct: type) type {
299+
return struct {
300+
fn anotherFunc() !void {
301+
try expect(0 == (try SubStruct.func()));
302+
}
303+
};
304+
}
305+
};
306+
307+
const GeneratedStruct = S.AnotherStruct(S.Struct);
308+
try GeneratedStruct.anotherFunc();
309+
}
310+
290311
test "error union peer type resolution" {
291312
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
292313
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO

test/behavior/ptrcast.zig

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,37 @@ test "comptime ptrcast keeps larger alignment" {
203203
}
204204
}
205205

206+
test "ptrcast of const integer has the correct object size" {
207+
const is_value = ~@intCast(isize, std.math.minInt(isize));
208+
const is_bytes = @ptrCast([*]const u8, &is_value)[0..@sizeOf(isize)];
209+
if (@sizeOf(isize) == 8) {
210+
switch (native_endian) {
211+
.Little => {
212+
try expect(is_bytes[0] == 0xff);
213+
try expect(is_bytes[1] == 0xff);
214+
try expect(is_bytes[2] == 0xff);
215+
try expect(is_bytes[3] == 0xff);
216+
217+
try expect(is_bytes[4] == 0xff);
218+
try expect(is_bytes[5] == 0xff);
219+
try expect(is_bytes[6] == 0xff);
220+
try expect(is_bytes[7] == 0x7f);
221+
},
222+
.Big => {
223+
try expect(is_bytes[0] == 0x7f);
224+
try expect(is_bytes[1] == 0xff);
225+
try expect(is_bytes[2] == 0xff);
226+
try expect(is_bytes[3] == 0xff);
227+
228+
try expect(is_bytes[4] == 0xff);
229+
try expect(is_bytes[5] == 0xff);
230+
try expect(is_bytes[6] == 0xff);
231+
try expect(is_bytes[7] == 0xff);
232+
},
233+
}
234+
}
235+
}
236+
206237
test "implicit optional pointer to optional anyopaque pointer" {
207238
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
208239
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO

0 commit comments

Comments
 (0)