authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-05-08 19:02:15+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-05-08 19:03:27+03:00
log336ddb5b7656367d074ab7d8a6899321a041452c
treeebf575313f251d7e4d60f6b3c5ffc3f8e2ebd30f
parent92a423739d91bd0677940fc1a86b593649cafaa6
signature Commit is signed but in an unrecognized format.

std: add test for mem.zeroes on sentinel terminated arrays


1 files changed, 7 insertions(+), 3 deletions(-)

lib/std/mem.zig+7-3
......@@ -341,8 +341,8 @@ pub fn zeroes(comptime T: type) T {
341341 }
342342 },
343343 .Array => |info| {
344 if (info.sentinel) |sentinel| {
345 return [_:info.sentinel]info.child{zeroes(info.child)} ** info.len;
344 if (info.sentinel) |sentinel| {
345 return [_:sentinel]info.child{zeroes(info.child)} ** info.len;
346346 }
347347 return [_]info.child{zeroes(info.child)} ** info.len;
348348 },
......@@ -407,6 +407,7 @@ test "mem.zeroes" {
407407 array: [2]u32,
408408 optional_int: ?u8,
409409 empty: void,
410 sentinel: [3:0]u8,
410411 };
411412
412413 const b = zeroes(ZigStruct);
......@@ -431,6 +432,9 @@ test "mem.zeroes" {
431432 testing.expectEqual(@as(u32, 0), e);
432433 }
433434 testing.expectEqual(@as(?u8, null), b.optional_int);
435 for (b.sentinel) |e| {
436 testing.expectEqual(@as(u8, 0), e);
437 }
434438}
435439
436440pub fn secureZero(comptime T: type, s: []T) void {
......@@ -504,7 +508,7 @@ pub const toSlice = @compileError("deprecated; use std.mem.spanZ");
504508/// the constness of the input type. `[*c]` pointers are assumed to be 0-terminated,
505509/// and assumed to not allow null.
506510pub fn Span(comptime T: type) type {
507 switch(@typeInfo(T)) {
511 switch (@typeInfo(T)) {
508512 .Optional => |optional_info| {
509513 return ?Span(optional_info.child);
510514 },