mirror of
https://github.com/ziglang/zig.git
synced 2026-02-12 20:37:54 +00:00
add test cases for arbitrary pointer sentinels
This commit is contained in:
parent
09ec720dab
commit
4018034708
@ -213,3 +213,51 @@ test "null terminated pointer" {
|
||||
S.doTheTest();
|
||||
comptime S.doTheTest();
|
||||
}
|
||||
|
||||
test "allow any sentinel" {
|
||||
const S = struct {
|
||||
fn doTheTest() void {
|
||||
var array = [_:std.math.minInt(i32)]i32{1, 2, 3, 4};
|
||||
var ptr: [*:std.math.minInt(i32)]i32 = &array;
|
||||
expect(ptr[4] == std.math.minInt(i32));
|
||||
}
|
||||
};
|
||||
S.doTheTest();
|
||||
comptime S.doTheTest();
|
||||
}
|
||||
|
||||
test "pointer sentinel with enums" {
|
||||
const S = struct {
|
||||
const Number = enum{one, two, sentinel};
|
||||
|
||||
fn doTheTest() void {
|
||||
var ptr: [*:.sentinel]Number = &[_:.sentinel]Number{.one, .two, .two, .one};
|
||||
expect(ptr[4] == .sentinel); // TODO this should be comptime expect, see #3731
|
||||
}
|
||||
};
|
||||
S.doTheTest();
|
||||
comptime S.doTheTest();
|
||||
}
|
||||
|
||||
test "pointer sentinel with optional element" {
|
||||
const S = struct {
|
||||
fn doTheTest() void {
|
||||
var ptr: [*:null]?i32 = &[_:null]?i32{1, 2, 3, 4};
|
||||
expect(ptr[4] == null); // TODO this should be comptime expect, see #3731
|
||||
}
|
||||
};
|
||||
S.doTheTest();
|
||||
comptime S.doTheTest();
|
||||
}
|
||||
|
||||
test "pointer sentinel with +inf" {
|
||||
const S = struct {
|
||||
fn doTheTest() void {
|
||||
const inf = std.math.inf_f32;
|
||||
var ptr: [*:inf]f32 = &[_:inf]f32{1.1, 2.2, 3.3, 4.4};
|
||||
expect(ptr[4] == inf); // TODO this should be comptime expect, see #3731
|
||||
}
|
||||
};
|
||||
S.doTheTest();
|
||||
comptime S.doTheTest();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user