categorize behavior/bugs/<issueno>.zig tests
This commit is contained in:
committed by
Andrew Kelley
parent
282ff8d3bd
commit
804cee3b93
@@ -827,3 +827,121 @@ test "tuple initialized through reference to anonymous array init provides resul
|
||||
try expect(foo[0] == 12345);
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user