From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0.migadu.com ([2001:41d0:303:5f26::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id YO/uL+n54GWRbAAAbAwnHQ (envelope-from ) for ; Thu, 29 Feb 2024 22:40:57 +0100 Received: from aspmx1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0.migadu.com with LMTPS id OJ7wKen54GXxegEAqHPOHw (envelope-from ) for ; Thu, 29 Feb 2024 22:40:57 +0100 X-Envelope-To: patches@johnnyrichard.com Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=lists.sr.ht header.s=20240113 header.b="joNhOq/d"; dkim=pass header.d=johnnyrichard.com header.s=key1 header.b=DPMnHAfB; spf=pass (aspmx1.migadu.com: domain of lists@sr.ht designates 46.23.81.152 as permitted sender) smtp.mailfrom=lists@sr.ht; dmarc=pass (policy=quarantine) header.from=johnnyrichard.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=johnnyrichard.com; s=key1; t=1709242857; h=from:from:sender:sender: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:list-id:list-unsubscribe:list-subscribe: list-post:dkim-signature; bh=X7Ttre3UVnc7Ndjw78vsq+A8q+CxhrmBoaGtzPvUTJ8=; b=1Mbok7BVulpN23OqoNE3ohtxdpveqhaZEKE5E7TjskzMcHavistUGll34VRzeByhqnITGE vy15T7gIb7IAisACAFdutjyurazX6zCTOdSE2h+mVOTLHXLNeK9MJ/brCL+IUlBnxKs4vm 7oEE19weTg9xgc4r1izIsgegqcdoJaRV+lpAqQb+rWbGOIUbLuDOuhil+dhSg80bYrNxwB SKlZfqncQ9RgOOMDu3Z3t6rwH7MJZIrxcKWPbTQMl8HDrkTqC0LPvMFagCj8ET+syP9L3X EkuZA8fgkM2pynt81PJLMq9SE6i26E6eC+7sz8tBf/QUFswzCOnBQzj/Y+ix2w== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=lists.sr.ht header.s=20240113 header.b="joNhOq/d"; dkim=pass header.d=johnnyrichard.com header.s=key1 header.b=DPMnHAfB; spf=pass (aspmx1.migadu.com: domain of lists@sr.ht designates 46.23.81.152 as permitted sender) smtp.mailfrom=lists@sr.ht; dmarc=pass (policy=quarantine) header.from=johnnyrichard.com ARC-Seal: i=1; s=key1; d=johnnyrichard.com; t=1709242857; a=rsa-sha256; cv=none; b=ICaPvhx8YeDLiWgDjXHOjDNiDbna9ML4oVv2Fkij1cWvTUA4juJMBqa9wHF7ncgx3dQk5/ 1ViSSoi6/7S94i4lFD/f4xe6f7HnLq4jauk/fCNjGvVHEcCZs4dpKRA/wwY5fEd4w8cD0+ lFzjg4n2IsUJfJLO/Hobumbks6xryNJlcPfkFPzV3YLrLfE5Epk3OcZGYICla93UDXy+Lm BPTU2kDHRUMVyS4zzVezU39q0BbMD9qOGyD3F6av/9O31egicpJ5RvigxdVfeKXIlOaIYx K6tTpKNe9dar2uFQwPfB0g4tbuZkbXnpkTcB6z/qYqv+Jf2d+Y4/ETA/GaMAGg== Received: from mail-a.sr.ht (mail-a.sr.ht [46.23.81.152]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 1AC7E6150B for ; Thu, 29 Feb 2024 22:40:54 +0100 (CET) DKIM-Signature: a=rsa-sha256; bh=/7aJFcz1K1lYBB34gleuptGTtB+dND8rIIESW1rszc8=; c=simple/simple; d=lists.sr.ht; h=Date:From:To:Cc:Subject:References:In-Reply-To:List-Unsubscribe:List-Subscribe:List-Archive:List-Post:List-ID; q=dns/txt; s=20240113; t=1709242853; v=1; b=joNhOq/dmX2HwCU1XVANmr37V/M/UM2QTHv7MnTE9Qi0lz5FSSpX/Y2eA5m2+VFZYNP8wBa9 3JjlREChSfrwQ+jl6TpsY7QU4g951vE18N7c/lVHNHyX/lpbvknoMPnpF4gNa2GZMVQIG94ce+j XbTBnkjm4tn3xVI6uSz27c2bpvWx9iQpLXrVshtAG2j8qs398tWb7Ie13hYbHPeWf4cn8b67np7 T5K9BnfUUqoXqiZ3SEV8BCx+OlC4OBeoF+Z/lYoyWFEP/GvUS7ondHO8oA2sumiM42BJmdFNZnk 8F+Bq7KB2/rWpXGXbjzbue8KtcyYZDOa+J1YyxMILRiLQ== Received: from lists.sr.ht (unknown [46.23.81.154]) by mail-a.sr.ht (Postfix) with ESMTPSA id 2F2BA202BB for ; Thu, 29 Feb 2024 21:40:53 +0000 (UTC) Received: from out-177.mta1.migadu.com (out-177.mta1.migadu.com [IPv6:2001:41d0:203:375::b1]) by mail-a.sr.ht (Postfix) with ESMTPS id 8BC0F200D2 for <~johnnyrichard/olang-devel@lists.sr.ht>; Thu, 29 Feb 2024 21:40:52 +0000 (UTC) Date: Thu, 29 Feb 2024 23:40:58 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=johnnyrichard.com; s=key1; t=1709242851; 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=X7Ttre3UVnc7Ndjw78vsq+A8q+CxhrmBoaGtzPvUTJ8=; b=DPMnHAfB3h3rVt+42pzRJ9jdVX+ChO2+VKu3ag1W2KTjew5X1ey30hpWFZOE/wuAvQ4CS1 Z+FRTE/HswgMoE6BOiYLFmIjycpG2hFgU2Jfsn1962Cmxn2rAyiiAYBvjxA07whVieUmQ+ yJ7/vlxvr7gb+9pza4qUASt+x9QCpfK2hyeCVJPcV2As1fYGZQsPCLsa5VBeQ6iCI8qAUR pXYwDRKNP8V3x40CIDj9pS8FkOSGF2sb3ht/qP1cro4nM+NJXD9iJ/OVH3Yf/pkzqN5UTS rNsi3NJ6hBiWE2pf/ZOU4eF0GR6NaL2qCs8VZHfbFAwywrTmllMP2aLivxFEuA== X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Johnny Richard To: Carlos Maniero Cc: ~johnnyrichard/olang-devel@lists.sr.ht Subject: Re: [PATCH olang v1 2/4] string_view: add string view conversion to uint32_t Message-ID: <6twqh7dbwf4xyjrfyaamfirqeug5m2mt5y24mgmua5oulzf5yd@egsadwjvmk4g> References: <20240228190956.78191-1-johnny@johnnyrichard.com> <20240228190956.78191-3-johnny@johnnyrichard.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Unsubscribe: List-Subscribe: List-Archive: Archived-At: List-Post: List-ID: ~johnnyrichard/olang-devel <~johnnyrichard/olang-devel.lists.sr.ht> Sender: ~johnnyrichard/olang-devel <~johnnyrichard/olang-devel@lists.sr.ht> X-Migadu-Country: NL X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: -8.04 X-Spam-Score: -8.04 X-Migadu-Queue-Id: 1AC7E6150B X-Migadu-Scanner: mx11.migadu.com X-TUID: +YTcZ23/IGCU On Thu, Feb 29, 2024 at 12:16:07PM -0300, Carlos Maniero wrote: > > + memset(ret, 0, str.size + 1); > > + memcpy(ret, str.chars, str.size); > This will iterate *str.size* times twice. Instead of using *memset* you > could only set the *NULL terminator* as the last char of *ret*. Sure, I will fix it in an other revision. > > +static MunitResult > > +string_view_eq_to_cstr_test(const MunitParameter params[], void *user_data_or_fixture) > > +{ > > + char *name = "John Doe"; > > + > > + string_view_t str = { .chars = name, .size = strlen(name) }; > > + > > + assert_true(string_view_eq_to_cstr(str, "John Doe")); > > + assert_false(string_view_eq_to_cstr(str, "Doe")); > > + > > + return MUNIT_OK; > > +} > It would be great if you add also a test taking just a portion of the > string to make sure the *.size* is working. Hmm... I think it's better to create a separated test for this. > > +static MunitResult > > +string_view_to_u32_test(const MunitParameter params[], void *user_data_or_fixture) > > +{ > > + char *number = "69"; > > + > > + string_view_t str = { .chars = number, .size = strlen(number) }; > > + > > + assert_uint32(string_view_to_u32(str), ==, 69); > > + > > + return MUNIT_OK; > > +} > Same here. Instead of taking the entire number you can get just a digit. I will create another test for this. Something like test create slice over cstr.