authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-11-24 16:52:32-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-11-24 16:52:32-05:00
log4018034708beea63086a34d361ffb400979a1189
tree5d24aa6feb04b778f00bd2fa54df5b94cdc6913b
parent09ec720dab6331c8be0300f2943f7d757ad0d7c3
signaturelock-open Commit is signed but in an unrecognized format.

add test cases for arbitrary pointer sentinels


1 files changed, 48 insertions(+), 0 deletions(-)

test/stage1/behavior/pointers.zig+48
......@@ -213,3 +213,51 @@ test "null terminated pointer" {
213213 S.doTheTest();
214214 comptime S.doTheTest();
215215}
216
217test "allow any sentinel" {
218 const S = struct {
219 fn doTheTest() void {
220 var array = [_:std.math.minInt(i32)]i32{1, 2, 3, 4};
221 var ptr: [*:std.math.minInt(i32)]i32 = &array;
222 expect(ptr[4] == std.math.minInt(i32));
223 }
224 };
225 S.doTheTest();
226 comptime S.doTheTest();
227}
228
229test "pointer sentinel with enums" {
230 const S = struct {
231 const Number = enum{one, two, sentinel};
232
233 fn doTheTest() void {
234 var ptr: [*:.sentinel]Number = &[_:.sentinel]Number{.one, .two, .two, .one};
235 expect(ptr[4] == .sentinel); // TODO this should be comptime expect, see #3731
236 }
237 };
238 S.doTheTest();
239 comptime S.doTheTest();
240}
241
242test "pointer sentinel with optional element" {
243 const S = struct {
244 fn doTheTest() void {
245 var ptr: [*:null]?i32 = &[_:null]?i32{1, 2, 3, 4};
246 expect(ptr[4] == null); // TODO this should be comptime expect, see #3731
247 }
248 };
249 S.doTheTest();
250 comptime S.doTheTest();
251}
252
253test "pointer sentinel with +inf" {
254 const S = struct {
255 fn doTheTest() void {
256 const inf = std.math.inf_f32;
257 var ptr: [*:inf]f32 = &[_:inf]f32{1.1, 2.2, 3.3, 4.4};
258 expect(ptr[4] == inf); // TODO this should be comptime expect, see #3731
259 }
260 };
261 S.doTheTest();
262 comptime S.doTheTest();
263}