From: Johnny Richard <johnny@johnnyrichard.com>
To: Carlos Maniero <carlos@maniero.me>
Cc: ~johnnyrichard/olang-devel@lists.sr.ht
Subject: Re: [PATCH olang v1 2/4] string_view: add string view conversion to uint32_t
Date: Thu, 29 Feb 2024 23:40:58 +0100 [thread overview]
Message-ID: <6twqh7dbwf4xyjrfyaamfirqeug5m2mt5y24mgmua5oulzf5yd@egsadwjvmk4g> (raw)
In-Reply-To: <CZHNU93PN41A.1Y74LHV3SFD6K@maniero.me>
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.
next prev parent reply other threads:[~2024-02-29 21:40 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-28 19:04 [PATCH olang v1 0/4] create initial syntax analysis logic Johnny Richard
2024-02-28 19:04 ` [PATCH olang v1 1/4] string_view: add string view formatter for printf fmt Johnny Richard
2024-02-28 19:04 ` [PATCH olang v1 2/4] string_view: add string view conversion to uint32_t Johnny Richard
2024-02-29 15:16 ` Carlos Maniero
2024-02-29 22:40 ` Johnny Richard [this message]
2024-02-28 19:04 ` [PATCH olang v1 3/4] lexer: add token lookahead capability Johnny Richard
2024-02-28 19:04 ` [PATCH olang v1 4/4] parser: create simplified parser for tiny AST Johnny Richard
2024-02-28 18:11 ` [olang/patches/.build.yml] build success builds.sr.ht
2024-03-01 3:34 ` [PATCH olang v1 4/4] parser: create simplified parser for tiny AST Carlos Maniero
2024-03-01 22:23 ` Johnny Richard
2024-03-01 22:33 ` [PATCH olang v1 0/4] create initial syntax analysis logic Johnny Richard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6twqh7dbwf4xyjrfyaamfirqeug5m2mt5y24mgmua5oulzf5yd@egsadwjvmk4g \
--to=johnny@johnnyrichard.com \
--cc=carlos@maniero.me \
--cc=~johnnyrichard/olang-devel@lists.sr.ht \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.johnnyrichard.com/olang.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox