2019-02-09 07:18:47 +08:00
|
|
|
const expect = @import("std").testing.expect;
|
2022-02-22 21:15:09 +08:00
|
|
|
const builtin = @import("builtin");
|
2017-02-08 06:19:51 +08:00
|
|
|
|
2018-11-13 21:08:37 +08:00
|
|
|
const Foo = struct {
|
2017-02-08 06:19:51 +08:00
|
|
|
a: void,
|
|
|
|
b: i32,
|
|
|
|
c: void,
|
|
|
|
};
|
|
|
|
|
2017-05-24 09:38:31 +08:00
|
|
|
test "compare void with void compile time known" {
|
2017-02-08 06:19:51 +08:00
|
|
|
comptime {
|
2018-11-13 21:08:37 +08:00
|
|
|
const foo = Foo{
|
2017-02-08 06:19:51 +08:00
|
|
|
.a = {},
|
|
|
|
.b = 1,
|
|
|
|
.c = {},
|
|
|
|
};
|
2021-05-05 02:23:22 +08:00
|
|
|
try expect(foo.a == {});
|
2017-02-08 06:19:51 +08:00
|
|
|
}
|
|
|
|
}
|
2018-07-07 05:27:44 +08:00
|
|
|
|
|
|
|
test "iterate over a void slice" {
|
2022-10-11 21:39:47 +08:00
|
|
|
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
2022-02-22 21:15:09 +08:00
|
|
|
|
2018-07-07 05:27:44 +08:00
|
|
|
var j: usize = 0;
|
|
|
|
for (times(10)) |_, i| {
|
2021-05-05 02:23:22 +08:00
|
|
|
try expect(i == j);
|
2018-07-07 05:27:44 +08:00
|
|
|
j += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn times(n: usize) []const void {
|
2019-11-07 12:25:57 +08:00
|
|
|
return @as([*]void, undefined)[0..n];
|
2018-07-07 05:27:44 +08:00
|
|
|
}
|
2019-01-30 10:47:26 +08:00
|
|
|
|
|
|
|
test "void optional" {
|
2022-02-22 21:15:09 +08:00
|
|
|
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
|
|
|
|
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
|
|
|
|
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
|
2022-10-11 21:39:47 +08:00
|
|
|
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
2022-02-22 21:15:09 +08:00
|
|
|
|
2019-01-30 10:47:26 +08:00
|
|
|
var x: ?void = {};
|
2021-05-05 02:23:22 +08:00
|
|
|
try expect(x != null);
|
2019-01-30 10:47:26 +08:00
|
|
|
}
|
2019-08-20 03:58:31 +08:00
|
|
|
|
|
|
|
test "void array as a local variable initializer" {
|
|
|
|
var x = [_]void{{}} ** 1004;
|
2021-06-10 09:35:42 +08:00
|
|
|
_ = x[0];
|
2019-08-20 03:58:31 +08:00
|
|
|
}
|
2022-08-26 03:17:20 +08:00
|
|
|
|
|
|
|
const void_constant = {};
|
|
|
|
test "reference to void constants" {
|
|
|
|
var a = void_constant;
|
|
|
|
_ = a;
|
|
|
|
}
|