Authentication-Results: mail-b.sr.ht; dkim=pass header.d=gpanders.com header.i=@gpanders.com Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [217.70.183.193]) by mail-b.sr.ht (Postfix) with ESMTPS id E5BB111EEF7 for <~andrewrk/ziglang@lists.sr.ht>; Tue, 2 Aug 2022 01:32:40 +0000 (UTC) Received: (Authenticated sender: greg@gpanders.com) by mail.gandi.net (Postfix) with ESMTPSA id E80FF240003; Tue, 2 Aug 2022 01:32:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gpanders.com; s=gm1; t=1659403959; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=KWpVx5lL/3ocZbxIrmflYUt6A8xQQ6X1+NuyydkCASY=; b=n/m9M8ux4BOKFVYXvwKrSch1kn/yuNb/qtZWWMMW52faC+7LPoatuv065lg6M2YVVjdPfB cQeiyzCYCOf1V1MAaF2yKcVkTsG9ZQcYYvlbNRqDDyEEAdSh9Ru1XQ92J9IHamCm79vXij b5r5FT7iuVboC9IrG/XAEHtoSJan16bnIKUQKw0iF89kmCcrfw2vIRcnP/hXtw25P25twy HnJloXgvo7vhwrqWYCsBbW+6luM8sd/yTxFW141oQScpjaZU3xZN8pObI1wLaKSudbUAqm 3thxbGn6+ocS7JlXLxujpBQCIQEOonEGK3s1/rWjPfDyOTR/dYQX8X/o+maOyg== Date: Tue, 2 Aug 2022 01:32:35 +0000 From: Gregory Anders To: Peter Bridge Cc: ~andrewrk/ziglang@lists.sr.ht Subject: Re: std.mem.eql and sentinels Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Disposition: inline In-Reply-To: On Mon, 01 Aug 2022 15:55 +0200, Peter Bridge wrote: >Are these considered equal? > >const a = [_:0]u8{ '4', '2'}; >const b = [_]u8{ '4', '2'}; > >I am not sure how I could even check the sentinels match, or if it >even matters :) but since I still have some custom string utils (some >with sentinels, and some without (wasm not C)), I want to also have >some tests to make sure they are adding/not adding sentinels in the >correct place. But then I get index of of bounds... Any tips on how >to test such functions please? Cheers Peter "Equal" in what sense? They have different types, but they would compare equal element-wise. Sentinels are encoded in the type system. To check if a given variable has a sentinel you can check the type info using @typeInfo, e.g. @typeInfo(@TypeOf(a)).Array.sentinel There are also some handy functions in std.meta for this kind of thing, e.g. std.meta.sentinel: const std = @import("std"); test { const a = [_:0]u8{ '4', '2' }; const b = [_]u8{ '4', '2' }; try std.testing.expectEqual(std.meta.sentinel(@TypeOf(a)), 0); try std.testing.expectEqual(std.meta.sentinel(@TypeOf(b)), null); } Greg