public inbox for ~johnnyrichard/olang-devel@lists.sr.ht
 help / color / mirror / code / Atom feed
From: "Carlos Maniero" <carlos@maniero.me>
To: "Johnny Richard" <johnny@johnnyrichard.com>,
	<~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 12:16:07 -0300	[thread overview]
Message-ID: <CZHNU93PN41A.1Y74LHV3SFD6K@maniero.me> (raw)
In-Reply-To: <20240228190956.78191-3-johnny@johnnyrichard.com>

First of all, thank you for adding tests to *string_view*. I've just
a few small adjustments to ask:

> +    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*.

> +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.

> +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.

  reply	other threads:[~2024-02-29 15:16 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 [this message]
2024-02-29 22:40     ` Johnny Richard
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=CZHNU93PN41A.1Y74LHV3SFD6K@maniero.me \
    --to=carlos@maniero.me \
    --cc=johnny@johnnyrichard.com \
    --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