diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2021-09-07 17:53:49 -0400 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2021-10-17 09:49:01 -0400 |
commit | f0e693b18afbe1de37d7da5b5a8967b6c87d8e53 (patch) | |
tree | be5e1cdbfa218ba81ec06bf45e45cfeb7f79a2a5 /tests/buf/basic.c | |
parent | 5346be3ddd3bcf19779c5d62e71f8442a0171133 (diff) | |
download | libgit2-ethomson/gitstr.tar.gz |
str: introduce `git_str` for internal, `git_buf` is externalethomson/gitstr
libgit2 has two distinct requirements that were previously solved by
`git_buf`. We require:
1. A general purpose string class that provides a number of utility APIs
for manipulating data (eg, concatenating, truncating, etc).
2. A structure that we can use to return strings to callers that they
can take ownership of.
By using a single class (`git_buf`) for both of these purposes, we have
confused the API to the point that refactorings are difficult and
reasoning about correctness is also difficult.
Move the utility class `git_buf` to be called `git_str`: this represents
its general purpose, as an internal string buffer class. The name also
is an homage to Junio Hamano ("gitstr").
The public API remains `git_buf`, and has a much smaller footprint. It
is generally only used as an "out" param with strict requirements that
follow the documentation. (Exceptions exist for some legacy APIs to
avoid breaking callers unnecessarily.)
Utility functions exist to convert a user-specified `git_buf` to a
`git_str` so that we can call internal functions, then converting it
back again.
Diffstat (limited to 'tests/buf/basic.c')
-rw-r--r-- | tests/buf/basic.c | 51 |
1 files changed, 0 insertions, 51 deletions
diff --git a/tests/buf/basic.c b/tests/buf/basic.c deleted file mode 100644 index f90c4c6ed..000000000 --- a/tests/buf/basic.c +++ /dev/null @@ -1,51 +0,0 @@ -#include "clar_libgit2.h" -#include "buffer.h" - -static const char *test_string = "Have you seen that? Have you seeeen that??"; - -void test_buf_basic__resize(void) -{ - git_buf buf1 = GIT_BUF_INIT; - git_buf_puts(&buf1, test_string); - cl_assert(git_buf_oom(&buf1) == 0); - cl_assert_equal_s(git_buf_cstr(&buf1), test_string); - - git_buf_puts(&buf1, test_string); - cl_assert(strlen(git_buf_cstr(&buf1)) == strlen(test_string) * 2); - git_buf_dispose(&buf1); -} - -void test_buf_basic__resize_incremental(void) -{ - git_buf buf1 = GIT_BUF_INIT; - - /* Presently, asking for 6 bytes will round up to 8. */ - cl_git_pass(git_buf_puts(&buf1, "Hello")); - cl_assert_equal_i(5, buf1.size); - cl_assert_equal_i(8, buf1.asize); - - /* Ensure an additional byte does not realloc. */ - cl_git_pass(git_buf_grow_by(&buf1, 1)); - cl_assert_equal_i(5, buf1.size); - cl_assert_equal_i(8, buf1.asize); - - /* But requesting many does. */ - cl_git_pass(git_buf_grow_by(&buf1, 16)); - cl_assert_equal_i(5, buf1.size); - cl_assert(buf1.asize > 8); - - git_buf_dispose(&buf1); -} - -void test_buf_basic__printf(void) -{ - git_buf buf2 = GIT_BUF_INIT; - git_buf_printf(&buf2, "%s %s %d ", "shoop", "da", 23); - cl_assert(git_buf_oom(&buf2) == 0); - cl_assert_equal_s(git_buf_cstr(&buf2), "shoop da 23 "); - - git_buf_printf(&buf2, "%s %d", "woop", 42); - cl_assert(git_buf_oom(&buf2) == 0); - cl_assert_equal_s(git_buf_cstr(&buf2), "shoop da 23 woop 42"); - git_buf_dispose(&buf2); -} |