mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 14:23:09 +00:00
categorize behavior/bugs/<issueno>.zig tests
This commit is contained in:
parent
282ff8d3bd
commit
804cee3b93
@ -12,136 +12,6 @@ test {
|
|||||||
_ = @import("behavior/bitcast.zig");
|
_ = @import("behavior/bitcast.zig");
|
||||||
_ = @import("behavior/bitreverse.zig");
|
_ = @import("behavior/bitreverse.zig");
|
||||||
_ = @import("behavior/bool.zig");
|
_ = @import("behavior/bool.zig");
|
||||||
// Ideally, all tests would be categorized and independent from GitHub, but
|
|
||||||
// if that's too much trouble, having test coverage this way is better than nothing.
|
|
||||||
_ = @import("behavior/bugs/394.zig");
|
|
||||||
_ = @import("behavior/bugs/421.zig");
|
|
||||||
_ = @import("behavior/bugs/529.zig");
|
|
||||||
_ = @import("behavior/bugs/624.zig");
|
|
||||||
_ = @import("behavior/bugs/655.zig");
|
|
||||||
_ = @import("behavior/bugs/656.zig");
|
|
||||||
_ = @import("behavior/bugs/679.zig");
|
|
||||||
_ = @import("behavior/bugs/704.zig");
|
|
||||||
_ = @import("behavior/bugs/718.zig");
|
|
||||||
_ = @import("behavior/bugs/726.zig");
|
|
||||||
_ = @import("behavior/bugs/828.zig");
|
|
||||||
_ = @import("behavior/bugs/920.zig");
|
|
||||||
_ = @import("behavior/bugs/1025.zig");
|
|
||||||
_ = @import("behavior/bugs/1076.zig");
|
|
||||||
_ = @import("behavior/bugs/1277.zig");
|
|
||||||
_ = @import("behavior/bugs/1310.zig");
|
|
||||||
_ = @import("behavior/bugs/1381.zig");
|
|
||||||
_ = @import("behavior/bugs/1421.zig");
|
|
||||||
_ = @import("behavior/bugs/1442.zig");
|
|
||||||
_ = @import("behavior/bugs/1486.zig");
|
|
||||||
_ = @import("behavior/bugs/1500.zig");
|
|
||||||
_ = @import("behavior/bugs/1607.zig");
|
|
||||||
_ = @import("behavior/bugs/1735.zig");
|
|
||||||
_ = @import("behavior/bugs/1851.zig");
|
|
||||||
_ = @import("behavior/bugs/1914.zig");
|
|
||||||
_ = @import("behavior/bugs/2006.zig");
|
|
||||||
_ = @import("behavior/bugs/2114.zig");
|
|
||||||
_ = @import("behavior/bugs/2346.zig");
|
|
||||||
_ = @import("behavior/bugs/2557.zig");
|
|
||||||
_ = @import("behavior/bugs/2578.zig");
|
|
||||||
_ = @import("behavior/bugs/2622.zig");
|
|
||||||
_ = @import("behavior/bugs/2692.zig");
|
|
||||||
_ = @import("behavior/bugs/2727.zig");
|
|
||||||
_ = @import("behavior/bugs/2889.zig");
|
|
||||||
_ = @import("behavior/bugs/3007.zig");
|
|
||||||
_ = @import("behavior/bugs/3046.zig");
|
|
||||||
_ = @import("behavior/bugs/3112.zig");
|
|
||||||
_ = @import("behavior/bugs/3367.zig");
|
|
||||||
_ = @import("behavior/bugs/3384.zig");
|
|
||||||
_ = @import("behavior/bugs/3586.zig");
|
|
||||||
_ = @import("behavior/bugs/3742.zig");
|
|
||||||
_ = @import("behavior/bugs/4328.zig");
|
|
||||||
_ = @import("behavior/bugs/4560.zig");
|
|
||||||
_ = @import("behavior/bugs/4769_a.zig");
|
|
||||||
_ = @import("behavior/bugs/4769_b.zig");
|
|
||||||
_ = @import("behavior/bugs/4954.zig");
|
|
||||||
_ = @import("behavior/bugs/5398.zig");
|
|
||||||
_ = @import("behavior/bugs/5413.zig");
|
|
||||||
_ = @import("behavior/bugs/5474.zig");
|
|
||||||
_ = @import("behavior/bugs/5487.zig");
|
|
||||||
_ = @import("behavior/bugs/6047.zig");
|
|
||||||
_ = @import("behavior/bugs/6456.zig");
|
|
||||||
_ = @import("behavior/bugs/6781.zig");
|
|
||||||
_ = @import("behavior/bugs/6850.zig");
|
|
||||||
_ = @import("behavior/bugs/6905.zig");
|
|
||||||
_ = @import("behavior/bugs/6947.zig");
|
|
||||||
_ = @import("behavior/bugs/7003.zig");
|
|
||||||
_ = @import("behavior/bugs/7047.zig");
|
|
||||||
_ = @import("behavior/bugs/7187.zig");
|
|
||||||
_ = @import("behavior/bugs/7325.zig");
|
|
||||||
_ = @import("behavior/bugs/8277.zig");
|
|
||||||
_ = @import("behavior/bugs/8646.zig");
|
|
||||||
_ = @import("behavior/bugs/9584.zig");
|
|
||||||
_ = @import("behavior/bugs/10138.zig");
|
|
||||||
_ = @import("behavior/bugs/10147.zig");
|
|
||||||
_ = @import("behavior/bugs/10970.zig");
|
|
||||||
_ = @import("behavior/bugs/10684.zig");
|
|
||||||
_ = @import("behavior/bugs/11046.zig");
|
|
||||||
_ = @import("behavior/bugs/11100.zig");
|
|
||||||
_ = @import("behavior/bugs/11139.zig");
|
|
||||||
_ = @import("behavior/bugs/11159.zig");
|
|
||||||
_ = @import("behavior/bugs/11162.zig");
|
|
||||||
_ = @import("behavior/bugs/11165.zig");
|
|
||||||
_ = @import("behavior/bugs/11179.zig");
|
|
||||||
_ = @import("behavior/bugs/11181.zig");
|
|
||||||
_ = @import("behavior/bugs/11213.zig");
|
|
||||||
_ = @import("behavior/bugs/11787.zig");
|
|
||||||
_ = @import("behavior/bugs/11816.zig");
|
|
||||||
_ = @import("behavior/bugs/11995.zig");
|
|
||||||
_ = @import("behavior/bugs/12000.zig");
|
|
||||||
_ = @import("behavior/bugs/12003.zig");
|
|
||||||
_ = @import("behavior/bugs/12025.zig");
|
|
||||||
_ = @import("behavior/bugs/12033.zig");
|
|
||||||
_ = @import("behavior/bugs/12043.zig");
|
|
||||||
_ = @import("behavior/bugs/12051.zig");
|
|
||||||
_ = @import("behavior/bugs/12092.zig");
|
|
||||||
_ = @import("behavior/bugs/12119.zig");
|
|
||||||
_ = @import("behavior/bugs/12142.zig");
|
|
||||||
_ = @import("behavior/bugs/12169.zig");
|
|
||||||
_ = @import("behavior/bugs/12430.zig");
|
|
||||||
_ = @import("behavior/bugs/12450.zig");
|
|
||||||
_ = @import("behavior/bugs/12486.zig");
|
|
||||||
_ = @import("behavior/bugs/12498.zig");
|
|
||||||
_ = @import("behavior/bugs/12551.zig");
|
|
||||||
_ = @import("behavior/bugs/12571.zig");
|
|
||||||
_ = @import("behavior/bugs/12644.zig");
|
|
||||||
_ = @import("behavior/bugs/12723.zig");
|
|
||||||
_ = @import("behavior/bugs/12776.zig");
|
|
||||||
_ = @import("behavior/bugs/12786.zig");
|
|
||||||
_ = @import("behavior/bugs/12794.zig");
|
|
||||||
_ = @import("behavior/bugs/12801-1.zig");
|
|
||||||
_ = @import("behavior/bugs/12801-2.zig");
|
|
||||||
_ = @import("behavior/bugs/12885.zig");
|
|
||||||
_ = @import("behavior/bugs/12890.zig");
|
|
||||||
_ = @import("behavior/bugs/12891.zig");
|
|
||||||
_ = @import("behavior/bugs/12911.zig");
|
|
||||||
_ = @import("behavior/bugs/12928.zig");
|
|
||||||
_ = @import("behavior/bugs/12945.zig");
|
|
||||||
_ = @import("behavior/bugs/12972.zig");
|
|
||||||
_ = @import("behavior/bugs/12984.zig");
|
|
||||||
_ = @import("behavior/bugs/13064.zig");
|
|
||||||
_ = @import("behavior/bugs/13065.zig");
|
|
||||||
_ = @import("behavior/bugs/13068.zig");
|
|
||||||
_ = @import("behavior/bugs/13069.zig");
|
|
||||||
_ = @import("behavior/bugs/13112.zig");
|
|
||||||
_ = @import("behavior/bugs/13113.zig");
|
|
||||||
_ = @import("behavior/bugs/13128.zig");
|
|
||||||
_ = @import("behavior/bugs/13159.zig");
|
|
||||||
_ = @import("behavior/bugs/13171.zig");
|
|
||||||
_ = @import("behavior/bugs/13209.zig");
|
|
||||||
_ = @import("behavior/bugs/13285.zig");
|
|
||||||
_ = @import("behavior/bugs/13366.zig");
|
|
||||||
_ = @import("behavior/bugs/13435.zig");
|
|
||||||
_ = @import("behavior/bugs/13664.zig");
|
|
||||||
_ = @import("behavior/bugs/13714.zig");
|
|
||||||
_ = @import("behavior/bugs/13785.zig");
|
|
||||||
_ = @import("behavior/bugs/14854.zig");
|
|
||||||
_ = @import("behavior/bugs/15778.zig");
|
|
||||||
_ = @import("behavior/byteswap.zig");
|
_ = @import("behavior/byteswap.zig");
|
||||||
_ = @import("behavior/byval_arg_var.zig");
|
_ = @import("behavior/byval_arg_var.zig");
|
||||||
_ = @import("behavior/c_char_signedness.zig");
|
_ = @import("behavior/c_char_signedness.zig");
|
||||||
@ -189,6 +59,7 @@ test {
|
|||||||
_ = @import("behavior/memset.zig");
|
_ = @import("behavior/memset.zig");
|
||||||
_ = @import("behavior/merge_error_sets.zig");
|
_ = @import("behavior/merge_error_sets.zig");
|
||||||
_ = @import("behavior/muladd.zig");
|
_ = @import("behavior/muladd.zig");
|
||||||
|
_ = @import("behavior/multiple_externs_with_conflicting_types.zig");
|
||||||
_ = @import("behavior/namespace_depends_on_compile_var.zig");
|
_ = @import("behavior/namespace_depends_on_compile_var.zig");
|
||||||
_ = @import("behavior/nan.zig");
|
_ = @import("behavior/nan.zig");
|
||||||
_ = @import("behavior/null.zig");
|
_ = @import("behavior/null.zig");
|
||||||
|
|||||||
@ -827,3 +827,121 @@ test "tuple initialized through reference to anonymous array init provides resul
|
|||||||
try expect(foo[0] == 12345);
|
try expect(foo[0] == 12345);
|
||||||
try expect(@intFromPtr(foo[1]) == 0x1000);
|
try expect(@intFromPtr(foo[1]) == 0x1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "copied array element doesn't alias source" {
|
||||||
|
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
|
||||||
|
|
||||||
|
var x: [10][10]u32 = undefined;
|
||||||
|
|
||||||
|
x[0][1] = 0;
|
||||||
|
const a = x[0];
|
||||||
|
x[0][1] = 15;
|
||||||
|
|
||||||
|
try expect(a[1] == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
test "array initialized with string literal" {
|
||||||
|
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
||||||
|
|
||||||
|
const S = struct {
|
||||||
|
a: u32,
|
||||||
|
c: [5]u8,
|
||||||
|
};
|
||||||
|
const U = union {
|
||||||
|
s: S,
|
||||||
|
};
|
||||||
|
const s_1 = S{
|
||||||
|
.a = undefined,
|
||||||
|
.c = "12345".*, // this caused problems
|
||||||
|
};
|
||||||
|
|
||||||
|
var u_2 = U{ .s = s_1 };
|
||||||
|
_ = &u_2;
|
||||||
|
try std.testing.expectEqualStrings("12345", &u_2.s.c);
|
||||||
|
}
|
||||||
|
|
||||||
|
test "array initialized with array with sentinel" {
|
||||||
|
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
||||||
|
|
||||||
|
const S = struct {
|
||||||
|
a: u32,
|
||||||
|
c: [5]u8,
|
||||||
|
};
|
||||||
|
const U = union {
|
||||||
|
s: S,
|
||||||
|
};
|
||||||
|
const c = [5:0]u8{ 1, 2, 3, 4, 5 };
|
||||||
|
const s_1 = S{
|
||||||
|
.a = undefined,
|
||||||
|
.c = c, // this caused problems
|
||||||
|
};
|
||||||
|
var u_2 = U{ .s = s_1 };
|
||||||
|
_ = &u_2;
|
||||||
|
try std.testing.expectEqualSlices(u8, &.{ 1, 2, 3, 4, 5 }, &u_2.s.c);
|
||||||
|
}
|
||||||
|
|
||||||
|
test "store array of array of structs at comptime" {
|
||||||
|
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
||||||
|
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
||||||
|
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
||||||
|
|
||||||
|
const S = struct {
|
||||||
|
fn storeArrayOfArrayOfStructs() u8 {
|
||||||
|
const S = struct {
|
||||||
|
x: u8,
|
||||||
|
};
|
||||||
|
|
||||||
|
var cases = [_][1]S{
|
||||||
|
[_]S{
|
||||||
|
S{ .x = 15 },
|
||||||
|
},
|
||||||
|
};
|
||||||
|
_ = &cases;
|
||||||
|
return cases[0][0].x;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
try expect(S.storeArrayOfArrayOfStructs() == 15);
|
||||||
|
try comptime expect(S.storeArrayOfArrayOfStructs() == 15);
|
||||||
|
}
|
||||||
|
|
||||||
|
test "accessing multidimensional global array at comptime" {
|
||||||
|
if (builtin.zig_backend == .stage2_x86) 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 S = struct {
|
||||||
|
const array = [_][]const []const u8{
|
||||||
|
&.{"hello"},
|
||||||
|
&.{ "world", "hello" },
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
try std.testing.expect(S.array[0].len == 1);
|
||||||
|
try std.testing.expectEqualStrings("hello", S.array[0][0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
test "union that needs padding bytes inside an array" {
|
||||||
|
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
|
||||||
|
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
|
||||||
|
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
||||||
|
|
||||||
|
const B = union(enum) {
|
||||||
|
D: u8,
|
||||||
|
E: u16,
|
||||||
|
};
|
||||||
|
const A = union(enum) {
|
||||||
|
B: B,
|
||||||
|
C: u8,
|
||||||
|
};
|
||||||
|
var as = [_]A{
|
||||||
|
A{ .B = B{ .D = 1 } },
|
||||||
|
A{ .B = B{ .D = 1 } },
|
||||||
|
};
|
||||||
|
_ = &as;
|
||||||
|
|
||||||
|
const a = as[0].B;
|
||||||
|
try std.testing.expect(a.D == 1);
|
||||||
|
}
|
||||||
|
|||||||
@ -1219,3 +1219,184 @@ test "integer compare" {
|
|||||||
try comptime S.doTheTestSigned(T);
|
try comptime S.doTheTestSigned(T);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "reference to inferred local variable works as expected" {
|
||||||
|
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
||||||
|
|
||||||
|
const Crasher = struct {
|
||||||
|
lets_crash: u64 = 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
var a: Crasher = undefined;
|
||||||
|
const crasher_ptr = &a;
|
||||||
|
var crasher_local = crasher_ptr.*;
|
||||||
|
const crasher_local_ptr = &crasher_local;
|
||||||
|
crasher_local_ptr.lets_crash = 1;
|
||||||
|
|
||||||
|
try expect(crasher_local.lets_crash != a.lets_crash);
|
||||||
|
}
|
||||||
|
|
||||||
|
test "@Type returned from block" {
|
||||||
|
const T = comptime b: {
|
||||||
|
break :b @Type(.{ .Int = .{
|
||||||
|
.signedness = .unsigned,
|
||||||
|
.bits = 8,
|
||||||
|
} });
|
||||||
|
};
|
||||||
|
try std.testing.expect(T == u8);
|
||||||
|
}
|
||||||
|
|
||||||
|
test "comptime variable initialized with addresses of literals" {
|
||||||
|
comptime var st = .{
|
||||||
|
.foo = &1,
|
||||||
|
.bar = &2,
|
||||||
|
};
|
||||||
|
_ = &st;
|
||||||
|
|
||||||
|
inline for (@typeInfo(@TypeOf(st)).Struct.fields) |field| {
|
||||||
|
_ = field;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
test "pointer to tuple field can be dereferenced at comptime" {
|
||||||
|
comptime {
|
||||||
|
const tuple_with_ptrs = .{ &0, &0 };
|
||||||
|
const field_ptr = (&tuple_with_ptrs.@"0");
|
||||||
|
_ = field_ptr.*;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
test "proper value is returned from labeled block" {
|
||||||
|
const S = struct {
|
||||||
|
fn hash(v: *u32, key: anytype) void {
|
||||||
|
const Key = @TypeOf(key);
|
||||||
|
if (@typeInfo(Key) == .ErrorSet) {
|
||||||
|
v.* += 1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
switch (@typeInfo(Key)) {
|
||||||
|
.ErrorUnion => blk: {
|
||||||
|
const payload = key catch |err| {
|
||||||
|
hash(v, err);
|
||||||
|
break :blk;
|
||||||
|
};
|
||||||
|
|
||||||
|
hash(v, payload);
|
||||||
|
},
|
||||||
|
|
||||||
|
else => unreachable,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const g: error{Test}!void = error.Test;
|
||||||
|
|
||||||
|
var v: u32 = 0;
|
||||||
|
S.hash(&v, g);
|
||||||
|
try expect(v == 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
test "const inferred array of slices" {
|
||||||
|
const T = struct { v: bool };
|
||||||
|
|
||||||
|
const decls = [_][]const T{
|
||||||
|
&[_]T{
|
||||||
|
.{ .v = false },
|
||||||
|
},
|
||||||
|
};
|
||||||
|
_ = decls;
|
||||||
|
}
|
||||||
|
|
||||||
|
test "var inferred array of slices" {
|
||||||
|
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
||||||
|
|
||||||
|
const T = struct { v: bool };
|
||||||
|
|
||||||
|
var decls = [_][]const T{
|
||||||
|
&[_]T{
|
||||||
|
.{ .v = false },
|
||||||
|
},
|
||||||
|
};
|
||||||
|
_ = &decls;
|
||||||
|
}
|
||||||
|
|
||||||
|
test "copy array of self-referential struct" {
|
||||||
|
const ListNode = struct {
|
||||||
|
next: ?*const @This() = null,
|
||||||
|
};
|
||||||
|
comptime var nodes = [_]ListNode{ .{}, .{} };
|
||||||
|
nodes[0].next = &nodes[1];
|
||||||
|
const copied_nodes = nodes;
|
||||||
|
_ = copied_nodes;
|
||||||
|
}
|
||||||
|
|
||||||
|
test "break out of block based on comptime known values" {
|
||||||
|
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
|
||||||
|
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
|
||||||
|
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
||||||
|
|
||||||
|
const S = struct {
|
||||||
|
const source = "A-";
|
||||||
|
|
||||||
|
fn parseNote() ?i32 {
|
||||||
|
const letter = source[0];
|
||||||
|
const modifier = source[1];
|
||||||
|
|
||||||
|
const semitone = blk: {
|
||||||
|
if (letter == 'C' and modifier == '-') break :blk @as(i32, 0);
|
||||||
|
if (letter == 'C' and modifier == '#') break :blk @as(i32, 1);
|
||||||
|
if (letter == 'D' and modifier == '-') break :blk @as(i32, 2);
|
||||||
|
if (letter == 'D' and modifier == '#') break :blk @as(i32, 3);
|
||||||
|
if (letter == 'E' and modifier == '-') break :blk @as(i32, 4);
|
||||||
|
if (letter == 'F' and modifier == '-') break :blk @as(i32, 5);
|
||||||
|
if (letter == 'F' and modifier == '#') break :blk @as(i32, 6);
|
||||||
|
if (letter == 'G' and modifier == '-') break :blk @as(i32, 7);
|
||||||
|
if (letter == 'G' and modifier == '#') break :blk @as(i32, 8);
|
||||||
|
if (letter == 'A' and modifier == '-') break :blk @as(i32, 9);
|
||||||
|
if (letter == 'A' and modifier == '#') break :blk @as(i32, 10);
|
||||||
|
if (letter == 'B' and modifier == '-') break :blk @as(i32, 11);
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
return semitone;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const result = S.parseNote();
|
||||||
|
try std.testing.expect(result.? == 9);
|
||||||
|
}
|
||||||
|
|
||||||
|
test "allocation and looping over 3-byte integer" {
|
||||||
|
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
|
||||||
|
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
|
||||||
|
|
||||||
|
if (builtin.zig_backend == .stage2_llvm and builtin.os.tag == .macos) {
|
||||||
|
return error.SkipZigTest; // TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch == .wasm32) {
|
||||||
|
return error.SkipZigTest; // TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
try expect(@sizeOf(u24) == 4);
|
||||||
|
try expect(@sizeOf([1]u24) == 4);
|
||||||
|
try expect(@alignOf(u24) == 4);
|
||||||
|
try expect(@alignOf([1]u24) == 4);
|
||||||
|
|
||||||
|
var x = try std.testing.allocator.alloc(u24, 2);
|
||||||
|
defer std.testing.allocator.free(x);
|
||||||
|
try expect(x.len == 2);
|
||||||
|
x[0] = 0xFFFFFF;
|
||||||
|
x[1] = 0xFFFFFF;
|
||||||
|
|
||||||
|
const bytes = std.mem.sliceAsBytes(x);
|
||||||
|
try expect(@TypeOf(bytes) == []align(4) u8);
|
||||||
|
try expect(bytes.len == 8);
|
||||||
|
|
||||||
|
for (bytes) |*b| {
|
||||||
|
b.* = 0x00;
|
||||||
|
}
|
||||||
|
|
||||||
|
try expect(x[0] == 0x00);
|
||||||
|
try expect(x[1] == 0x00);
|
||||||
|
}
|
||||||
|
|||||||
@ -152,3 +152,9 @@ test "Saturating Shift Left where lhs is of a computed type" {
|
|||||||
try expect(value.value == 2);
|
try expect(value.value == 2);
|
||||||
try expect(value.exponent == 0);
|
try expect(value.exponent == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
comptime {
|
||||||
|
var image: [1]u8 = undefined;
|
||||||
|
_ = ℑ
|
||||||
|
_ = @shlExact(@as(u16, image[0]), 8);
|
||||||
|
}
|
||||||
|
|||||||
@ -90,3 +90,12 @@ fn testShortCircuit(f: bool, t: bool) !void {
|
|||||||
try expect(hit_3);
|
try expect(hit_3);
|
||||||
try expect(hit_4);
|
try expect(hit_4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "or with noreturn operand" {
|
||||||
|
const S = struct {
|
||||||
|
fn foo(a: u32, b: u32) bool {
|
||||||
|
return a == 5 or b == 2 or @panic("oh no");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
_ = S.foo(2, 2);
|
||||||
|
}
|
||||||
|
|||||||
@ -1,34 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
const builtin = @import("builtin");
|
|
||||||
|
|
||||||
test "registers get overwritten when ignoring return" {
|
|
||||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
|
|
||||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
|
|
||||||
if (builtin.cpu.arch != .x86_64 or builtin.os.tag != .linux) return error.SkipZigTest;
|
|
||||||
|
|
||||||
const fd = open();
|
|
||||||
_ = write(fd, "a", 1);
|
|
||||||
_ = close(fd);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn open() usize {
|
|
||||||
return 42;
|
|
||||||
}
|
|
||||||
|
|
||||||
fn write(fd: usize, a: [*]const u8, len: usize) usize {
|
|
||||||
return syscall4(.WRITE, fd, @intFromPtr(a), len);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn syscall4(n: enum { WRITE }, a: usize, b: usize, c: usize) usize {
|
|
||||||
_ = n;
|
|
||||||
_ = a;
|
|
||||||
_ = b;
|
|
||||||
_ = c;
|
|
||||||
return 23;
|
|
||||||
}
|
|
||||||
|
|
||||||
fn close(fd: usize) usize {
|
|
||||||
if (fd != 42)
|
|
||||||
unreachable;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
@ -1,20 +0,0 @@
|
|||||||
const builtin = @import("builtin");
|
|
||||||
const std = @import("std");
|
|
||||||
|
|
||||||
test "test calling @clz on both vector and scalar inputs" {
|
|
||||||
if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
|
|
||||||
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
|
|
||||||
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
|
|
||||||
|
|
||||||
var x: u32 = 0x1;
|
|
||||||
_ = &x;
|
|
||||||
var y: @Vector(4, u32) = [_]u32{ 0x1, 0x1, 0x1, 0x1 };
|
|
||||||
_ = &y;
|
|
||||||
const a = @clz(x);
|
|
||||||
const b = @clz(y);
|
|
||||||
try std.testing.expectEqual(@as(u6, 31), a);
|
|
||||||
try std.testing.expectEqual([_]u6{ 31, 31, 31, 31 }, b);
|
|
||||||
}
|
|
||||||
@ -1,14 +0,0 @@
|
|||||||
const builtin = @import("builtin");
|
|
||||||
|
|
||||||
const A = struct {
|
|
||||||
B: type,
|
|
||||||
};
|
|
||||||
|
|
||||||
fn getA() A {
|
|
||||||
return A{ .B = u8 };
|
|
||||||
}
|
|
||||||
|
|
||||||
test "bug 1025" {
|
|
||||||
const a = getA();
|
|
||||||
try @import("std").testing.expect(a.B == u8);
|
|
||||||
}
|
|
||||||
@ -1,17 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
const builtin = @import("builtin");
|
|
||||||
const expectEqualStrings = std.testing.expectEqualStrings;
|
|
||||||
|
|
||||||
test "slicing slices" {
|
|
||||||
if (builtin.zig_backend == .stage2_x86) 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 foo = "1234";
|
|
||||||
const bar = foo[0..4];
|
|
||||||
try expectEqualStrings("1234", bar);
|
|
||||||
try expectEqualStrings("2", bar[1..2]);
|
|
||||||
try expectEqualStrings("3", bar[2..3]);
|
|
||||||
try expectEqualStrings("4", bar[3..4]);
|
|
||||||
try expectEqualStrings("34", bar[2..4]);
|
|
||||||
}
|
|
||||||
@ -1,27 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
const builtin = @import("builtin");
|
|
||||||
const mem = std.mem;
|
|
||||||
const expect = std.testing.expect;
|
|
||||||
|
|
||||||
test "comptime code should not modify constant data" {
|
|
||||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
|
|
||||||
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
|
||||||
|
|
||||||
try testCastPtrOfArrayToSliceAndPtr();
|
|
||||||
try comptime testCastPtrOfArrayToSliceAndPtr();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn testCastPtrOfArrayToSliceAndPtr() !void {
|
|
||||||
{
|
|
||||||
var array = "aoeu".*;
|
|
||||||
const x: [*]u8 = &array;
|
|
||||||
x[0] += 1;
|
|
||||||
try expect(mem.eql(u8, array[0..], "boeu"));
|
|
||||||
}
|
|
||||||
{
|
|
||||||
var array: [4]u8 = "aoeu".*;
|
|
||||||
const x: [*]u8 = &array;
|
|
||||||
x[0] += 1;
|
|
||||||
try expect(mem.eql(u8, array[0..], "boeu"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,20 +0,0 @@
|
|||||||
const builtin = @import("builtin");
|
|
||||||
|
|
||||||
fn retOpt() ?u32 {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
test "breaking from a loop in an if statement" {
|
|
||||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
|
|
||||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
|
|
||||||
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
|
||||||
|
|
||||||
var cond = true;
|
|
||||||
_ = &cond;
|
|
||||||
const opt = while (cond) {
|
|
||||||
if (retOpt()) |opt| {
|
|
||||||
break opt;
|
|
||||||
}
|
|
||||||
break 1;
|
|
||||||
} else 2;
|
|
||||||
_ = opt;
|
|
||||||
}
|
|
||||||
@ -1,22 +0,0 @@
|
|||||||
const builtin = @import("builtin");
|
|
||||||
|
|
||||||
fn foo() !void {
|
|
||||||
var a = true;
|
|
||||||
_ = &a;
|
|
||||||
if (a) return error.Foo;
|
|
||||||
return error.Bar;
|
|
||||||
}
|
|
||||||
fn bar() !void {
|
|
||||||
try foo();
|
|
||||||
}
|
|
||||||
|
|
||||||
test "fixed" {
|
|
||||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
|
||||||
|
|
||||||
bar() catch |err| switch (err) {
|
|
||||||
error.Foo => {}, // error: expected (inferred error set of bar), found error{Foo}
|
|
||||||
error.Bar => {},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@ -1,13 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
const builtin = @import("builtin");
|
|
||||||
|
|
||||||
pub fn do() bool {
|
|
||||||
inline for (.{"a"}) |_| {
|
|
||||||
if (true) return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
test "bug" {
|
|
||||||
try std.testing.expect(!do());
|
|
||||||
}
|
|
||||||
@ -1,26 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
const builtin = @import("builtin");
|
|
||||||
const expect = std.testing.expect;
|
|
||||||
|
|
||||||
test "store array of array of structs at comptime" {
|
|
||||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
|
||||||
|
|
||||||
try expect(storeArrayOfArrayOfStructs() == 15);
|
|
||||||
try comptime expect(storeArrayOfArrayOfStructs() == 15);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn storeArrayOfArrayOfStructs() u8 {
|
|
||||||
const S = struct {
|
|
||||||
x: u8,
|
|
||||||
};
|
|
||||||
|
|
||||||
var cases = [_][1]S{
|
|
||||||
[_]S{
|
|
||||||
S{ .x = 15 },
|
|
||||||
},
|
|
||||||
};
|
|
||||||
_ = &cases;
|
|
||||||
return cases[0][0].x;
|
|
||||||
}
|
|
||||||
@ -1,19 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
const builtin = @import("builtin");
|
|
||||||
|
|
||||||
test {
|
|
||||||
const T = @TypeOf(.{ @as(i32, 0), @as(u32, 0) });
|
|
||||||
var a: T = .{ 0, 0 };
|
|
||||||
_ = &a;
|
|
||||||
}
|
|
||||||
|
|
||||||
test {
|
|
||||||
const S = struct {
|
|
||||||
comptime x: i32 = 0,
|
|
||||||
comptime y: u32 = 0,
|
|
||||||
};
|
|
||||||
var a: S = .{};
|
|
||||||
_ = &a;
|
|
||||||
var b = S{};
|
|
||||||
_ = &b;
|
|
||||||
}
|
|
||||||
@ -1,16 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
const builtin = @import("builtin");
|
|
||||||
const expect = std.testing.expect;
|
|
||||||
|
|
||||||
test "aggregate initializers should allow initializing comptime fields, verifying equality" {
|
|
||||||
if (true) return error.SkipZigTest; // TODO
|
|
||||||
|
|
||||||
var x: u32 = 15;
|
|
||||||
_ = &x;
|
|
||||||
const T = @TypeOf(.{ @as(i32, -1234), @as(u32, 5678), x });
|
|
||||||
const a: T = .{ -1234, 5678, x + 1 };
|
|
||||||
|
|
||||||
try expect(a[0] == -1234);
|
|
||||||
try expect(a[1] == 5678);
|
|
||||||
try expect(a[2] == 16);
|
|
||||||
}
|
|
||||||
@ -1,44 +0,0 @@
|
|||||||
const builtin = @import("builtin");
|
|
||||||
|
|
||||||
test "bytes" {
|
|
||||||
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
|
||||||
|
|
||||||
const S = struct {
|
|
||||||
a: u32,
|
|
||||||
c: [5]u8,
|
|
||||||
};
|
|
||||||
|
|
||||||
const U = union {
|
|
||||||
s: S,
|
|
||||||
};
|
|
||||||
|
|
||||||
const s_1 = S{
|
|
||||||
.a = undefined,
|
|
||||||
.c = "12345".*, // this caused problems
|
|
||||||
};
|
|
||||||
|
|
||||||
var u_2 = U{ .s = s_1 };
|
|
||||||
_ = &u_2;
|
|
||||||
}
|
|
||||||
|
|
||||||
test "aggregate" {
|
|
||||||
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
|
||||||
|
|
||||||
const S = struct {
|
|
||||||
a: u32,
|
|
||||||
c: [5]u8,
|
|
||||||
};
|
|
||||||
|
|
||||||
const U = union {
|
|
||||||
s: S,
|
|
||||||
};
|
|
||||||
|
|
||||||
const c = [5:0]u8{ 1, 2, 3, 4, 5 };
|
|
||||||
const s_1 = S{
|
|
||||||
.a = undefined,
|
|
||||||
.c = c, // this caused problems
|
|
||||||
};
|
|
||||||
|
|
||||||
var u_2 = U{ .s = s_1 };
|
|
||||||
_ = &u_2;
|
|
||||||
}
|
|
||||||
@ -1,19 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
const builtin = @import("builtin");
|
|
||||||
const Type = std.builtin.Type;
|
|
||||||
|
|
||||||
test "Tuple" {
|
|
||||||
const fields_list = fields(@TypeOf(.{}));
|
|
||||||
if (fields_list.len != 0)
|
|
||||||
@compileError("Argument count mismatch");
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn fields(comptime T: type) switch (@typeInfo(T)) {
|
|
||||||
.Struct => []const Type.StructField,
|
|
||||||
else => unreachable,
|
|
||||||
} {
|
|
||||||
return switch (@typeInfo(T)) {
|
|
||||||
.Struct => |info| info.fields,
|
|
||||||
else => unreachable,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@ -1,25 +0,0 @@
|
|||||||
const builtin = @import("builtin");
|
|
||||||
|
|
||||||
test "const inferred array of slices" {
|
|
||||||
const T = struct { v: bool };
|
|
||||||
|
|
||||||
const decls = [_][]const T{
|
|
||||||
&[_]T{
|
|
||||||
.{ .v = false },
|
|
||||||
},
|
|
||||||
};
|
|
||||||
_ = decls;
|
|
||||||
}
|
|
||||||
|
|
||||||
test "var inferred array of slices" {
|
|
||||||
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
|
||||||
|
|
||||||
const T = struct { v: bool };
|
|
||||||
|
|
||||||
var decls = [_][]const T{
|
|
||||||
&[_]T{
|
|
||||||
.{ .v = false },
|
|
||||||
},
|
|
||||||
};
|
|
||||||
_ = &decls;
|
|
||||||
}
|
|
||||||
@ -1,33 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
const builtin = @import("builtin");
|
|
||||||
const testing = std.testing;
|
|
||||||
|
|
||||||
test {
|
|
||||||
const g: error{Test}!void = error.Test;
|
|
||||||
|
|
||||||
var v: u32 = 0;
|
|
||||||
hash(&v, g);
|
|
||||||
try testing.expect(v == 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn hash(v: *u32, key: anytype) void {
|
|
||||||
const Key = @TypeOf(key);
|
|
||||||
|
|
||||||
if (@typeInfo(Key) == .ErrorSet) {
|
|
||||||
v.* += 1;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (@typeInfo(Key)) {
|
|
||||||
.ErrorUnion => blk: {
|
|
||||||
const payload = key catch |err| {
|
|
||||||
hash(v, err);
|
|
||||||
break :blk;
|
|
||||||
};
|
|
||||||
|
|
||||||
hash(v, payload);
|
|
||||||
},
|
|
||||||
|
|
||||||
else => unreachable,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,19 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
const builtin = @import("builtin");
|
|
||||||
const testing = std.testing;
|
|
||||||
|
|
||||||
test "slicing zero length array field of struct" {
|
|
||||||
if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
|
|
||||||
|
|
||||||
const S = struct {
|
|
||||||
a: [0]usize,
|
|
||||||
fn foo(self: *@This(), start: usize, end: usize) []usize {
|
|
||||||
return self.a[start..end];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
var s: S = undefined;
|
|
||||||
try testing.expect(s.foo(0, 0).len == 0);
|
|
||||||
}
|
|
||||||
@ -1,14 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
const builtin = @import("builtin");
|
|
||||||
|
|
||||||
test {
|
|
||||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
|
||||||
|
|
||||||
var x: u32 = 3;
|
|
||||||
const val: usize = while (true) switch (x) {
|
|
||||||
1 => break 2,
|
|
||||||
else => x -= 1,
|
|
||||||
};
|
|
||||||
try std.testing.expect(val == 2);
|
|
||||||
}
|
|
||||||
@ -1,33 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
const testing = std.testing;
|
|
||||||
const builtin = @import("builtin");
|
|
||||||
|
|
||||||
fn wuffs_base__make_io_buffer(arg_data: wuffs_base__slice_u8, arg_meta: *wuffs_base__io_buffer_meta) callconv(.C) void {
|
|
||||||
arg_data.ptr[0] = 'w';
|
|
||||||
arg_meta.closed = false;
|
|
||||||
}
|
|
||||||
const wuffs_base__io_buffer_meta = extern struct {
|
|
||||||
wi: usize,
|
|
||||||
ri: usize,
|
|
||||||
pos: u64,
|
|
||||||
closed: bool,
|
|
||||||
};
|
|
||||||
const wuffs_base__slice_u8 = extern struct {
|
|
||||||
ptr: [*c]u8,
|
|
||||||
len: usize,
|
|
||||||
};
|
|
||||||
test {
|
|
||||||
if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
|
||||||
|
|
||||||
var string: [5]u8 = "hello".*;
|
|
||||||
const arg_data = wuffs_base__slice_u8{ .ptr = @as([*c]u8, @ptrCast(&string)), .len = string.len };
|
|
||||||
var arg_meta = wuffs_base__io_buffer_meta{ .wi = 1, .ri = 2, .pos = 3, .closed = true };
|
|
||||||
wuffs_base__make_io_buffer(arg_data, &arg_meta);
|
|
||||||
try std.testing.expectEqualStrings("wello", arg_data.ptr[0..arg_data.len]);
|
|
||||||
try std.testing.expectEqual(@as(usize, 1), arg_meta.wi);
|
|
||||||
try std.testing.expectEqual(@as(usize, 2), arg_meta.ri);
|
|
||||||
try std.testing.expectEqual(@as(u64, 3), arg_meta.pos);
|
|
||||||
try std.testing.expect(!arg_meta.closed);
|
|
||||||
}
|
|
||||||
@ -1,16 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
const builtin = @import("builtin");
|
|
||||||
|
|
||||||
const T = struct {
|
|
||||||
next: @TypeOf(null, @as(*const T, undefined)),
|
|
||||||
};
|
|
||||||
|
|
||||||
test {
|
|
||||||
if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
|
||||||
|
|
||||||
var t: T = .{ .next = null };
|
|
||||||
_ = &t;
|
|
||||||
try std.testing.expect(t.next == null);
|
|
||||||
}
|
|
||||||
@ -1,7 +0,0 @@
|
|||||||
test {
|
|
||||||
comptime {
|
|
||||||
const tuple_with_ptrs = .{ &0, &0 };
|
|
||||||
const field_ptr = (&tuple_with_ptrs.@"0");
|
|
||||||
_ = field_ptr.*;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,13 +0,0 @@
|
|||||||
const builtin = @import("builtin");
|
|
||||||
|
|
||||||
test {
|
|
||||||
comptime var st = .{
|
|
||||||
.foo = &1,
|
|
||||||
.bar = &2,
|
|
||||||
};
|
|
||||||
_ = &st;
|
|
||||||
|
|
||||||
inline for (@typeInfo(@TypeOf(st)).Struct.fields) |field| {
|
|
||||||
_ = field;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,13 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
const builtin = @import("builtin");
|
|
||||||
|
|
||||||
test {
|
|
||||||
const string = "Hello!\x00World!";
|
|
||||||
try std.testing.expect(@TypeOf(string) == *const [13:0]u8);
|
|
||||||
|
|
||||||
const slice_without_sentinel: []const u8 = string[0..6];
|
|
||||||
try std.testing.expect(@TypeOf(slice_without_sentinel) == []const u8);
|
|
||||||
|
|
||||||
const slice_with_sentinel: [:0]const u8 = string[0..6 :0];
|
|
||||||
try std.testing.expect(@TypeOf(slice_with_sentinel) == [:0]const u8);
|
|
||||||
}
|
|
||||||
@ -1,13 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
const builtin = @import("builtin");
|
|
||||||
const expect = std.testing.expect;
|
|
||||||
|
|
||||||
var ok = false;
|
|
||||||
fn foo(x: anytype) void {
|
|
||||||
ok = x;
|
|
||||||
}
|
|
||||||
test {
|
|
||||||
const x = &foo;
|
|
||||||
x(true);
|
|
||||||
try expect(ok);
|
|
||||||
}
|
|
||||||
@ -1,40 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
const builtin = @import("builtin");
|
|
||||||
|
|
||||||
test {
|
|
||||||
if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
|
|
||||||
|
|
||||||
const x = X{};
|
|
||||||
try std.testing.expectEqual(@as(u16, 0), x.y.a);
|
|
||||||
try std.testing.expectEqual(false, x.y.b);
|
|
||||||
try std.testing.expectEqual(Z{ .a = 0 }, x.y.c);
|
|
||||||
try std.testing.expectEqual(Z{ .a = 0 }, x.y.d);
|
|
||||||
}
|
|
||||||
|
|
||||||
const X = struct {
|
|
||||||
y: Y = Y.init(),
|
|
||||||
};
|
|
||||||
|
|
||||||
const Y = struct {
|
|
||||||
a: u16,
|
|
||||||
b: bool,
|
|
||||||
c: Z,
|
|
||||||
d: Z,
|
|
||||||
|
|
||||||
fn init() Y {
|
|
||||||
return .{
|
|
||||||
.a = 0,
|
|
||||||
.b = false,
|
|
||||||
.c = @as(Z, @bitCast(@as(u32, 0))),
|
|
||||||
.d = @as(Z, @bitCast(@as(u32, 0))),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const Z = packed struct {
|
|
||||||
a: u32,
|
|
||||||
};
|
|
||||||
@ -1,28 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
const builtin = @import("builtin");
|
|
||||||
|
|
||||||
const Foo = struct {
|
|
||||||
a: Bar,
|
|
||||||
};
|
|
||||||
|
|
||||||
const Bar = struct {
|
|
||||||
b: u32,
|
|
||||||
};
|
|
||||||
|
|
||||||
fn takeFoo(foo: *const Foo) !void {
|
|
||||||
try std.testing.expectEqual(@as(u32, 24), foo.a.b);
|
|
||||||
}
|
|
||||||
|
|
||||||
test {
|
|
||||||
if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
|
||||||
|
|
||||||
var baz: u32 = 24;
|
|
||||||
_ = &baz;
|
|
||||||
try takeFoo(&.{
|
|
||||||
.a = .{
|
|
||||||
.b = baz,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
@ -1,15 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
const builtin = @import("builtin");
|
|
||||||
|
|
||||||
const u8x32 = @Vector(32, u8);
|
|
||||||
const u32x8 = @Vector(8, u32);
|
|
||||||
|
|
||||||
test {
|
|
||||||
if (builtin.zig_backend == .stage2_x86) 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 zerox32: u8x32 = [_]u8{0} ** 32;
|
|
||||||
const bigsum: u32x8 = @as(u32x8, @bitCast(zerox32));
|
|
||||||
try std.testing.expectEqual(0, @reduce(.Add, bigsum));
|
|
||||||
}
|
|
||||||
@ -1,36 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
const builtin = @import("builtin");
|
|
||||||
|
|
||||||
const Holder = struct {
|
|
||||||
array: []const u8,
|
|
||||||
};
|
|
||||||
|
|
||||||
const Test = struct {
|
|
||||||
holders: []const Holder,
|
|
||||||
};
|
|
||||||
|
|
||||||
const Letter = enum(u8) {
|
|
||||||
A = 0x41,
|
|
||||||
B,
|
|
||||||
};
|
|
||||||
|
|
||||||
fn letter(e: Letter) u8 {
|
|
||||||
return @intFromEnum(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
test {
|
|
||||||
if (builtin.zig_backend == .stage2_x86) 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 test_struct = Test{
|
|
||||||
.holders = &.{
|
|
||||||
Holder{
|
|
||||||
.array = &.{
|
|
||||||
letter(.A),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
try std.testing.expectEqualStrings("A", test_struct.holders[0].array);
|
|
||||||
}
|
|
||||||
@ -1,19 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
const builtin = @import("builtin");
|
|
||||||
|
|
||||||
test {
|
|
||||||
if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
|
||||||
|
|
||||||
if (comptime builtin.zig_backend == .stage2_llvm and builtin.cpu.arch.endian() == .big) {
|
|
||||||
// https://github.com/ziglang/zig/issues/13782
|
|
||||||
return error.SkipZigTest;
|
|
||||||
}
|
|
||||||
|
|
||||||
const a = @Vector(2, bool){ true, true };
|
|
||||||
const b = @Vector(1, bool){true};
|
|
||||||
try std.testing.expect(@reduce(.And, a));
|
|
||||||
try std.testing.expect(@reduce(.And, b));
|
|
||||||
}
|
|
||||||
@ -1,11 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
|
|
||||||
test {
|
|
||||||
const T = comptime b: {
|
|
||||||
break :b @Type(.{ .Int = .{
|
|
||||||
.signedness = .unsigned,
|
|
||||||
.bits = 8,
|
|
||||||
} });
|
|
||||||
};
|
|
||||||
try std.testing.expect(T == u8);
|
|
||||||
}
|
|
||||||
@ -1,22 +0,0 @@
|
|||||||
const expect = @import("std").testing.expect;
|
|
||||||
const builtin = @import("builtin");
|
|
||||||
|
|
||||||
const Foo = packed struct {
|
|
||||||
a: i32,
|
|
||||||
b: u8,
|
|
||||||
};
|
|
||||||
|
|
||||||
var buffer: [256]u8 = undefined;
|
|
||||||
|
|
||||||
test {
|
|
||||||
if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
|
|
||||||
|
|
||||||
var f1: *align(16) Foo = @alignCast(@as(*align(1) Foo, @ptrCast(&buffer[0])));
|
|
||||||
try expect(@typeInfo(@TypeOf(f1)).Pointer.alignment == 16);
|
|
||||||
try expect(@intFromPtr(f1) == @intFromPtr(&f1.a));
|
|
||||||
try expect(@typeInfo(@TypeOf(&f1.a)).Pointer.alignment == 16);
|
|
||||||
}
|
|
||||||
@ -1,49 +0,0 @@
|
|||||||
const SomeEnum = union(enum) {
|
|
||||||
EnumVariant: u8,
|
|
||||||
};
|
|
||||||
|
|
||||||
const SomeStruct = struct {
|
|
||||||
struct_field: u8,
|
|
||||||
};
|
|
||||||
|
|
||||||
const OptEnum = struct {
|
|
||||||
opt_enum: ?SomeEnum,
|
|
||||||
};
|
|
||||||
|
|
||||||
const ErrEnum = struct {
|
|
||||||
err_enum: anyerror!SomeEnum,
|
|
||||||
};
|
|
||||||
|
|
||||||
const OptStruct = struct {
|
|
||||||
opt_struct: ?SomeStruct,
|
|
||||||
};
|
|
||||||
|
|
||||||
const ErrStruct = struct {
|
|
||||||
err_struct: anyerror!SomeStruct,
|
|
||||||
};
|
|
||||||
|
|
||||||
test {
|
|
||||||
_ = OptEnum{
|
|
||||||
.opt_enum = .{
|
|
||||||
.EnumVariant = 1,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
_ = ErrEnum{
|
|
||||||
.err_enum = .{
|
|
||||||
.EnumVariant = 1,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
_ = OptStruct{
|
|
||||||
.opt_struct = .{
|
|
||||||
.struct_field = 1,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
_ = ErrStruct{
|
|
||||||
.err_struct = .{
|
|
||||||
.struct_field = 1,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@ -1,9 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
const expect = std.testing.expect;
|
|
||||||
|
|
||||||
const S = struct { a: usize };
|
|
||||||
test "lazy abi size used in comparison" {
|
|
||||||
var rhs: i32 = 100;
|
|
||||||
_ = &rhs;
|
|
||||||
try expect(@sizeOf(S) < rhs);
|
|
||||||
}
|
|
||||||
@ -1,11 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
const builtin = @import("builtin");
|
|
||||||
|
|
||||||
test {
|
|
||||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
|
||||||
|
|
||||||
try std.testing.expect(for ([1]u8{0}) |x| {
|
|
||||||
if (x == 0) break true;
|
|
||||||
} else false);
|
|
||||||
}
|
|
||||||
@ -1,23 +0,0 @@
|
|||||||
const builtin = @import("builtin");
|
|
||||||
const std = @import("std");
|
|
||||||
const expect = std.testing.expect;
|
|
||||||
|
|
||||||
const Frame = packed struct {
|
|
||||||
num: u20,
|
|
||||||
};
|
|
||||||
|
|
||||||
const Entry = packed struct {
|
|
||||||
other: u12,
|
|
||||||
frame: Frame,
|
|
||||||
};
|
|
||||||
|
|
||||||
test {
|
|
||||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
|
|
||||||
|
|
||||||
const frame = Frame{ .num = 0x7FDE };
|
|
||||||
var entry = Entry{ .other = 0, .frame = .{ .num = 0xFFFFF } };
|
|
||||||
entry.frame = frame;
|
|
||||||
try expect(entry.frame.num == 0x7FDE);
|
|
||||||
}
|
|
||||||
@ -1,16 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
const builtin = @import("builtin");
|
|
||||||
|
|
||||||
inline fn foo(comptime T: type) !T {
|
|
||||||
return error.AnError;
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main0() !void {
|
|
||||||
_ = try foo(u8);
|
|
||||||
}
|
|
||||||
|
|
||||||
test "issue12644" {
|
|
||||||
main0() catch |e| {
|
|
||||||
try std.testing.expect(e == error.AnError);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@ -1,8 +0,0 @@
|
|||||||
const expect = @import("std").testing.expect;
|
|
||||||
|
|
||||||
test "Non-exhaustive enum backed by comptime_int" {
|
|
||||||
const E = enum(comptime_int) { a, b, c, _ };
|
|
||||||
comptime var e: E = .a;
|
|
||||||
e = @as(E, @enumFromInt(378089457309184723749));
|
|
||||||
try expect(@intFromEnum(e) == 378089457309184723749);
|
|
||||||
}
|
|
||||||
@ -1,21 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
const builtin = @import("builtin");
|
|
||||||
|
|
||||||
const S = struct {
|
|
||||||
f: ?*const fn () i32,
|
|
||||||
};
|
|
||||||
|
|
||||||
const s = S{ .f = &f };
|
|
||||||
|
|
||||||
fn f() i32 {
|
|
||||||
return 1234;
|
|
||||||
}
|
|
||||||
|
|
||||||
test "don't emit an LLVM global for a const function when it's in an optional in a struct" {
|
|
||||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
|
|
||||||
|
|
||||||
try std.testing.expect(s.f.?() == 1234);
|
|
||||||
}
|
|
||||||
@ -1,47 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
const builtin = @import("builtin");
|
|
||||||
|
|
||||||
const RAM = struct {
|
|
||||||
data: [0xFFFF + 1]u8,
|
|
||||||
fn new() !RAM {
|
|
||||||
return RAM{ .data = [_]u8{0} ** 0x10000 };
|
|
||||||
}
|
|
||||||
fn get(self: *RAM, addr: u16) u8 {
|
|
||||||
return self.data[addr];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const CPU = packed struct {
|
|
||||||
interrupts: bool,
|
|
||||||
ram: *RAM,
|
|
||||||
fn new(ram: *RAM) !CPU {
|
|
||||||
return CPU{
|
|
||||||
.ram = ram,
|
|
||||||
.interrupts = false,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
fn tick(self: *CPU) !void {
|
|
||||||
var queued_interrupts = self.ram.get(0xFFFF) & self.ram.get(0xFF0F);
|
|
||||||
_ = &queued_interrupts;
|
|
||||||
if (self.interrupts and queued_interrupts != 0) {
|
|
||||||
self.interrupts = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
test {
|
|
||||||
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
|
|
||||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
|
|
||||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
|
|
||||||
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest;
|
|
||||||
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
|
|
||||||
if (builtin.zig_backend == .stage2_x86_64) {
|
|
||||||
// Careful enabling this test, fails randomly.
|
|
||||||
return error.SkipZigTest;
|
|
||||||
}
|
|
||||||
|
|
||||||
var ram = try RAM.new();
|
|
||||||
var cpu = try CPU.new(&ram);
|
|
||||||
try cpu.tick();
|
|
||||||
try std.testing.expect(cpu.interrupts == false);
|
|
||||||
}
|
|
||||||
@ -1,28 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
|
|
||||||
fn NamespacedGlobals(comptime modules: anytype) type {
|
|
||||||
return @Type(.{
|
|
||||||
.Struct = .{
|
|
||||||
.layout = .Auto,
|
|
||||||
.is_tuple = false,
|
|
||||||
.fields = &.{
|
|
||||||
.{
|
|
||||||
.name = "globals",
|
|
||||||
.type = modules.mach.globals,
|
|
||||||
.default_value = null,
|
|
||||||
.is_comptime = false,
|
|
||||||
.alignment = @alignOf(modules.mach.globals),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
.decls = &[_]std.builtin.Type.Declaration{},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
test {
|
|
||||||
_ = NamespacedGlobals(.{
|
|
||||||
.mach = .{
|
|
||||||
.globals = struct {},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
@ -1,38 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
|
|
||||||
fn NamespacedComponents(comptime modules: anytype) type {
|
|
||||||
return @Type(.{
|
|
||||||
.Struct = .{
|
|
||||||
.layout = .Auto,
|
|
||||||
.is_tuple = false,
|
|
||||||
.fields = &.{.{
|
|
||||||
.name = "components",
|
|
||||||
.type = @TypeOf(modules.components),
|
|
||||||
.default_value = null,
|
|
||||||
.is_comptime = false,
|
|
||||||
.alignment = @alignOf(@TypeOf(modules.components)),
|
|
||||||
}},
|
|
||||||
.decls = &[_]std.builtin.Type.Declaration{},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
fn namespacedComponents(comptime modules: anytype) NamespacedComponents(modules) {
|
|
||||||
var x: NamespacedComponents(modules) = undefined;
|
|
||||||
x.components = modules.components;
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn World(comptime modules: anytype) type {
|
|
||||||
const all_components = namespacedComponents(modules);
|
|
||||||
_ = all_components;
|
|
||||||
return struct {};
|
|
||||||
}
|
|
||||||
|
|
||||||
test {
|
|
||||||
_ = World(.{
|
|
||||||
.components = .{
|
|
||||||
.location = struct {},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
@ -1,13 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
const builtin = @import("builtin");
|
|
||||||
|
|
||||||
comptime capacity: fn () u64 = capacity_,
|
|
||||||
fn capacity_() u64 {
|
|
||||||
return 64;
|
|
||||||
}
|
|
||||||
|
|
||||||
test {
|
|
||||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
|
||||||
|
|
||||||
try std.testing.expect((@This(){}).capacity() == 64);
|
|
||||||
}
|
|
||||||
@ -1,25 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
const builtin = @import("builtin");
|
|
||||||
|
|
||||||
const Auto = struct {
|
|
||||||
auto: [max_len]u8 = undefined,
|
|
||||||
offset: u64 = 0,
|
|
||||||
|
|
||||||
comptime capacity: *const fn () u64 = capacity,
|
|
||||||
|
|
||||||
const max_len: u64 = 32;
|
|
||||||
|
|
||||||
fn capacity() u64 {
|
|
||||||
return max_len;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
test {
|
|
||||||
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
|
|
||||||
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
|
|
||||||
|
|
||||||
const a: Auto = .{ .offset = 16, .capacity = Auto.capacity };
|
|
||||||
try std.testing.expect(a.capacity() == 32);
|
|
||||||
try std.testing.expect((a.capacity)() == 32);
|
|
||||||
}
|
|
||||||
@ -1,34 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
const builtin = std.builtin;
|
|
||||||
const expect = std.testing.expect;
|
|
||||||
|
|
||||||
const info = .{
|
|
||||||
.args = [_]builtin.Type.Error{
|
|
||||||
.{ .name = "bar" },
|
|
||||||
},
|
|
||||||
};
|
|
||||||
const Foo = @Type(.{
|
|
||||||
.ErrorSet = &info.args,
|
|
||||||
});
|
|
||||||
test "ErrorSet comptime_field_ptr" {
|
|
||||||
try expect(Foo == error{bar});
|
|
||||||
}
|
|
||||||
|
|
||||||
const fn_info = .{
|
|
||||||
.params = [_]builtin.Type.Fn.Param{
|
|
||||||
.{ .is_generic = false, .is_noalias = false, .type = u8 },
|
|
||||||
},
|
|
||||||
};
|
|
||||||
const Bar = @Type(.{
|
|
||||||
.Fn = .{
|
|
||||||
.calling_convention = .Unspecified,
|
|
||||||
.alignment = 0,
|
|
||||||
.is_generic = false,
|
|
||||||
.is_var_args = false,
|
|
||||||
.return_type = void,
|
|
||||||
.params = &fn_info.params,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
test "fn comptime_field_ptr" {
|
|
||||||
try expect(@typeInfo(Bar) == .Fn);
|
|
||||||
}
|
|
||||||
@ -1,18 +0,0 @@
|
|||||||
const expect = @import("std").testing.expect;
|
|
||||||
const builtin = @import("builtin");
|
|
||||||
|
|
||||||
fn a(b: []u3, c: u3) void {
|
|
||||||
switch (c) {
|
|
||||||
0...1 => b[c] = c,
|
|
||||||
2...3 => b[c] = c,
|
|
||||||
4...7 => |d| b[d] = c,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
test {
|
|
||||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
|
||||||
|
|
||||||
var arr: [8]u3 = undefined;
|
|
||||||
a(&arr, 5);
|
|
||||||
try expect(arr[5] == 5);
|
|
||||||
}
|
|
||||||
@ -1,83 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
const builtin = @import("builtin");
|
|
||||||
|
|
||||||
test "issue12891" {
|
|
||||||
const f = 10.0;
|
|
||||||
var i: usize = 0;
|
|
||||||
_ = &i;
|
|
||||||
try std.testing.expect(i < f);
|
|
||||||
}
|
|
||||||
test "nan" {
|
|
||||||
const f = comptime std.math.nan(f64);
|
|
||||||
var i: usize = 0;
|
|
||||||
_ = &i;
|
|
||||||
try std.testing.expect(!(f < i));
|
|
||||||
}
|
|
||||||
test "inf" {
|
|
||||||
const f = comptime std.math.inf(f64);
|
|
||||||
var i: usize = 0;
|
|
||||||
_ = &i;
|
|
||||||
try std.testing.expect(f > i);
|
|
||||||
}
|
|
||||||
test "-inf < 0" {
|
|
||||||
const f = comptime -std.math.inf(f64);
|
|
||||||
var i: usize = 0;
|
|
||||||
_ = &i;
|
|
||||||
try std.testing.expect(f < i);
|
|
||||||
}
|
|
||||||
test "inf >= 1" {
|
|
||||||
const f = comptime std.math.inf(f64);
|
|
||||||
var i: usize = 1;
|
|
||||||
_ = &i;
|
|
||||||
try std.testing.expect(f >= i);
|
|
||||||
}
|
|
||||||
test "isNan(nan * 1)" {
|
|
||||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
|
||||||
|
|
||||||
const nan_times_one = comptime std.math.nan(f64) * 1;
|
|
||||||
try std.testing.expect(std.math.isNan(nan_times_one));
|
|
||||||
}
|
|
||||||
test "runtime isNan(nan * 1)" {
|
|
||||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
|
||||||
|
|
||||||
const nan_times_one = std.math.nan(f64) * 1;
|
|
||||||
try std.testing.expect(std.math.isNan(nan_times_one));
|
|
||||||
}
|
|
||||||
test "isNan(nan * 0)" {
|
|
||||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
|
||||||
|
|
||||||
const nan_times_zero = comptime std.math.nan(f64) * 0;
|
|
||||||
try std.testing.expect(std.math.isNan(nan_times_zero));
|
|
||||||
const zero_times_nan = 0 * comptime std.math.nan(f64);
|
|
||||||
try std.testing.expect(std.math.isNan(zero_times_nan));
|
|
||||||
}
|
|
||||||
test "isNan(inf * 0)" {
|
|
||||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
|
||||||
|
|
||||||
const inf_times_zero = comptime std.math.inf(f64) * 0;
|
|
||||||
try std.testing.expect(std.math.isNan(inf_times_zero));
|
|
||||||
const zero_times_inf = 0 * comptime std.math.inf(f64);
|
|
||||||
try std.testing.expect(std.math.isNan(zero_times_inf));
|
|
||||||
}
|
|
||||||
test "runtime isNan(nan * 0)" {
|
|
||||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
|
||||||
|
|
||||||
const nan_times_zero = std.math.nan(f64) * 0;
|
|
||||||
try std.testing.expect(std.math.isNan(nan_times_zero));
|
|
||||||
const zero_times_nan = 0 * std.math.nan(f64);
|
|
||||||
try std.testing.expect(std.math.isNan(zero_times_nan));
|
|
||||||
}
|
|
||||||
test "runtime isNan(inf * 0)" {
|
|
||||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
|
||||||
|
|
||||||
const inf_times_zero = std.math.inf(f64) * 0;
|
|
||||||
try std.testing.expect(std.math.isNan(inf_times_zero));
|
|
||||||
const zero_times_inf = 0 * std.math.inf(f64);
|
|
||||||
try std.testing.expect(std.math.isNan(zero_times_inf));
|
|
||||||
}
|
|
||||||
@ -1,9 +0,0 @@
|
|||||||
const builtin = @import("builtin");
|
|
||||||
|
|
||||||
const Item = struct { field: u8 };
|
|
||||||
const Thing = struct {
|
|
||||||
array: [1]Item,
|
|
||||||
};
|
|
||||||
test {
|
|
||||||
_ = Thing{ .array = undefined };
|
|
||||||
}
|
|
||||||
@ -1,30 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
const builtin = @import("builtin");
|
|
||||||
const expect = std.testing.expect;
|
|
||||||
|
|
||||||
const A = extern struct {
|
|
||||||
value: *volatile B,
|
|
||||||
};
|
|
||||||
const B = extern struct {
|
|
||||||
a: u32,
|
|
||||||
b: i32,
|
|
||||||
};
|
|
||||||
|
|
||||||
test {
|
|
||||||
var a: *A = undefined;
|
|
||||||
try expect(@TypeOf(&a.value.a) == *volatile u32);
|
|
||||||
try expect(@TypeOf(&a.value.b) == *volatile i32);
|
|
||||||
}
|
|
||||||
|
|
||||||
const C = extern struct {
|
|
||||||
value: *volatile D,
|
|
||||||
};
|
|
||||||
const D = extern union {
|
|
||||||
a: u32,
|
|
||||||
b: i32,
|
|
||||||
};
|
|
||||||
test {
|
|
||||||
var c: *C = undefined;
|
|
||||||
try expect(@TypeOf(&c.value.a) == *volatile u32);
|
|
||||||
try expect(@TypeOf(&c.value.b) == *volatile i32);
|
|
||||||
}
|
|
||||||
@ -1,13 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
const expect = std.testing.expect;
|
|
||||||
|
|
||||||
fn A(
|
|
||||||
comptime T: type,
|
|
||||||
comptime destroycb: ?*const fn (?*T) callconv(.C) void,
|
|
||||||
) !void {
|
|
||||||
try expect(destroycb == null);
|
|
||||||
}
|
|
||||||
|
|
||||||
test {
|
|
||||||
try A(u32, null);
|
|
||||||
}
|
|
||||||
@ -1,18 +0,0 @@
|
|||||||
const builtin = @import("builtin");
|
|
||||||
|
|
||||||
pub fn f(_: [:null]const ?u8) void {}
|
|
||||||
|
|
||||||
test {
|
|
||||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
|
||||||
|
|
||||||
const c: u8 = 42;
|
|
||||||
f(&[_:null]?u8{c});
|
|
||||||
f(&.{c});
|
|
||||||
|
|
||||||
var v: u8 = 42;
|
|
||||||
_ = &v;
|
|
||||||
f(&[_:null]?u8{v});
|
|
||||||
f(&.{v});
|
|
||||||
}
|
|
||||||
@ -1,20 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
const builtin = @import("builtin");
|
|
||||||
|
|
||||||
pub fn DeleagateWithContext(comptime Function: type) type {
|
|
||||||
const ArgArgs = std.meta.ArgsTuple(Function);
|
|
||||||
return struct {
|
|
||||||
t: ArgArgs,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
pub const OnConfirm = DeleagateWithContext(fn (bool) void);
|
|
||||||
pub const CustomDraw = DeleagateWithContext(fn (?OnConfirm) void);
|
|
||||||
|
|
||||||
test "simple test" {
|
|
||||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
|
||||||
|
|
||||||
var c: CustomDraw = undefined;
|
|
||||||
_ = &c;
|
|
||||||
}
|
|
||||||
@ -1,17 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
const builtin = @import("builtin");
|
|
||||||
const expect = std.testing.expect;
|
|
||||||
|
|
||||||
test {
|
|
||||||
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
|
|
||||||
|
|
||||||
var x: [10][10]u32 = undefined;
|
|
||||||
|
|
||||||
x[0][1] = 0;
|
|
||||||
const a = x[0];
|
|
||||||
x[0][1] = 15;
|
|
||||||
|
|
||||||
try expect(a[1] == 0);
|
|
||||||
}
|
|
||||||
@ -1,22 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
const builtin = @import("builtin");
|
|
||||||
const expect = std.testing.expect;
|
|
||||||
|
|
||||||
const U = union(enum) {
|
|
||||||
array: [10]u32,
|
|
||||||
other: u32,
|
|
||||||
};
|
|
||||||
|
|
||||||
test {
|
|
||||||
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
|
|
||||||
|
|
||||||
var x = U{ .array = undefined };
|
|
||||||
|
|
||||||
x.array[1] = 0;
|
|
||||||
const a = x.array;
|
|
||||||
x.array[1] = 15;
|
|
||||||
|
|
||||||
try expect(a[1] == 0);
|
|
||||||
}
|
|
||||||
@ -1,14 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
const builtin = @import("builtin");
|
|
||||||
|
|
||||||
pub const allocator = std.heap.page_allocator;
|
|
||||||
var list = std.ArrayList(u32).init(allocator);
|
|
||||||
|
|
||||||
test {
|
|
||||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
|
|
||||||
|
|
||||||
list.items.len = 0;
|
|
||||||
}
|
|
||||||
@ -1,17 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
const builtin = @import("builtin");
|
|
||||||
const expect = std.testing.expect;
|
|
||||||
|
|
||||||
test {
|
|
||||||
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
|
|
||||||
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
|
|
||||||
|
|
||||||
var opt_x: ?[3]f32 = [_]f32{0.0} ** 3;
|
|
||||||
|
|
||||||
const x = opt_x.?;
|
|
||||||
opt_x.?[0] = 15.0;
|
|
||||||
|
|
||||||
try expect(x[0] == 0.0);
|
|
||||||
}
|
|
||||||
@ -1,27 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
const expect = std.testing.expect;
|
|
||||||
const builtin = @import("builtin");
|
|
||||||
|
|
||||||
pub const VM = ?[*]const struct_InvocationTable_;
|
|
||||||
pub const struct_InvocationTable_ = extern struct {
|
|
||||||
GetVM: ?*const fn (?[*]VM) callconv(.C) c_int,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub const struct_VM_ = extern struct {
|
|
||||||
functions: ?[*]const struct_InvocationTable_,
|
|
||||||
};
|
|
||||||
|
|
||||||
//excised output from stdlib.h etc
|
|
||||||
|
|
||||||
pub const InvocationTable_ = struct_InvocationTable_;
|
|
||||||
pub const VM_ = struct_VM_;
|
|
||||||
|
|
||||||
fn agent_callback(_vm: [*]VM, options: [*]u8) callconv(.C) i32 {
|
|
||||||
_ = _vm;
|
|
||||||
_ = options;
|
|
||||||
return 11;
|
|
||||||
}
|
|
||||||
|
|
||||||
test {
|
|
||||||
try expect(agent_callback(undefined, undefined) == 11);
|
|
||||||
}
|
|
||||||
@ -1,7 +0,0 @@
|
|||||||
fn nice(a: u32, b: u32) bool {
|
|
||||||
return a == 5 or b == 2 or @panic("oh no");
|
|
||||||
}
|
|
||||||
|
|
||||||
test {
|
|
||||||
_ = nice(2, 2);
|
|
||||||
}
|
|
||||||
@ -1,20 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
const builtin = @import("builtin");
|
|
||||||
|
|
||||||
const Foo = extern struct {
|
|
||||||
a: u8 align(1),
|
|
||||||
b: u16 align(1),
|
|
||||||
};
|
|
||||||
|
|
||||||
test {
|
|
||||||
if (builtin.zig_backend == .stage2_x86) 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 foo = Foo{
|
|
||||||
.a = 1,
|
|
||||||
.b = 2,
|
|
||||||
};
|
|
||||||
try std.testing.expectEqual(1, foo.a);
|
|
||||||
try std.testing.expectEqual(2, foo.b);
|
|
||||||
}
|
|
||||||
@ -1,29 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
const builtin = @import("builtin");
|
|
||||||
const expect = std.testing.expect;
|
|
||||||
|
|
||||||
const U = union(enum) {
|
|
||||||
x: u128,
|
|
||||||
y: [17]u8,
|
|
||||||
};
|
|
||||||
|
|
||||||
fn foo(val: U) !void {
|
|
||||||
try expect(val.x == 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
test "runtime union init, most-aligned field != largest" {
|
|
||||||
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
|
|
||||||
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
|
|
||||||
|
|
||||||
var x: u8 = 1;
|
|
||||||
_ = &x;
|
|
||||||
try foo(.{ .x = x });
|
|
||||||
|
|
||||||
const val: U = @unionInit(U, "x", x);
|
|
||||||
try expect(val.x == 1);
|
|
||||||
|
|
||||||
const val2: U = .{ .x = x };
|
|
||||||
try expect(val2.x == 1);
|
|
||||||
}
|
|
||||||
@ -1,18 +0,0 @@
|
|||||||
const builtin = @import("builtin");
|
|
||||||
const std = @import("std");
|
|
||||||
const expect = std.testing.expect;
|
|
||||||
|
|
||||||
const Bar = packed struct {
|
|
||||||
const Baz = enum {
|
|
||||||
fizz,
|
|
||||||
buzz,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
test {
|
|
||||||
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
|
||||||
|
|
||||||
var foo = Bar.Baz.fizz;
|
|
||||||
_ = &foo;
|
|
||||||
try expect(foo == .fizz);
|
|
||||||
}
|
|
||||||
@ -1,16 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
const expect = std.testing.expect;
|
|
||||||
|
|
||||||
fn BuildType(comptime T: type) type {
|
|
||||||
return struct {
|
|
||||||
val: union {
|
|
||||||
b: T,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
test {
|
|
||||||
const TestStruct = BuildType(u32);
|
|
||||||
const c = TestStruct{ .val = .{ .b = 10 } };
|
|
||||||
try expect(c.val.b == 10);
|
|
||||||
}
|
|
||||||
@ -1,5 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
test {
|
|
||||||
try std.testing.expect(-1 == @as(i8, -3) >> 2);
|
|
||||||
try std.testing.expect(-1 == -3 >> 2000);
|
|
||||||
}
|
|
||||||
@ -1,15 +0,0 @@
|
|||||||
const builtin = @import("builtin");
|
|
||||||
|
|
||||||
const Crasher = struct {
|
|
||||||
lets_crash: u64 = 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
test {
|
|
||||||
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
|
||||||
|
|
||||||
var a: Crasher = undefined;
|
|
||||||
const crasher_ptr = &a;
|
|
||||||
var crasher_local = crasher_ptr.*;
|
|
||||||
const crasher_local_ptr = &crasher_local;
|
|
||||||
crasher_local_ptr.lets_crash = 1;
|
|
||||||
}
|
|
||||||
@ -1,28 +0,0 @@
|
|||||||
const builtin = @import("builtin");
|
|
||||||
const std = @import("std");
|
|
||||||
const expect = std.testing.expect;
|
|
||||||
|
|
||||||
const ComptimeReason = union(enum) {
|
|
||||||
c_import: struct {
|
|
||||||
a: u32,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const Block = struct {
|
|
||||||
reason: ?*const ComptimeReason,
|
|
||||||
};
|
|
||||||
|
|
||||||
test {
|
|
||||||
if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
|
||||||
|
|
||||||
var a: u32 = 16;
|
|
||||||
_ = &a;
|
|
||||||
var reason = .{ .c_import = .{ .a = a } };
|
|
||||||
var block = Block{
|
|
||||||
.reason = &reason,
|
|
||||||
};
|
|
||||||
_ = █
|
|
||||||
try expect(block.reason.?.c_import.a == 16);
|
|
||||||
}
|
|
||||||
@ -1,22 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
|
|
||||||
fn CreateUnion(comptime T: type) type {
|
|
||||||
return @Type(.{
|
|
||||||
.Union = .{
|
|
||||||
.layout = .Auto,
|
|
||||||
.tag_type = null,
|
|
||||||
.fields = &[_]std.builtin.Type.UnionField{
|
|
||||||
.{
|
|
||||||
.name = "field",
|
|
||||||
.type = T,
|
|
||||||
.alignment = @alignOf(T),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
.decls = &[_]std.builtin.Type.Declaration{},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
test {
|
|
||||||
_ = CreateUnion(struct {});
|
|
||||||
}
|
|
||||||
@ -1,28 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
const builtin = @import("builtin");
|
|
||||||
|
|
||||||
const Fields = packed struct {
|
|
||||||
timestamp: u50,
|
|
||||||
random_bits: u13,
|
|
||||||
};
|
|
||||||
const ID = packed union {
|
|
||||||
value: u63,
|
|
||||||
fields: Fields,
|
|
||||||
};
|
|
||||||
fn value() i64 {
|
|
||||||
return 1341;
|
|
||||||
}
|
|
||||||
test {
|
|
||||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
|
|
||||||
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
|
|
||||||
|
|
||||||
const timestamp: i64 = value();
|
|
||||||
const id = ID{ .fields = Fields{
|
|
||||||
.timestamp = @as(u50, @intCast(timestamp)),
|
|
||||||
.random_bits = 420,
|
|
||||||
} };
|
|
||||||
try std.testing.expect((ID{ .value = id.value }).fields.timestamp == timestamp);
|
|
||||||
}
|
|
||||||
@ -1,5 +0,0 @@
|
|||||||
comptime {
|
|
||||||
var image: [1]u8 = undefined;
|
|
||||||
_ = ℑ
|
|
||||||
_ = @shlExact(@as(u16, image[0]), 8);
|
|
||||||
}
|
|
||||||
@ -1,14 +0,0 @@
|
|||||||
const builtin = @import("builtin");
|
|
||||||
const std = @import("std");
|
|
||||||
|
|
||||||
const S = packed struct { a: u0 = 0 };
|
|
||||||
test {
|
|
||||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
|
|
||||||
|
|
||||||
var a: u8 = 0;
|
|
||||||
_ = &a;
|
|
||||||
try std.io.null_writer.print("\n{} {}\n", .{ a, S{} });
|
|
||||||
}
|
|
||||||
@ -1,27 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
const builtin = @import("builtin");
|
|
||||||
|
|
||||||
const B = union(enum) {
|
|
||||||
D: u8,
|
|
||||||
E: u16,
|
|
||||||
};
|
|
||||||
|
|
||||||
const A = union(enum) {
|
|
||||||
B: B,
|
|
||||||
C: u8,
|
|
||||||
};
|
|
||||||
|
|
||||||
test "union that needs padding bytes inside an array" {
|
|
||||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
|
|
||||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
|
|
||||||
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
|
||||||
|
|
||||||
var as = [_]A{
|
|
||||||
A{ .B = B{ .D = 1 } },
|
|
||||||
A{ .B = B{ .D = 1 } },
|
|
||||||
};
|
|
||||||
_ = &as;
|
|
||||||
|
|
||||||
const a = as[0].B;
|
|
||||||
try std.testing.expect(a.D == 1);
|
|
||||||
}
|
|
||||||
@ -1,14 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
const expect = std.testing.expect;
|
|
||||||
const builtin = @import("builtin");
|
|
||||||
|
|
||||||
const S = struct {
|
|
||||||
fn method() std.builtin.Type {
|
|
||||||
return @typeInfo(S);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
test "functions with return type required to be comptime are generic" {
|
|
||||||
const ti = S.method();
|
|
||||||
try expect(@as(std.builtin.TypeId, ti) == std.builtin.TypeId.Struct);
|
|
||||||
}
|
|
||||||
@ -1,17 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
const builtin = @import("builtin");
|
|
||||||
|
|
||||||
const Union = union(enum) {
|
|
||||||
Text: []const u8,
|
|
||||||
Color: u32,
|
|
||||||
};
|
|
||||||
|
|
||||||
test "const error union field alignment" {
|
|
||||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
|
|
||||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
|
|
||||||
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
|
||||||
|
|
||||||
var union_or_err: anyerror!Union = Union{ .Color = 1234 };
|
|
||||||
_ = &union_or_err;
|
|
||||||
try std.testing.expect((union_or_err catch unreachable).Color == 1234);
|
|
||||||
}
|
|
||||||
@ -1,8 +0,0 @@
|
|||||||
pub const E = enum(u32) { A, B, C };
|
|
||||||
pub const S = extern struct {
|
|
||||||
e: E,
|
|
||||||
};
|
|
||||||
test "bug 1467" {
|
|
||||||
const s: S = undefined;
|
|
||||||
_ = s;
|
|
||||||
}
|
|
||||||
@ -1,14 +0,0 @@
|
|||||||
const testing = @import("std").testing;
|
|
||||||
const builtin = @import("builtin");
|
|
||||||
|
|
||||||
test {
|
|
||||||
try testing.expect(getGeneric(u8, getU8) == 123);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn getU8() callconv(.C) u8 {
|
|
||||||
return 123;
|
|
||||||
}
|
|
||||||
|
|
||||||
fn getGeneric(comptime T: type, supplier: fn () callconv(.C) T) T {
|
|
||||||
return supplier();
|
|
||||||
}
|
|
||||||
@ -1,14 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
const expect = std.testing.expect;
|
|
||||||
const builtin = @import("builtin");
|
|
||||||
|
|
||||||
const ptr = &global;
|
|
||||||
var global: usize = 123;
|
|
||||||
|
|
||||||
test "constant pointer to global variable causes runtime load" {
|
|
||||||
if (builtin.zig_backend == .stage2_aarch64 and builtin.os.tag == .macos) return error.SkipZigTest;
|
|
||||||
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
|
||||||
global = 1234;
|
|
||||||
try expect(&global == ptr);
|
|
||||||
try expect(ptr.* == 1234);
|
|
||||||
}
|
|
||||||
@ -1,16 +0,0 @@
|
|||||||
const builtin = @import("builtin");
|
|
||||||
const A = struct {
|
|
||||||
b: B,
|
|
||||||
};
|
|
||||||
|
|
||||||
const B = *const fn (A) void;
|
|
||||||
|
|
||||||
test "allow these dependencies" {
|
|
||||||
var a: A = undefined;
|
|
||||||
var b: B = undefined;
|
|
||||||
_ = .{ &a, &b };
|
|
||||||
if (false) {
|
|
||||||
a;
|
|
||||||
b;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,23 +0,0 @@
|
|||||||
const builtin = @import("builtin");
|
|
||||||
|
|
||||||
test {
|
|
||||||
if (builtin.zig_backend == .stage2_x86) 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_riscv64) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
|
||||||
const a = @Vector(0, i32){};
|
|
||||||
const b = @Vector(0, i32){};
|
|
||||||
_ = a + b;
|
|
||||||
}
|
|
||||||
|
|
||||||
test {
|
|
||||||
if (builtin.zig_backend == .stage2_x86) 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_riscv64) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
|
||||||
const a = @Vector(0, f32){};
|
|
||||||
const b = @Vector(0, f32){};
|
|
||||||
_ = a - b;
|
|
||||||
}
|
|
||||||
@ -1,20 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
const testing = std.testing;
|
|
||||||
const builtin = @import("builtin");
|
|
||||||
|
|
||||||
const a = [_]u8{ 1, 2, 3 };
|
|
||||||
|
|
||||||
fn checkAddress(s: []const u8) !void {
|
|
||||||
for (s, 0..) |*i, j| {
|
|
||||||
try testing.expect(i == &a[j]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
test "slices pointing at the same address as global array." {
|
|
||||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
|
|
||||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
|
|
||||||
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
|
||||||
|
|
||||||
try checkAddress(&a);
|
|
||||||
try comptime checkAddress(&a);
|
|
||||||
}
|
|
||||||
@ -1,50 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
const builtin = @import("builtin");
|
|
||||||
|
|
||||||
const mystruct = struct {
|
|
||||||
pending: ?listofstructs,
|
|
||||||
};
|
|
||||||
pub fn DoublyLinkedList(comptime T: type) type {
|
|
||||||
return struct {
|
|
||||||
const Self = @This();
|
|
||||||
|
|
||||||
pub const Node = struct {
|
|
||||||
prev: ?*Node,
|
|
||||||
next: ?*Node,
|
|
||||||
data: T,
|
|
||||||
};
|
|
||||||
|
|
||||||
first: ?*Node,
|
|
||||||
last: ?*Node,
|
|
||||||
len: usize,
|
|
||||||
|
|
||||||
pub fn init() Self {
|
|
||||||
return Self{
|
|
||||||
.first = null,
|
|
||||||
.last = null,
|
|
||||||
.len = 0,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
const listofstructs = DoublyLinkedList(mystruct);
|
|
||||||
|
|
||||||
const a = struct {
|
|
||||||
const Self = @This();
|
|
||||||
|
|
||||||
foo: listofstructs,
|
|
||||||
|
|
||||||
pub fn init() Self {
|
|
||||||
return Self{
|
|
||||||
.foo = listofstructs.init(),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
test "initialization" {
|
|
||||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
|
|
||||||
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
|
||||||
|
|
||||||
const t = a.init();
|
|
||||||
try std.testing.expect(t.foo.len == 0);
|
|
||||||
}
|
|
||||||
@ -1,40 +0,0 @@
|
|||||||
const builtin = @import("builtin");
|
|
||||||
const std = @import("std");
|
|
||||||
const expect = std.testing.expect;
|
|
||||||
|
|
||||||
test "allocation and looping over 3-byte integer" {
|
|
||||||
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
|
|
||||||
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
|
|
||||||
|
|
||||||
if (builtin.zig_backend == .stage2_llvm and builtin.os.tag == .macos) {
|
|
||||||
return error.SkipZigTest; // TODO
|
|
||||||
}
|
|
||||||
|
|
||||||
if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch == .wasm32) {
|
|
||||||
return error.SkipZigTest; // TODO
|
|
||||||
}
|
|
||||||
|
|
||||||
try expect(@sizeOf(u24) == 4);
|
|
||||||
try expect(@sizeOf([1]u24) == 4);
|
|
||||||
try expect(@alignOf(u24) == 4);
|
|
||||||
try expect(@alignOf([1]u24) == 4);
|
|
||||||
|
|
||||||
var x = try std.testing.allocator.alloc(u24, 2);
|
|
||||||
defer std.testing.allocator.free(x);
|
|
||||||
try expect(x.len == 2);
|
|
||||||
x[0] = 0xFFFFFF;
|
|
||||||
x[1] = 0xFFFFFF;
|
|
||||||
|
|
||||||
const bytes = std.mem.sliceAsBytes(x);
|
|
||||||
try expect(@TypeOf(bytes) == []align(4) u8);
|
|
||||||
try expect(bytes.len == 8);
|
|
||||||
|
|
||||||
for (bytes) |*b| {
|
|
||||||
b.* = 0x00;
|
|
||||||
}
|
|
||||||
|
|
||||||
try expect(x[0] == 0x00);
|
|
||||||
try expect(x[1] == 0x00);
|
|
||||||
}
|
|
||||||
@ -1,32 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
const builtin = @import("builtin");
|
|
||||||
|
|
||||||
const A = struct {
|
|
||||||
b_list_pointer: *const []B,
|
|
||||||
};
|
|
||||||
const B = struct {
|
|
||||||
a_pointer: *const A,
|
|
||||||
};
|
|
||||||
|
|
||||||
const b_list: []B = &[_]B{};
|
|
||||||
const a = A{ .b_list_pointer = &b_list };
|
|
||||||
|
|
||||||
test "segfault bug" {
|
|
||||||
const assert = std.debug.assert;
|
|
||||||
const obj = B{ .a_pointer = &a };
|
|
||||||
assert(obj.a_pointer == &a); // this makes zig crash
|
|
||||||
}
|
|
||||||
|
|
||||||
const A2 = struct {
|
|
||||||
pointer: *B,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub const B2 = struct {
|
|
||||||
pointer_array: []*A2,
|
|
||||||
};
|
|
||||||
|
|
||||||
var b_value = B2{ .pointer_array = &[_]*A2{} };
|
|
||||||
|
|
||||||
test "basic stuff" {
|
|
||||||
std.debug.assert(&b_value == &b_value);
|
|
||||||
}
|
|
||||||
@ -1,15 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
const expect = std.testing.expect;
|
|
||||||
const builtin = @import("builtin");
|
|
||||||
|
|
||||||
const S = struct {
|
|
||||||
p: *S,
|
|
||||||
};
|
|
||||||
test "bug 2006" {
|
|
||||||
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
|
||||||
|
|
||||||
var a: S = undefined;
|
|
||||||
a = S{ .p = undefined };
|
|
||||||
try expect(@sizeOf(S) != 0);
|
|
||||||
try expect(@sizeOf(*void) == @sizeOf(*i32));
|
|
||||||
}
|
|
||||||
@ -1,27 +0,0 @@
|
|||||||
const builtin = @import("builtin");
|
|
||||||
const std = @import("std");
|
|
||||||
const expect = std.testing.expect;
|
|
||||||
const math = std.math;
|
|
||||||
|
|
||||||
fn ctz(x: anytype) usize {
|
|
||||||
return @ctz(x);
|
|
||||||
}
|
|
||||||
|
|
||||||
test "fixed" {
|
|
||||||
if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf) return error.SkipZigTest;
|
|
||||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
|
|
||||||
|
|
||||||
try testCtz();
|
|
||||||
try comptime testCtz();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn testCtz() !void {
|
|
||||||
try expect(ctz(@as(u128, 0x40000000000000000000000000000000)) == 126);
|
|
||||||
try expect(math.rotl(u128, @as(u128, 0x40000000000000000000000000000000), @as(u8, 1)) == @as(u128, 0x80000000000000000000000000000000));
|
|
||||||
try expect(ctz(@as(u128, 0x80000000000000000000000000000000)) == 127);
|
|
||||||
try expect(ctz(math.rotl(u128, @as(u128, 0x40000000000000000000000000000000), @as(u8, 1))) == 127);
|
|
||||||
}
|
|
||||||
@ -1,10 +0,0 @@
|
|||||||
const builtin = @import("builtin");
|
|
||||||
|
|
||||||
test "fixed" {
|
|
||||||
const a: *void = undefined;
|
|
||||||
const b: *[1]void = a;
|
|
||||||
_ = b;
|
|
||||||
const c: *[0]u8 = undefined;
|
|
||||||
const d: []u8 = c;
|
|
||||||
_ = d;
|
|
||||||
}
|
|
||||||
@ -1,6 +0,0 @@
|
|||||||
test {
|
|
||||||
var a = if (true) {
|
|
||||||
return;
|
|
||||||
} else true;
|
|
||||||
_ = &a;
|
|
||||||
}
|
|
||||||
@ -1,20 +0,0 @@
|
|||||||
const builtin = @import("builtin");
|
|
||||||
|
|
||||||
const Foo = struct {
|
|
||||||
y: u8,
|
|
||||||
};
|
|
||||||
|
|
||||||
var foo: Foo = undefined;
|
|
||||||
const t = &foo;
|
|
||||||
|
|
||||||
fn bar(pointer: ?*anyopaque) void {
|
|
||||||
_ = pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
test "fixed" {
|
|
||||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
|
|
||||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
|
||||||
|
|
||||||
bar(t);
|
|
||||||
}
|
|
||||||
@ -1,14 +0,0 @@
|
|||||||
const builtin = @import("builtin");
|
|
||||||
|
|
||||||
var buf: []u8 = undefined;
|
|
||||||
|
|
||||||
test "reslice of undefined global var slice" {
|
|
||||||
if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
|
||||||
|
|
||||||
var mem: [100]u8 = [_]u8{0} ** 100;
|
|
||||||
buf = &mem;
|
|
||||||
const x = buf[0..1];
|
|
||||||
try @import("std").testing.expect(x.len == 1 and x[0] == 0);
|
|
||||||
}
|
|
||||||
@ -1,13 +0,0 @@
|
|||||||
const builtin = @import("builtin");
|
|
||||||
|
|
||||||
fn foo(a: []u8) void {
|
|
||||||
_ = a;
|
|
||||||
}
|
|
||||||
|
|
||||||
test "address of 0 length array" {
|
|
||||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
|
|
||||||
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
|
||||||
|
|
||||||
var pt: [0]u8 = undefined;
|
|
||||||
foo(&pt);
|
|
||||||
}
|
|
||||||
@ -1,16 +0,0 @@
|
|||||||
const builtin = @import("builtin");
|
|
||||||
|
|
||||||
fn t() bool {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
test {
|
|
||||||
if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
|
||||||
|
|
||||||
comptime var i: usize = 0;
|
|
||||||
inline while (i < 2) : (i += 1) {
|
|
||||||
if (t()) {} else return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,36 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
const builtin = @import("builtin");
|
|
||||||
|
|
||||||
const source = "A-";
|
|
||||||
|
|
||||||
fn parseNote() ?i32 {
|
|
||||||
const letter = source[0];
|
|
||||||
const modifier = source[1];
|
|
||||||
|
|
||||||
const semitone = blk: {
|
|
||||||
if (letter == 'C' and modifier == '-') break :blk @as(i32, 0);
|
|
||||||
if (letter == 'C' and modifier == '#') break :blk @as(i32, 1);
|
|
||||||
if (letter == 'D' and modifier == '-') break :blk @as(i32, 2);
|
|
||||||
if (letter == 'D' and modifier == '#') break :blk @as(i32, 3);
|
|
||||||
if (letter == 'E' and modifier == '-') break :blk @as(i32, 4);
|
|
||||||
if (letter == 'F' and modifier == '-') break :blk @as(i32, 5);
|
|
||||||
if (letter == 'F' and modifier == '#') break :blk @as(i32, 6);
|
|
||||||
if (letter == 'G' and modifier == '-') break :blk @as(i32, 7);
|
|
||||||
if (letter == 'G' and modifier == '#') break :blk @as(i32, 8);
|
|
||||||
if (letter == 'A' and modifier == '-') break :blk @as(i32, 9);
|
|
||||||
if (letter == 'A' and modifier == '#') break :blk @as(i32, 10);
|
|
||||||
if (letter == 'B' and modifier == '-') break :blk @as(i32, 11);
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
|
|
||||||
return semitone;
|
|
||||||
}
|
|
||||||
|
|
||||||
test "fixed" {
|
|
||||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
|
|
||||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
|
|
||||||
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
|
||||||
|
|
||||||
const result = parseNote();
|
|
||||||
try std.testing.expect(result.? == 9);
|
|
||||||
}
|
|
||||||
@ -1,28 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
const builtin = @import("builtin");
|
|
||||||
|
|
||||||
const Foo = struct {
|
|
||||||
free: bool,
|
|
||||||
|
|
||||||
pub const FooError = error{NotFree};
|
|
||||||
};
|
|
||||||
|
|
||||||
var foo = Foo{ .free = true };
|
|
||||||
var default_foo: ?*Foo = null;
|
|
||||||
|
|
||||||
fn get_foo() Foo.FooError!*Foo {
|
|
||||||
if (foo.free) {
|
|
||||||
foo.free = false;
|
|
||||||
return &foo;
|
|
||||||
}
|
|
||||||
return error.NotFree;
|
|
||||||
}
|
|
||||||
|
|
||||||
test "fixed" {
|
|
||||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
|
|
||||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
|
||||||
|
|
||||||
default_foo = get_foo() catch null; // This Line
|
|
||||||
try std.testing.expect(!default_foo.?.free);
|
|
||||||
}
|
|
||||||
@ -1,24 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
const builtin = @import("builtin");
|
|
||||||
const expect = std.testing.expect;
|
|
||||||
|
|
||||||
const SomeStruct = struct {
|
|
||||||
field: i32,
|
|
||||||
};
|
|
||||||
|
|
||||||
fn couldFail() anyerror!i32 {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
var some_struct: SomeStruct = undefined;
|
|
||||||
|
|
||||||
test "fixed" {
|
|
||||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
|
|
||||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
|
|
||||||
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
|
||||||
|
|
||||||
some_struct = SomeStruct{
|
|
||||||
.field = couldFail() catch @as(i32, 0),
|
|
||||||
};
|
|
||||||
try expect(some_struct.field == 1);
|
|
||||||
}
|
|
||||||
@ -1,23 +0,0 @@
|
|||||||
const builtin = @import("builtin");
|
|
||||||
const std = @import("std");
|
|
||||||
const expect = std.testing.expect;
|
|
||||||
|
|
||||||
const State = struct {
|
|
||||||
const Self = @This();
|
|
||||||
enter: *const fn (previous: ?Self) void,
|
|
||||||
};
|
|
||||||
|
|
||||||
fn prev(p: ?State) void {
|
|
||||||
expect(p == null) catch @panic("test failure");
|
|
||||||
}
|
|
||||||
|
|
||||||
test "zig test crash" {
|
|
||||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
|
|
||||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
|
|
||||||
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
|
||||||
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
|
|
||||||
|
|
||||||
var global: State = undefined;
|
|
||||||
global.enter = prev;
|
|
||||||
global.enter(null);
|
|
||||||
}
|
|
||||||
@ -1,15 +0,0 @@
|
|||||||
const builtin = @import("builtin");
|
|
||||||
const Foo = struct {
|
|
||||||
usingnamespace Mixin;
|
|
||||||
};
|
|
||||||
|
|
||||||
const Mixin = struct {
|
|
||||||
pub fn two(self: Foo) void {
|
|
||||||
_ = self;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
test "container member access usingnamespace decls" {
|
|
||||||
var foo = Foo{};
|
|
||||||
foo.two();
|
|
||||||
}
|
|
||||||
@ -1,11 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
const expect = std.testing.expect;
|
|
||||||
|
|
||||||
test "resolve array slice using builtin" {
|
|
||||||
try expect(@hasDecl(@This(), "std") == true);
|
|
||||||
try expect(@hasDecl(@This(), "std"[0..0]) == false);
|
|
||||||
try expect(@hasDecl(@This(), "std"[0..1]) == false);
|
|
||||||
try expect(@hasDecl(@This(), "std"[0..2]) == false);
|
|
||||||
try expect(@hasDecl(@This(), "std"[0..3]) == true);
|
|
||||||
try expect(@hasDecl(@This(), "std"[0..]) == true);
|
|
||||||
}
|
|
||||||
@ -1,7 +0,0 @@
|
|||||||
// zig fmt: off
|
|
||||||
test "pointer deref next to assignment" {
|
|
||||||
var a:i32=2;
|
|
||||||
var b=&a;
|
|
||||||
b.*=3;
|
|
||||||
_=&b;
|
|
||||||
}
|
|
||||||
@ -1,16 +0,0 @@
|
|||||||
const builtin = @import("builtin");
|
|
||||||
|
|
||||||
const NoteParams = struct {};
|
|
||||||
|
|
||||||
const Container = struct {
|
|
||||||
params: ?NoteParams,
|
|
||||||
};
|
|
||||||
|
|
||||||
test "fixed" {
|
|
||||||
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
|
||||||
|
|
||||||
var ctr = Container{
|
|
||||||
.params = NoteParams{},
|
|
||||||
};
|
|
||||||
_ = &ctr;
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user