aboutsummaryrefslogtreecommitdiffstats
path: root/tests/check_content_parser.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/check_content_parser.c')
-rw-r--r--tests/check_content_parser.c412
1 files changed, 323 insertions, 89 deletions
diff --git a/tests/check_content_parser.c b/tests/check_content_parser.c
index ea3a9a2..0eaab70 100644
--- a/tests/check_content_parser.c
+++ b/tests/check_content_parser.c
@@ -81,6 +81,7 @@ static void
test_content_parse(void **state)
{
size_t l = 0;
+ char *d = NULL;
char *html = blogc_content_parse(
"# um\n"
"## dois\n"
@@ -122,9 +123,11 @@ test_content_parse(void **state)
"\n"
"-- asd\n"
"\n"
- "--- lol\n", &l);
+ "--- lol\n", &l, &d);
assert_non_null(html);
assert_int_equal(l, 0);
+ assert_non_null(d);
+ assert_string_equal(d, "bola");
assert_string_equal(html,
"<h1 id=\"um\">um</h1>\n"
"<h2 id=\"dois\">dois</h2>\n"
@@ -162,6 +165,7 @@ test_content_parse(void **state)
"<p>&ndash; asd</p>\n"
"<p>&mdash; lol</p>\n");
free(html);
+ free(d);
}
@@ -169,6 +173,7 @@ static void
test_content_parse_crlf(void **state)
{
size_t l = 0;
+ char *d = NULL;
char *html = blogc_content_parse(
"# um\r\n"
"## dois\r\n"
@@ -210,9 +215,11 @@ test_content_parse_crlf(void **state)
"\r\n"
"-- asd\r\n"
"\r\n"
- "--- lol\r\n", &l);
+ "--- lol\r\n", &l, &d);
assert_non_null(html);
assert_int_equal(l, 0);
+ assert_non_null(d);
+ assert_string_equal(d, "bola");
assert_string_equal(html,
"<h1 id=\"um\">um</h1>\r\n"
"<h2 id=\"dois\">dois</h2>\r\n"
@@ -250,6 +257,7 @@ test_content_parse_crlf(void **state)
"<p>&ndash; asd</p>\r\n"
"<p>&mdash; lol</p>\r\n");
free(html);
+ free(d);
}
@@ -257,6 +265,7 @@ static void
test_content_parse_with_excerpt(void **state)
{
size_t l = 0;
+ char *d = NULL;
char *html = blogc_content_parse(
"# test\n"
"\n"
@@ -265,9 +274,11 @@ test_content_parse_with_excerpt(void **state)
"..\n"
"\n"
"guda\n"
- "lol", &l);
+ "lol", &l, &d);
assert_non_null(html);
assert_int_equal(l, 38);
+ assert_non_null(d);
+ assert_string_equal(d, "chunda");
assert_string_equal(html,
"<h1 id=\"test\">test</h1>\n"
"<p>chunda</p>\n"
@@ -275,6 +286,8 @@ test_content_parse_with_excerpt(void **state)
"lol</p>\n");
free(html);
l = 0;
+ free(d);
+ d = NULL;
html = blogc_content_parse(
"# test\n"
"\n"
@@ -283,15 +296,18 @@ test_content_parse_with_excerpt(void **state)
"...\n"
"\n"
"guda\n"
- "lol", &l);
+ "lol", &l, &d);
assert_non_null(html);
assert_int_equal(l, 38);
+ assert_non_null(d);
+ assert_string_equal(d, "chunda");
assert_string_equal(html,
"<h1 id=\"test\">test</h1>\n"
"<p>chunda</p>\n"
"<p>guda\n"
"lol</p>\n");
free(html);
+ free(d);
}
@@ -299,6 +315,7 @@ static void
test_content_parse_with_excerpt_crlf(void **state)
{
size_t l = 0;
+ char *d = NULL;
char *html = blogc_content_parse(
"# test\r\n"
"\r\n"
@@ -307,9 +324,11 @@ test_content_parse_with_excerpt_crlf(void **state)
"..\r\n"
"\r\n"
"guda\r\n"
- "lol", &l);
+ "lol", &l, &d);
assert_non_null(html);
assert_int_equal(l, 40);
+ assert_non_null(d);
+ assert_string_equal(d, "chunda");
assert_string_equal(html,
"<h1 id=\"test\">test</h1>\r\n"
"<p>chunda</p>\r\n"
@@ -317,6 +336,8 @@ test_content_parse_with_excerpt_crlf(void **state)
"lol</p>\r\n");
free(html);
l = 0;
+ free(d);
+ d = NULL;
html = blogc_content_parse(
"# test\r\n"
"\r\n"
@@ -325,26 +346,29 @@ test_content_parse_with_excerpt_crlf(void **state)
"...\r\n"
"\r\n"
"guda\r\n"
- "lol", &l);
+ "lol", &l, &d);
assert_non_null(html);
assert_int_equal(l, 40);
+ assert_non_null(d);
+ assert_string_equal(d, "chunda");
assert_string_equal(html,
"<h1 id=\"test\">test</h1>\r\n"
"<p>chunda</p>\r\n"
"<p>guda\r\n"
"lol</p>\r\n");
free(html);
+ free(d);
}
static void
test_content_parse_header(void **state)
{
- char *html = blogc_content_parse("## bola", NULL);
+ char *html = blogc_content_parse("## bola", NULL, NULL);
assert_non_null(html);
assert_string_equal(html, "<h2 id=\"bola\">bola</h2>\n");
free(html);
- html = blogc_content_parse("## bola\n", NULL);
+ html = blogc_content_parse("## bola\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html, "<h2 id=\"bola\">bola</h2>\n");
free(html);
@@ -353,7 +377,7 @@ test_content_parse_header(void **state)
"\n"
"## bola\n"
"\n"
- "guda\n", NULL);
+ "guda\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>bola</p>\n"
@@ -366,11 +390,11 @@ test_content_parse_header(void **state)
static void
test_content_parse_header_crlf(void **state)
{
- char *html = blogc_content_parse("## bola", NULL);
+ char *html = blogc_content_parse("## bola", NULL, NULL);
assert_non_null(html);
assert_string_equal(html, "<h2 id=\"bola\">bola</h2>\n");
free(html);
- html = blogc_content_parse("## bola\r\n", NULL);
+ html = blogc_content_parse("## bola\r\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html, "<h2 id=\"bola\">bola</h2>\r\n");
free(html);
@@ -379,7 +403,7 @@ test_content_parse_header_crlf(void **state)
"\r\n"
"## bola\r\n"
"\r\n"
- "guda\r\n", NULL);
+ "guda\r\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>bola</p>\r\n"
@@ -392,11 +416,11 @@ test_content_parse_header_crlf(void **state)
static void
test_content_parse_html(void **state)
{
- char *html = blogc_content_parse("<div>\n</div>", NULL);
+ char *html = blogc_content_parse("<div>\n</div>", NULL, NULL);
assert_non_null(html);
assert_string_equal(html, "<div>\n</div>\n");
free(html);
- html = blogc_content_parse("<div>\n</div>\n", NULL);
+ html = blogc_content_parse("<div>\n</div>\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html, "<div>\n</div>\n");
free(html);
@@ -406,7 +430,7 @@ test_content_parse_html(void **state)
"<div>\n"
"</div>\n"
"\n"
- "chunda\n", NULL);
+ "chunda\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>bola</p>\n"
@@ -419,11 +443,11 @@ test_content_parse_html(void **state)
static void
test_content_parse_html_crlf(void **state)
{
- char *html = blogc_content_parse("<div>\r\n</div>", NULL);
+ char *html = blogc_content_parse("<div>\r\n</div>", NULL, NULL);
assert_non_null(html);
assert_string_equal(html, "<div>\r\n</div>\r\n");
free(html);
- html = blogc_content_parse("<div>\r\n</div>\r\n", NULL);
+ html = blogc_content_parse("<div>\r\n</div>\r\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html, "<div>\r\n</div>\r\n");
free(html);
@@ -433,7 +457,7 @@ test_content_parse_html_crlf(void **state)
"<div>\r\n"
"</div>\r\n"
"\r\n"
- "chunda\r\n", NULL);
+ "chunda\r\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>bola</p>\r\n"
@@ -446,14 +470,14 @@ test_content_parse_html_crlf(void **state)
static void
test_content_parse_blockquote(void **state)
{
- char *html = blogc_content_parse("> bola\n> guda", NULL);
+ char *html = blogc_content_parse("> bola\n> guda", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<blockquote><p>bola\n"
"guda</p>\n"
"</blockquote>\n");
free(html);
- html = blogc_content_parse("> bola\n> guda\n", NULL);
+ html = blogc_content_parse("> bola\n> guda\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<blockquote><p>bola\n"
@@ -464,9 +488,22 @@ test_content_parse_blockquote(void **state)
"bola\n"
"\n"
"> bola\n"
+ "\n"
+ "chunda\n", NULL, NULL);
+ assert_non_null(html);
+ assert_string_equal(html,
+ "<p>bola</p>\n"
+ "<blockquote><p>bola</p>\n"
+ "</blockquote>\n"
+ "<p>chunda</p>\n");
+ free(html);
+ html = blogc_content_parse(
+ "bola\n"
+ "\n"
+ "> bola\n"
"> guda\n"
"\n"
- "chunda\n", NULL);
+ "chunda\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>bola</p>\n"
@@ -481,14 +518,14 @@ test_content_parse_blockquote(void **state)
static void
test_content_parse_blockquote_crlf(void **state)
{
- char *html = blogc_content_parse("> bola\r\n> guda", NULL);
+ char *html = blogc_content_parse("> bola\r\n> guda", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<blockquote><p>bola\r\n"
"guda</p>\r\n"
"</blockquote>\r\n");
free(html);
- html = blogc_content_parse("> bola\r\n> guda\r\n", NULL);
+ html = blogc_content_parse("> bola\r\n> guda\r\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<blockquote><p>bola\r\n"
@@ -499,9 +536,22 @@ test_content_parse_blockquote_crlf(void **state)
"bola\r\n"
"\r\n"
"> bola\r\n"
+ "\r\n"
+ "chunda\r\n", NULL, NULL);
+ assert_non_null(html);
+ assert_string_equal(html,
+ "<p>bola</p>\r\n"
+ "<blockquote><p>bola</p>\r\n"
+ "</blockquote>\r\n"
+ "<p>chunda</p>\r\n");
+ free(html);
+ html = blogc_content_parse(
+ "bola\r\n"
+ "\r\n"
+ "> bola\r\n"
"> guda\r\n"
"\r\n"
- "chunda\r\n", NULL);
+ "chunda\r\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>bola</p>\r\n"
@@ -516,13 +566,13 @@ test_content_parse_blockquote_crlf(void **state)
static void
test_content_parse_code(void **state)
{
- char *html = blogc_content_parse(" bola\n guda", NULL);
+ char *html = blogc_content_parse(" bola\n guda", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<pre><code>bola\n"
"guda</code></pre>\n");
free(html);
- html = blogc_content_parse(" bola\n guda\n", NULL);
+ html = blogc_content_parse(" bola\n guda\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<pre><code>bola\n"
@@ -534,7 +584,7 @@ test_content_parse_code(void **state)
" bola\n"
" guda\n"
"\n"
- "chunda\n", NULL);
+ "chunda\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>bola</p>\n"
@@ -548,13 +598,13 @@ test_content_parse_code(void **state)
static void
test_content_parse_code_crlf(void **state)
{
- char *html = blogc_content_parse(" bola\r\n guda", NULL);
+ char *html = blogc_content_parse(" bola\r\n guda", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<pre><code>bola\r\n"
"guda</code></pre>\r\n");
free(html);
- html = blogc_content_parse(" bola\r\n guda\r\n", NULL);
+ html = blogc_content_parse(" bola\r\n guda\r\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<pre><code>bola\r\n"
@@ -566,7 +616,7 @@ test_content_parse_code_crlf(void **state)
" bola\r\n"
" guda\r\n"
"\r\n"
- "chunda\r\n", NULL);
+ "chunda\r\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>bola</p>\r\n"
@@ -580,28 +630,28 @@ test_content_parse_code_crlf(void **state)
static void
test_content_parse_horizontal_rule(void **state)
{
- char *html = blogc_content_parse("bola\nguda\n\n**", NULL);
+ char *html = blogc_content_parse("bola\nguda\n\n**", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>bola\n"
"guda</p>\n"
"<hr />\n");
free(html);
- html = blogc_content_parse("bola\nguda\n\n++++", NULL);
+ html = blogc_content_parse("bola\nguda\n\n++++", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>bola\n"
"guda</p>\n"
"<hr />\n");
free(html);
- html = blogc_content_parse("bola\nguda\n\n--\n", NULL);
+ html = blogc_content_parse("bola\nguda\n\n--\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>bola\n"
"guda</p>\n"
"<hr />\n");
free(html);
- html = blogc_content_parse("bola\nguda\n\n****\n", NULL);
+ html = blogc_content_parse("bola\nguda\n\n****\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>bola\n"
@@ -613,7 +663,7 @@ test_content_parse_horizontal_rule(void **state)
"\n"
"**\n"
"\n"
- "chunda\n", NULL);
+ "chunda\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>bola</p>\n"
@@ -625,7 +675,7 @@ test_content_parse_horizontal_rule(void **state)
"\n"
"----\n"
"\n"
- "chunda\n", NULL);
+ "chunda\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>bola</p>\n"
@@ -638,28 +688,28 @@ test_content_parse_horizontal_rule(void **state)
static void
test_content_parse_horizontal_rule_crlf(void **state)
{
- char *html = blogc_content_parse("bola\r\nguda\r\n\r\n**", NULL);
+ char *html = blogc_content_parse("bola\r\nguda\r\n\r\n**", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>bola\r\n"
"guda</p>\r\n"
"<hr />\r\n");
free(html);
- html = blogc_content_parse("bola\r\nguda\r\n\r\n++++", NULL);
+ html = blogc_content_parse("bola\r\nguda\r\n\r\n++++", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>bola\r\n"
"guda</p>\r\n"
"<hr />\r\n");
free(html);
- html = blogc_content_parse("bola\r\nguda\r\n\r\n--\r\n", NULL);
+ html = blogc_content_parse("bola\r\nguda\r\n\r\n--\r\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>bola\r\n"
"guda</p>\r\n"
"<hr />\r\n");
free(html);
- html = blogc_content_parse("bola\r\nguda\r\n\r\n****\r\n", NULL);
+ html = blogc_content_parse("bola\r\nguda\r\n\r\n****\r\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>bola\r\n"
@@ -671,7 +721,7 @@ test_content_parse_horizontal_rule_crlf(void **state)
"\r\n"
"**\r\n"
"\r\n"
- "chunda\r\n", NULL);
+ "chunda\r\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>bola</p>\r\n"
@@ -683,7 +733,7 @@ test_content_parse_horizontal_rule_crlf(void **state)
"\r\n"
"----\r\n"
"\r\n"
- "chunda\r\n", NULL);
+ "chunda\r\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>bola</p>\r\n"
@@ -701,7 +751,7 @@ test_content_parse_unordered_list(void **state)
"\n"
"* asd\n"
"* qwe\n"
- "* zxc", NULL);
+ "* zxc", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>lol</p>\n"
@@ -716,7 +766,7 @@ test_content_parse_unordered_list(void **state)
"\n"
"* asd\n"
"* qwe\n"
- "* zxc\n", NULL);
+ "* zxc\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>lol</p>\n"
@@ -733,7 +783,7 @@ test_content_parse_unordered_list(void **state)
"* qwe\n"
"* zxc\n"
"\n"
- "fuuuu\n", NULL);
+ "fuuuu\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>lol</p>\n"
@@ -753,7 +803,7 @@ test_content_parse_unordered_list(void **state)
"* zxc\n"
" 1234\n"
"\n"
- "fuuuu\n", NULL);
+ "fuuuu\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>lol</p>\n"
@@ -769,7 +819,7 @@ test_content_parse_unordered_list(void **state)
html = blogc_content_parse(
"* asd\n"
"* qwe\n"
- "* zxc", NULL);
+ "* zxc", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<ul>\n"
@@ -789,7 +839,7 @@ test_content_parse_unordered_list_crlf(void **state)
"\r\n"
"* asd\r\n"
"* qwe\r\n"
- "* zxc", NULL);
+ "* zxc", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>lol</p>\r\n"
@@ -804,7 +854,7 @@ test_content_parse_unordered_list_crlf(void **state)
"\r\n"
"* asd\r\n"
"* qwe\r\n"
- "* zxc\r\n", NULL);
+ "* zxc\r\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>lol</p>\r\n"
@@ -821,7 +871,7 @@ test_content_parse_unordered_list_crlf(void **state)
"* qwe\r\n"
"* zxc\r\n"
"\r\n"
- "fuuuu\r\n", NULL);
+ "fuuuu\r\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>lol</p>\r\n"
@@ -841,7 +891,7 @@ test_content_parse_unordered_list_crlf(void **state)
"* zxc\r\n"
" 1234\r\n"
"\r\n"
- "fuuuu\r\n", NULL);
+ "fuuuu\r\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>lol</p>\r\n"
@@ -857,7 +907,7 @@ test_content_parse_unordered_list_crlf(void **state)
html = blogc_content_parse(
"* asd\r\n"
"* qwe\r\n"
- "* zxc", NULL);
+ "* zxc", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<ul>\r\n"
@@ -877,7 +927,7 @@ test_content_parse_ordered_list(void **state)
"\n"
"1. asd\n"
"2. qwe\n"
- "3. zxc", NULL);
+ "3. zxc", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>lol</p>\n"
@@ -892,7 +942,7 @@ test_content_parse_ordered_list(void **state)
"\n"
"1. asd\n"
"2. qwe\n"
- "3. zxc\n", NULL);
+ "3. zxc\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>lol</p>\n"
@@ -909,7 +959,7 @@ test_content_parse_ordered_list(void **state)
"2. qwe\n"
"3. zxc\n"
"\n"
- "fuuuu\n", NULL);
+ "fuuuu\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>lol</p>\n"
@@ -929,7 +979,7 @@ test_content_parse_ordered_list(void **state)
"3. zxc\n"
" 1234\n"
"\n"
- "fuuuu\n", NULL);
+ "fuuuu\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>lol</p>\n"
@@ -945,7 +995,7 @@ test_content_parse_ordered_list(void **state)
html = blogc_content_parse(
"1. asd\n"
"2. qwe\n"
- "3. zxc", NULL);
+ "3. zxc", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<ol>\n"
@@ -965,7 +1015,7 @@ test_content_parse_ordered_list_crlf(void **state)
"\r\n"
"1. asd\r\n"
"2. qwe\r\n"
- "3. zxc", NULL);
+ "3. zxc", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>lol</p>\r\n"
@@ -980,7 +1030,7 @@ test_content_parse_ordered_list_crlf(void **state)
"\r\n"
"1. asd\r\n"
"2. qwe\r\n"
- "3. zxc\r\n", NULL);
+ "3. zxc\r\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>lol</p>\r\n"
@@ -997,7 +1047,7 @@ test_content_parse_ordered_list_crlf(void **state)
"2. qwe\r\n"
"3. zxc\r\n"
"\r\n"
- "fuuuu\r\n", NULL);
+ "fuuuu\r\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>lol</p>\r\n"
@@ -1017,7 +1067,7 @@ test_content_parse_ordered_list_crlf(void **state)
"3. zxc\r\n"
" 1234\r\n"
"\r\n"
- "fuuuu\r\n", NULL);
+ "fuuuu\r\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>lol</p>\r\n"
@@ -1033,7 +1083,7 @@ test_content_parse_ordered_list_crlf(void **state)
html = blogc_content_parse(
"1. asd\r\n"
"2. qwe\r\n"
- "3. zxc", NULL);
+ "3. zxc", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<ol>\r\n"
@@ -1046,9 +1096,176 @@ test_content_parse_ordered_list_crlf(void **state)
static void
+test_content_parse_description(void **state)
+{
+ char *d = NULL;
+ char *html = blogc_content_parse(
+ "# foo\n"
+ "\n"
+ "bar", NULL, &d);
+ assert_non_null(html);
+ assert_string_equal(html,
+ "<h1 id=\"foo\">foo</h1>\n"
+ "<p>bar</p>\n");
+ assert_non_null(d);
+ assert_string_equal(d, "bar");
+ free(html);
+ free(d);
+ d = NULL;
+ html = blogc_content_parse(
+ "# foo\n"
+ "\n"
+ "bar\n", NULL, &d);
+ assert_non_null(html);
+ assert_string_equal(html,
+ "<h1 id=\"foo\">foo</h1>\n"
+ "<p>bar</p>\n");
+ assert_non_null(d);
+ assert_string_equal(d, "bar");
+ free(html);
+ free(d);
+ d = NULL;
+ html = blogc_content_parse(
+ "# foo\n"
+ "\n"
+ "qwe\n"
+ "bar\n", NULL, &d);
+ assert_non_null(html);
+ assert_string_equal(html,
+ "<h1 id=\"foo\">foo</h1>\n"
+ "<p>qwe\n"
+ "bar</p>\n");
+ assert_non_null(d);
+ assert_string_equal(d, "qwe");
+ free(html);
+ free(d);
+ d = NULL;
+ html = blogc_content_parse(
+ "# foo\n"
+ "\n"
+ "> qwe\n"
+ "\n"
+ "bar\n", NULL, &d);
+ assert_non_null(html);
+ assert_string_equal(html,
+ "<h1 id=\"foo\">foo</h1>\n"
+ "<blockquote><p>qwe</p>\n"
+ "</blockquote>\n"
+ "<p>bar</p>\n");
+ assert_non_null(d);
+ assert_string_equal(d, "qwe");
+ free(html);
+ free(d);
+ d = NULL;
+ html = blogc_content_parse(
+ "# foo\n"
+ "\n"
+ "> qwe\n"
+ "> zxc\n"
+ "\n"
+ "bar\n", NULL, &d);
+ assert_non_null(html);
+ assert_string_equal(html,
+ "<h1 id=\"foo\">foo</h1>\n"
+ "<blockquote><p>qwe\n"
+ "zxc</p>\n"
+ "</blockquote>\n"
+ "<p>bar</p>\n");
+ assert_non_null(d);
+ assert_string_equal(d, "qwe");
+ free(html);
+ free(d);
+}
+
+
+static void
+test_content_parse_description_crlf(void **state)
+{
+ char *d = NULL;
+ char *html = blogc_content_parse(
+ "# foo\r\n"
+ "\r\n"
+ "bar", NULL, &d);
+ assert_non_null(html);
+ assert_string_equal(html,
+ "<h1 id=\"foo\">foo</h1>\r\n"
+ "<p>bar</p>\r\n");
+ assert_non_null(d);
+ assert_string_equal(d, "bar");
+ free(html);
+ free(d);
+ d = NULL;
+ html = blogc_content_parse(
+ "# foo\r\n"
+ "\r\n"
+ "bar\r\n", NULL, &d);
+ assert_non_null(html);
+ assert_string_equal(html,
+ "<h1 id=\"foo\">foo</h1>\r\n"
+ "<p>bar</p>\r\n");
+ assert_non_null(d);
+ assert_string_equal(d, "bar");
+ free(html);
+ free(d);
+ d = NULL;
+ html = blogc_content_parse(
+ "# foo\r\n"
+ "\r\n"
+ "qwe\r\n"
+ "bar\r\n", NULL, &d);
+ assert_non_null(html);
+ assert_string_equal(html,
+ "<h1 id=\"foo\">foo</h1>\r\n"
+ "<p>qwe\r\n"
+ "bar</p>\r\n");
+ assert_non_null(d);
+ assert_string_equal(d, "qwe");
+ free(html);
+ free(d);
+ d = NULL;
+ html = blogc_content_parse(
+ "# foo\r\n"
+ "\r\n"
+ "> qwe\r\n"
+ "\r\n"
+ "bar\r\n", NULL, &d);
+ assert_non_null(html);
+ assert_string_equal(html,
+ "<h1 id=\"foo\">foo</h1>\r\n"
+ "<blockquote><p>qwe</p>\r\n"
+ "</blockquote>\r\n"
+ "<p>bar</p>\r\n");
+ assert_non_null(d);
+ assert_string_equal(d, "qwe");
+ free(html);
+ free(d);
+ d = NULL;
+ html = blogc_content_parse(
+ "# foo\r\n"
+ "\r\n"
+ "> qwe\r\n"
+ "> zxc\r\n"
+ "\r\n"
+ "bar\r\n", NULL, &d);
+ assert_non_null(html);
+ assert_string_equal(html,
+ "<h1 id=\"foo\">foo</h1>\r\n"
+ "<blockquote><p>qwe\r\n"
+ "zxc</p>\r\n"
+ "</blockquote>\r\n"
+ "<p>bar</p>\r\n");
+ assert_non_null(d);
+ assert_string_equal(d, "qwe");
+ free(html);
+ free(d);
+}
+
+
+static void
test_content_parse_invalid_excerpt(void **state)
{
size_t l = 0;
+ char *d = NULL;
char *html = blogc_content_parse(
"# test\n"
"\n"
@@ -1056,9 +1273,11 @@ test_content_parse_invalid_excerpt(void **state)
"..\n"
"\n"
"guda\n"
- "lol", &l);
+ "lol", &l, &d);
assert_non_null(html);
assert_int_equal(l, 0);
+ assert_non_null(d);
+ assert_string_equal(d, "chunda");
assert_string_equal(html,
"<h1 id=\"test\">test</h1>\n"
"<p>chunda\n"
@@ -1067,6 +1286,8 @@ test_content_parse_invalid_excerpt(void **state)
"lol</p>\n");
free(html);
l = 0;
+ free(d);
+ d = NULL;
html = blogc_content_parse(
"# test\n"
"\n"
@@ -1074,9 +1295,11 @@ test_content_parse_invalid_excerpt(void **state)
"\n"
"...\n"
"guda\n"
- "lol", &l);
+ "lol", &l, &d);
assert_non_null(html);
assert_int_equal(l, 0);
+ assert_non_null(d);
+ assert_string_equal(d, "chunda");
assert_string_equal(html,
"<h1 id=\"test\">test</h1>\n"
"<p>chunda</p>\n"
@@ -1085,15 +1308,19 @@ test_content_parse_invalid_excerpt(void **state)
"lol</p>\n");
free(html);
l = 0;
+ free(d);
+ d = NULL;
html = blogc_content_parse(
"# test\n"
"\n"
"chunda..\n"
"\n"
"guda\n"
- "lol", &l);
+ "lol", &l, &d);
assert_non_null(html);
assert_int_equal(l, 0);
+ assert_non_null(d);
+ assert_string_equal(d, "chunda..");
assert_string_equal(html,
"<h1 id=\"test\">test</h1>\n"
"<p>chunda..</p>\n"
@@ -1101,21 +1328,26 @@ test_content_parse_invalid_excerpt(void **state)
"lol</p>\n");
free(html);
l = 0;
+ free(d);
+ d = NULL;
html = blogc_content_parse(
"# test\n"
"\n"
"chunda\n"
"\n"
"...guda\n"
- "lol", &l);
+ "lol", &l, &d);
assert_non_null(html);
assert_int_equal(l, 0);
+ assert_non_null(d);
+ assert_string_equal(d, "chunda");
assert_string_equal(html,
"<h1 id=\"test\">test</h1>\n"
"<p>chunda</p>\n"
"<p>...guda\n"
"lol</p>\n");
free(html);
+ free(d);
}
@@ -1125,7 +1357,7 @@ test_content_parse_invalid_header(void **state)
char *html = blogc_content_parse(
"asd\n"
"\n"
- "##bola\n", NULL);
+ "##bola\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>asd</p>\n"
@@ -1142,7 +1374,7 @@ test_content_parse_invalid_header_empty(void **state)
"\n"
"##\n"
"\n"
- "qwe\n", NULL);
+ "qwe\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>asd</p>\n"
@@ -1159,7 +1391,7 @@ test_content_parse_invalid_blockquote(void **state)
char *html = blogc_content_parse(
"> asd\n"
"> bola\n"
- "> foo\n", NULL);
+ "> foo\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>&gt; asd\n"
@@ -1168,7 +1400,7 @@ test_content_parse_invalid_blockquote(void **state)
free(html);
html = blogc_content_parse(
"> asd\n"
- "> bola", NULL);
+ "> bola", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>&gt; asd\n"
@@ -1183,7 +1415,7 @@ test_content_parse_invalid_code(void **state)
char *html = blogc_content_parse(
" asd\n"
" bola\n"
- " foo\n", NULL);
+ " foo\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p> asd\n"
@@ -1193,7 +1425,7 @@ test_content_parse_invalid_code(void **state)
html = blogc_content_parse(
" asd\n"
" bola\n"
- " foo", NULL);
+ " foo", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p> asd\n"
@@ -1207,11 +1439,11 @@ static void
test_content_parse_invalid_horizontal_rule(void **state)
{
// this generates invalid html, but...
- char *html = blogc_content_parse("** asd", NULL);
+ char *html = blogc_content_parse("** asd", NULL, NULL);
assert_non_null(html);
assert_string_equal(html, "<p><strong> asd</p>\n");
free(html);
- html = blogc_content_parse("** asd\n", NULL);
+ html = blogc_content_parse("** asd\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html, "<p><strong> asd</p>\n");
free(html);
@@ -1224,7 +1456,7 @@ test_content_parse_invalid_unordered_list(void **state)
// more invalid html
char *html = blogc_content_parse(
"* asd\n"
- "1. qwe", NULL);
+ "1. qwe", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p><em> asd\n"
@@ -1233,7 +1465,7 @@ test_content_parse_invalid_unordered_list(void **state)
html = blogc_content_parse(
"* asd\n"
"1. qwe\n"
- "\n", NULL);
+ "\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p><em> asd\n"
@@ -1241,7 +1473,7 @@ test_content_parse_invalid_unordered_list(void **state)
free(html);
html = blogc_content_parse(
"* asd\n"
- "1. qwe\n", NULL);
+ "1. qwe\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p><em> asd\n"
@@ -1250,7 +1482,7 @@ test_content_parse_invalid_unordered_list(void **state)
free(html);
html = blogc_content_parse(
"* asd\n"
- "1. qwe\n", NULL);
+ "1. qwe\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p><em> asd\n"
@@ -1263,7 +1495,7 @@ test_content_parse_invalid_unordered_list(void **state)
"* asd\n"
"1. qwe\n"
"\n"
- "poi\n", NULL);
+ "poi\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>chunda</p>\n"
@@ -1280,7 +1512,7 @@ test_content_parse_invalid_ordered_list(void **state)
// more invalid html
char *html = blogc_content_parse(
"1. asd\n"
- "* qwe", NULL);
+ "* qwe", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>1. asd\n"
@@ -1289,7 +1521,7 @@ test_content_parse_invalid_ordered_list(void **state)
html = blogc_content_parse(
"1. asd\n"
"* qwe\n"
- "\n", NULL);
+ "\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>1. asd\n"
@@ -1297,7 +1529,7 @@ test_content_parse_invalid_ordered_list(void **state)
free(html);
html = blogc_content_parse(
"1. asd\n"
- "* qwe\n", NULL);
+ "* qwe\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>1. asd\n"
@@ -1306,7 +1538,7 @@ test_content_parse_invalid_ordered_list(void **state)
free(html);
html = blogc_content_parse(
"1. asd\n"
- "* qwe\n", NULL);
+ "* qwe\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>1. asd\n"
@@ -1319,7 +1551,7 @@ test_content_parse_invalid_ordered_list(void **state)
"1. asd\n"
"* qwe\n"
"\n"
- "poi\n", NULL);
+ "poi\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>chunda</p>\n"
@@ -1329,7 +1561,7 @@ test_content_parse_invalid_ordered_list(void **state)
free(html);
html = blogc_content_parse(
"1 asd\n"
- "* qwe\n", NULL);
+ "* qwe\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>1 asd\n"
@@ -1337,7 +1569,7 @@ test_content_parse_invalid_ordered_list(void **state)
free(html);
html = blogc_content_parse(
"a. asd\n"
- "2. qwe\n", NULL);
+ "2. qwe\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>a. asd\n"
@@ -1345,18 +1577,18 @@ test_content_parse_invalid_ordered_list(void **state)
free(html);
html = blogc_content_parse(
"1.\nasd\n"
- "2. qwe\n", NULL);
+ "2. qwe\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>1.\n"
"asd\n"
"2. qwe</p>\n");
free(html);
- html = blogc_content_parse("1.\n", NULL);
+ html = blogc_content_parse("1.\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html, "<p>1.</p>\n");
free(html);
- html = blogc_content_parse("1 ", NULL);
+ html = blogc_content_parse("1 ", NULL, NULL);
assert_non_null(html);
assert_string_equal(html, "<p>1 </p>\n");
free(html);
@@ -1806,6 +2038,8 @@ main(void)
unit_test(test_content_parse_unordered_list_crlf),
unit_test(test_content_parse_ordered_list),
unit_test(test_content_parse_ordered_list_crlf),
+ unit_test(test_content_parse_description),
+ unit_test(test_content_parse_description_crlf),
unit_test(test_content_parse_invalid_excerpt),
unit_test(test_content_parse_invalid_header),
unit_test(test_content_parse_invalid_header_empty),