diff --git a/src/notification.h b/src/notification.h
index ccf2b47..d6b012a 100644
--- a/src/notification.h
+++ b/src/notification.h
@@ -67,6 +67,7 @@ int notification_close(notification * n, int reason);
void notification_print(notification * n);
char *notification_strip_markup(char *str);
char *notification_quote_markup(char *str);
+char *notification_replace_format(const char *needle, const char *replacement, char *haystack, enum markup_mode markup);
void notification_update_text_to_render(notification *n);
int notification_get_ttl(notification *n);
int notification_get_age(notification *n);
diff --git a/test/notification.c b/test/notification.c
index 6fcdcc5..5bc3634 100644
--- a/test/notification.c
+++ b/test/notification.c
@@ -32,7 +32,7 @@ TEST test_notification_is_duplicate(void *notifications)
ASSERT(notification_is_duplicate(a, b));
char *tmp = b->icon;
- enum icon_position_t icon_tmp = settings.icon_position;
+ enum icon_position_t icon_setting_tmp = settings.icon_position;
b->icon = "Test1";
@@ -56,7 +56,7 @@ TEST test_notification_is_duplicate(void *notifications)
b->raw_icon = NULL;
b->icon = tmp;
- settings.icon_position = icon_tmp;
+ settings.icon_position = icon_setting_tmp;
ASSERT(notification_is_duplicate(a, b));
@@ -70,6 +70,26 @@ TEST test_notification_is_duplicate(void *notifications)
PASS();
}
+TEST test_notification_replace_format(void)
+{
+ char *str = g_malloc(128 * sizeof(char));
+
+ strcpy(str, "Testing format replacement");
+ ASSERT_STR_EQ("Testing text replacement", (str = notification_replace_format("format", "text", str, MARKUP_FULL)));
+
+ strcpy(str, "Markup %a preserved");
+ ASSERT_STR_EQ("Markup and & is preserved", (str = notification_replace_format("%a", "and & is", str, MARKUP_FULL)));
+
+ strcpy(str, "Markup %a escaped");
+ ASSERT_STR_EQ("Markup and & <i>is</i> escaped", (str = notification_replace_format("%a", "and & is", str, MARKUP_NO)));
+
+ strcpy(str, "Markup %a");
+ ASSERT_STR_EQ("Markup is removed and & escaped", (str = notification_replace_format("%a", "is removed and & escaped", str, MARKUP_STRIP)));
+
+ g_free(str);
+ PASS();
+}
+
SUITE(suite_notification)
{
cmdline_load(0, NULL);
@@ -89,6 +109,10 @@ SUITE(suite_notification)
notification *n[2] = {a, b};
RUN_TEST1(test_notification_is_duplicate, (void*) n);
+ g_free(a);
+ g_free(b);
+
+ RUN_TEST(test_notification_replace_format);
}
/* vim: set tabstop=8 shiftwidth=8 expandtab textwidth=0: */