Merge pull request #387 from bebehei/tests-for-string-append

Tests for string append
This commit is contained in:
Nikos Tsipinakis 2017-10-06 18:17:50 +03:00 committed by GitHub
commit 0a3298dde4
3 changed files with 36 additions and 10 deletions

View File

@ -522,14 +522,8 @@ int notification_init(notification *n, int id)
char *tmp = g_strconcat(n->summary, " ", n->body, NULL);
char *tmp_urls = extract_urls(tmp);
if (tmp_urls != NULL) {
if (n->urls != NULL) {
n->urls = string_append(n->urls, tmp_urls, "\n");
g_free(tmp_urls);
} else {
n->urls = tmp_urls;
}
}
n->urls = string_append(n->urls, tmp_urls, "\n");
g_free(tmp_urls);
if (n->actions) {
n->actions->dmenu_str = NULL;

View File

@ -76,8 +76,12 @@ char *string_replace_all(const char *needle, const char *replacement,
char *string_append(char *a, const char *b, const char *sep)
{
if (!a)
if (!a || *a == '\0') {
g_free(a);
return g_strdup(b);
}
if (!b || *b == '\0')
return a;
char *new;
if (!sep)

View File

@ -72,7 +72,35 @@ TEST test_string_replace(void)
TEST test_string_append(void)
{
SKIP(); //TODO: Implement this
char *exp;
ASSERT_STR_EQ("text_sep_bit", (exp = string_append(g_strdup("text"), "bit", "_sep_")));
g_free(exp);
ASSERT_STR_EQ("textbit", (exp = string_append(g_strdup("text"), "bit", NULL)));
g_free(exp);
ASSERT_STR_EQ("textbit", (exp = string_append(g_strdup("text"), "bit", "")));
g_free(exp);
ASSERT_STR_EQ("text", (exp = string_append(g_strdup("text"), "", NULL)));
g_free(exp);
ASSERT_STR_EQ("text", (exp = string_append(g_strdup("text"), "", "_sep_")));
g_free(exp);
ASSERT_STR_EQ("b", (exp = string_append(g_strdup(""), "b", NULL)));
g_free(exp);
ASSERT_STR_EQ("b", (exp = string_append(NULL, "b", "_sep_")));
g_free(exp);
ASSERT_STR_EQ("a", (exp = string_append(g_strdup("a"), "", NULL)));
g_free(exp);
ASSERT_STR_EQ("a", (exp = string_append(g_strdup("a"), NULL, "_sep_")));
g_free(exp);
ASSERT_STR_EQ("", (exp = string_append(g_strdup(""), "", "_sep_")));
g_free(exp);
ASSERT_EQ(NULL, (exp = string_append(NULL, NULL, "_sep_")));
g_free(exp);
PASS();
}