Commit abdaf936 by Patrick Reynolds

add unit tests for git_buf_join corner cases

parent 7cbc6241
......@@ -406,6 +406,23 @@ check_joinbuf_2(
}
static void
check_joinbuf_overlapped(
const char *oldval,
int ofs_a,
const char *b,
const char *expected)
{
char sep = '/';
git_buf buf = GIT_BUF_INIT;
git_buf_sets(&buf, oldval);
git_buf_join(&buf, sep, buf.ptr + ofs_a, b);
cl_assert(git_buf_oom(&buf) == 0);
cl_assert_equal_s(expected, git_buf_cstr(&buf));
git_buf_free(&buf);
}
static void
check_joinbuf_n_2(
const char *a,
const char *b,
......@@ -480,6 +497,20 @@ void test_core_buffer__8(void)
check_joinbuf_2("/abcd/", "defg/", "/abcd/defg/");
check_joinbuf_2("/abcd/", "/defg/", "/abcd/defg/");
check_joinbuf_overlapped("abcd", 0, "efg", "abcd/efg");
check_joinbuf_overlapped("abcd", 1, "efg", "bcd/efg");
check_joinbuf_overlapped("abcd", 2, "efg", "cd/efg");
check_joinbuf_overlapped("abcd", 3, "efg", "d/efg");
check_joinbuf_overlapped("abcd", 4, "efg", "efg");
check_joinbuf_overlapped("abc/", 2, "efg", "c/efg");
check_joinbuf_overlapped("abc/", 3, "efg", "/efg");
check_joinbuf_overlapped("abc/", 4, "efg", "efg");
check_joinbuf_overlapped("abcd", 3, "", "d/");
check_joinbuf_overlapped("abcd", 4, "", "");
check_joinbuf_overlapped("abc/", 2, "", "c/");
check_joinbuf_overlapped("abc/", 3, "", "/");
check_joinbuf_overlapped("abc/", 4, "", "");
check_joinbuf_n_2("", "", "");
check_joinbuf_n_2("", "a", "a");
check_joinbuf_n_2("", "/a", "/a");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment