| 1 | const expect = @import("std").testing.expect; |
| 2 | const builtin = @import("builtin"); |
| 3 | |
| 4 | const Foo = struct { |
| 5 | a: void, |
| 6 | b: i32, |
| 7 | c: void, |
| 8 | }; |
| 9 | |
| 10 | test "compare void with void compile time known" { |
| 11 | comptime { |
| 12 | const foo = Foo{ |
| 13 | .a = {}, |
| 14 | .b = 1, |
| 15 | .c = {}, |
| 16 | }; |
| 17 | try expect(foo.a == {}); |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | test "iterate over a void slice" { |
| 22 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 23 | if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest; |
| 24 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; |
| 25 | |
| 26 | var j: usize = 0; |
| 27 | for (times(10), 0..) |_, i| { |
| 28 | try expect(i == j); |
| 29 | j += 1; |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | fn times(n: usize) []const void { |
| 34 | return @as([*]void, undefined)[0..n]; |
| 35 | } |
| 36 | |
| 37 | test "void optional" { |
| 38 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; |
| 39 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 40 | |
| 41 | var x: ?void = {}; |
| 42 | _ = &x; |
| 43 | try expect(x != null); |
| 44 | } |
| 45 | |
| 46 | test "void array as a local variable initializer" { |
| 47 | var x: [1004]void = @splat({}); |
| 48 | _ = &x[0]; |
| 49 | _ = x[0]; |
| 50 | } |
| 51 | |
| 52 | const void_constant = {}; |
| 53 | test "reference to void constants" { |
| 54 | var a = void_constant; |
| 55 | _ = &a; |
| 56 | } |