Add tests for markup functions

This commit is contained in:
Luke Shumaker 2017-03-09 14:25:33 -05:00
parent 0c84e53afb
commit c645ba3106
2 changed files with 59 additions and 0 deletions

57
test/markup.c Normal file
View File

@ -0,0 +1,57 @@
#include "greatest.h"
#include <stdbool.h>
#include <glib.h>
#include "src/markup.h"
TEST test_markup_strip(void)
{
char *ptr;
ASSERT_STR_EQ("&quot;", (ptr=markup_strip(g_strdup("&amp;quot;"))));
g_free(ptr);
ASSERT_STR_EQ("&apos;", (ptr=markup_strip(g_strdup("&amp;apos;"))));
g_free(ptr);
ASSERT_STR_EQ("&lt;", (ptr=markup_strip(g_strdup("&amp;lt;"))));
g_free(ptr);
ASSERT_STR_EQ("&gt;", (ptr=markup_strip(g_strdup("&amp;gt;"))));
g_free(ptr);
ASSERT_STR_EQ("&amp;", (ptr=markup_strip(g_strdup("&amp;amp;"))));
g_free(ptr);
ASSERT_STR_EQ(">A ", (ptr=markup_strip(g_strdup(">A <img> <string"))));
g_free(ptr);
PASS();
}
TEST test_markup_transform(void)
{
char *ptr;
settings.ignore_newline = false;
ASSERT_STR_EQ("&lt;i&gt;foo&lt;/i&gt;&lt;br&gt;bar\nbaz", (ptr=markup_transform(g_strdup("<i>foo</i><br>bar\nbaz"), MARKUP_NO)));
g_free(ptr);
ASSERT_STR_EQ("foo\nbar\nbaz", (ptr=markup_transform(g_strdup("<i>foo</i><br>bar\nbaz"), MARKUP_STRIP)));
g_free(ptr);
ASSERT_STR_EQ("<i>foo</i>\nbar\nbaz", (ptr=markup_transform(g_strdup("<i>foo</i><br>bar\nbaz"), MARKUP_FULL)));
g_free(ptr);
settings.ignore_newline = true;
ASSERT_STR_EQ("&lt;i&gt;foo&lt;/i&gt;&lt;br&gt;bar baz", (ptr=markup_transform(g_strdup("<i>foo</i><br>bar\nbaz"), MARKUP_NO)));
g_free(ptr);
ASSERT_STR_EQ("foo bar baz", (ptr=markup_transform(g_strdup("<i>foo</i><br>bar\nbaz"), MARKUP_STRIP)));
g_free(ptr);
ASSERT_STR_EQ("<i>foo</i> bar baz", (ptr=markup_transform(g_strdup("<i>foo</i><br>bar\nbaz"), MARKUP_FULL)));
g_free(ptr);
PASS();
}
SUITE(suite_markup)
{
RUN_TEST(test_markup_strip);
RUN_TEST(test_markup_transform);
}
/* vim: set tabstop=8 shiftwidth=8 expandtab textwidth=0: */

View File

@ -3,6 +3,7 @@
SUITE_EXTERN(suite_utils); SUITE_EXTERN(suite_utils);
SUITE_EXTERN(suite_option_parser); SUITE_EXTERN(suite_option_parser);
SUITE_EXTERN(suite_notification); SUITE_EXTERN(suite_notification);
SUITE_EXTERN(suite_markup);
GREATEST_MAIN_DEFS(); GREATEST_MAIN_DEFS();
@ -11,6 +12,7 @@ int main(int argc, char *argv[]) {
RUN_SUITE(suite_utils); RUN_SUITE(suite_utils);
RUN_SUITE(suite_option_parser); RUN_SUITE(suite_option_parser);
RUN_SUITE(suite_notification); RUN_SUITE(suite_notification);
RUN_SUITE(suite_markup);
GREATEST_MAIN_END(); GREATEST_MAIN_END();
} }
/* vim: set tabstop=8 shiftwidth=8 expandtab textwidth=0: */ /* vim: set tabstop=8 shiftwidth=8 expandtab textwidth=0: */