From 80017f034146b50fdc441c96636f1098adf7037e Mon Sep 17 00:00:00 2001
From: "Rafael G. Martins" – asd — lol – asd — lol%s
%s",
tmp, line_ending);
free(tmp);
diff --git a/src/blogc/content-parser.h b/src/blogc/content-parser.h
index 37e38d7..39230c6 100644
--- a/src/blogc/content-parser.h
+++ b/src/blogc/content-parser.h
@@ -17,7 +17,7 @@ char* blogc_htmlentities(const char *str);
char* blogc_fix_description(const char *paragraph);
char* blogc_content_parse_inline(const char *src);
bool blogc_is_ordered_list_item(const char *str, size_t prefix_len);
-char* blogc_content_parse(const char *src, size_t *end_excerpt,
+char* blogc_content_parse(const char *src, size_t *end_excerpt, char **title,
char **description);
#endif /* _CONTENT_PARSER_H */
diff --git a/src/blogc/source-parser.c b/src/blogc/source-parser.c
index a3d1e09..f6f3471 100644
--- a/src/blogc/source-parser.c
+++ b/src/blogc/source-parser.c
@@ -150,8 +150,21 @@ blogc_source_parse(const char *src, size_t src_len, bc_error_t **err)
if (current == (src_len - 1)) {
tmp = bc_strndup(src + start, src_len - start);
bc_trie_insert(rv, "RAW_CONTENT", tmp);
+ char *title = NULL;
char *description = NULL;
- content = blogc_content_parse(tmp, &end_excerpt, &description);
+ content = blogc_content_parse(tmp, &end_excerpt, &title,
+ &description);
+ if (title != NULL) {
+ // do not override source-provided title.
+ if (NULL == bc_trie_lookup(rv, "TITLE")) {
+ // no need to free, because we are transfering memory
+ // ownership to the trie.
+ bc_trie_insert(rv, "TITLE", title);
+ }
+ else {
+ free(title);
+ }
+ }
if (description != NULL) {
// do not override source-provided description.
if (NULL == bc_trie_lookup(rv, "DESCRIPTION")) {
diff --git a/tests/blogc/check_content_parser.c b/tests/blogc/check_content_parser.c
index 6cc58ff..33e0c38 100644
--- a/tests/blogc/check_content_parser.c
+++ b/tests/blogc/check_content_parser.c
@@ -123,6 +123,7 @@ static void
test_content_parse(void **state)
{
size_t l = 0;
+ char *t = NULL;
char *d = NULL;
char *html = blogc_content_parse(
"# um\n"
@@ -165,9 +166,11 @@ test_content_parse(void **state)
"\n"
"-- asd\n"
"\n"
- "--- lol\n", &l, &d);
+ "--- lol\n", &l, &t, &d);
assert_non_null(html);
assert_int_equal(l, 0);
+ assert_non_null(t);
+ assert_string_equal(t, "um");
assert_non_null(d);
assert_string_equal(d, "bola chunda");
assert_string_equal(html,
@@ -207,6 +210,7 @@ test_content_parse(void **state)
"
guda\n" "lol
\n"); free(html); + free(t); free(d); } @@ -357,6 +373,7 @@ static void test_content_parse_with_excerpt_crlf(void **state) { size_t l = 0; + char *t = NULL; char *d = NULL; char *html = blogc_content_parse( "# test\r\n" @@ -366,9 +383,11 @@ test_content_parse_with_excerpt_crlf(void **state) "..\r\n" "\r\n" "guda\r\n" - "lol", &l, &d); + "lol", &l, &t, &d); assert_non_null(html); assert_int_equal(l, 40); + assert_non_null(t); + assert_string_equal(t, "test"); assert_non_null(d); assert_string_equal(d, "chunda"); assert_string_equal(html, @@ -378,7 +397,9 @@ test_content_parse_with_excerpt_crlf(void **state) "lol\r\n"); free(html); l = 0; + free(t); free(d); + t = NULL; d = NULL; html = blogc_content_parse( "# test\r\n" @@ -388,9 +409,11 @@ test_content_parse_with_excerpt_crlf(void **state) "...\r\n" "\r\n" "guda\r\n" - "lol", &l, &d); + "lol", &l, &t, &d); assert_non_null(html); assert_int_equal(l, 40); + assert_non_null(t); + assert_string_equal(t, "test"); assert_non_null(d); assert_string_equal(d, "chunda"); assert_string_equal(html, @@ -399,6 +422,7 @@ test_content_parse_with_excerpt_crlf(void **state) "guda\r\n" "lol
\r\n"); free(html); + free(t); free(d); } @@ -406,11 +430,11 @@ test_content_parse_with_excerpt_crlf(void **state) static void test_content_parse_header(void **state) { - char *html = blogc_content_parse("## bola", NULL, NULL); + char *html = blogc_content_parse("## bola", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "bola
\n" @@ -432,11 +456,11 @@ test_content_parse_header(void **state) static void test_content_parse_header_crlf(void **state) { - char *html = blogc_content_parse("## bola", NULL, NULL); + char *html = blogc_content_parse("## bola", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "bola
\r\n" @@ -458,11 +482,11 @@ test_content_parse_header_crlf(void **state) static void test_content_parse_html(void **state) { - char *html = blogc_content_parse("bola
\n" @@ -485,11 +509,11 @@ test_content_parse_html(void **state) static void test_content_parse_html_crlf(void **state) { - char *html = blogc_content_parse("bola
\r\n" @@ -512,14 +536,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, NULL); + char *html = blogc_content_parse("> bola\n> guda", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "\n"); free(html); - html = blogc_content_parse("> bola\n> guda\n", NULL, NULL); + html = blogc_content_parse("> bola\n> guda\n", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "bola\n" "guda
\n" "
bola\n" @@ -531,7 +555,7 @@ test_content_parse_blockquote(void **state) "\n" "> bola\n" "\n" - "chunda\n", NULL, NULL); + "chunda\n", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "
bola
\n" @@ -545,7 +569,7 @@ test_content_parse_blockquote(void **state) "> bola\n" "> guda\n" "\n" - "chunda\n", NULL, NULL); + "chunda\n", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "bola
\n" @@ -560,14 +584,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, NULL); + char *html = blogc_content_parse("> bola\r\n> guda", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "\r\n"); free(html); - html = blogc_content_parse("> bola\r\n> guda\r\n", NULL, NULL); + html = blogc_content_parse("> bola\r\n> guda\r\n", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "bola\r\n" "guda
\r\n" "bola\r\n" @@ -579,7 +603,7 @@ test_content_parse_blockquote_crlf(void **state) "\r\n" "> bola\r\n" "\r\n" - "chunda\r\n", NULL, NULL); + "chunda\r\n", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "
bola
\r\n" @@ -593,7 +617,7 @@ test_content_parse_blockquote_crlf(void **state) "> bola\r\n" "> guda\r\n" "\r\n" - "chunda\r\n", NULL, NULL); + "chunda\r\n", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "bola
\r\n" @@ -608,13 +632,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, NULL); + char *html = blogc_content_parse(" bola\n guda", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "\n"); free(html); - html = blogc_content_parse(" bola\n guda\n", NULL, NULL); + html = blogc_content_parse(" bola\n guda\n", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "bola\n" "guda
bola\n" @@ -626,7 +650,7 @@ test_content_parse_code(void **state) " bola\n" " guda\n" "\n" - "chunda\n", NULL, NULL); + "chunda\n", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "
bola
\n" @@ -640,13 +664,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, NULL); + char *html = blogc_content_parse(" bola\r\n guda", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "\r\n"); free(html); - html = blogc_content_parse(" bola\r\n guda\r\n", NULL, NULL); + html = blogc_content_parse(" bola\r\n guda\r\n", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "bola\r\n" "guda
bola\r\n" @@ -658,7 +682,7 @@ test_content_parse_code_crlf(void **state) " bola\r\n" " guda\r\n" "\r\n" - "chunda\r\n", NULL, NULL); + "chunda\r\n", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "
bola
\r\n" @@ -672,28 +696,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, NULL); + char *html = blogc_content_parse("bola\nguda\n\n**", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "bola\n" "guda
\n" "
\n"); free(html); - html = blogc_content_parse("bola\nguda\n\n++++", NULL, NULL); + html = blogc_content_parse("bola\nguda\n\n++++", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "bola\n" "guda
\n" "
\n"); free(html); - html = blogc_content_parse("bola\nguda\n\n--\n", NULL, NULL); + html = blogc_content_parse("bola\nguda\n\n--\n", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "bola\n" "guda
\n" "
\n"); free(html); - html = blogc_content_parse("bola\nguda\n\n****\n", NULL, NULL); + html = blogc_content_parse("bola\nguda\n\n****\n", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "bola\n" @@ -705,7 +729,7 @@ test_content_parse_horizontal_rule(void **state) "\n" "**\n" "\n" - "chunda\n", NULL, NULL); + "chunda\n", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "
bola
\n" @@ -717,7 +741,7 @@ test_content_parse_horizontal_rule(void **state) "\n" "----\n" "\n" - "chunda\n", NULL, NULL); + "chunda\n", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "bola
\n" @@ -730,28 +754,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, NULL); + char *html = blogc_content_parse("bola\r\nguda\r\n\r\n**", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "bola\r\n" "guda
\r\n" "
\r\n"); free(html); - html = blogc_content_parse("bola\r\nguda\r\n\r\n++++", NULL, NULL); + html = blogc_content_parse("bola\r\nguda\r\n\r\n++++", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "bola\r\n" "guda
\r\n" "
\r\n"); free(html); - html = blogc_content_parse("bola\r\nguda\r\n\r\n--\r\n", NULL, NULL); + html = blogc_content_parse("bola\r\nguda\r\n\r\n--\r\n", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "bola\r\n" "guda
\r\n" "
\r\n"); free(html); - html = blogc_content_parse("bola\r\nguda\r\n\r\n****\r\n", NULL, NULL); + html = blogc_content_parse("bola\r\nguda\r\n\r\n****\r\n", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "bola\r\n" @@ -763,7 +787,7 @@ test_content_parse_horizontal_rule_crlf(void **state) "\r\n" "**\r\n" "\r\n" - "chunda\r\n", NULL, NULL); + "chunda\r\n", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "
bola
\r\n" @@ -775,7 +799,7 @@ test_content_parse_horizontal_rule_crlf(void **state) "\r\n" "----\r\n" "\r\n" - "chunda\r\n", NULL, NULL); + "chunda\r\n", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "bola
\r\n" @@ -793,7 +817,7 @@ test_content_parse_unordered_list(void **state) "\n" "* asd\n" "* qwe\n" - "* zxc", NULL, NULL); + "* zxc", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "lol
\n" @@ -808,7 +832,7 @@ test_content_parse_unordered_list(void **state) "\n" "* asd\n" "* qwe\n" - "* zxc\n", NULL, NULL); + "* zxc\n", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "lol
\n" @@ -825,7 +849,7 @@ test_content_parse_unordered_list(void **state) "* qwe\n" "* zxc\n" "\n" - "fuuuu\n", NULL, NULL); + "fuuuu\n", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "lol
\n" @@ -845,7 +869,7 @@ test_content_parse_unordered_list(void **state) "* zxc\n" " 1234\n" "\n" - "fuuuu\n", NULL, NULL); + "fuuuu\n", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "lol
\n" @@ -861,7 +885,7 @@ test_content_parse_unordered_list(void **state) html = blogc_content_parse( "* asd\n" "* qwe\n" - "* zxc", NULL, NULL); + "* zxc", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "\n" @@ -881,7 +905,7 @@ test_content_parse_unordered_list_crlf(void **state) "\r\n" "* asd\r\n" "* qwe\r\n" - "* zxc", NULL, NULL); + "* zxc", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "
lol
\r\n" @@ -896,7 +920,7 @@ test_content_parse_unordered_list_crlf(void **state) "\r\n" "* asd\r\n" "* qwe\r\n" - "* zxc\r\n", NULL, NULL); + "* zxc\r\n", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "lol
\r\n" @@ -913,7 +937,7 @@ test_content_parse_unordered_list_crlf(void **state) "* qwe\r\n" "* zxc\r\n" "\r\n" - "fuuuu\r\n", NULL, NULL); + "fuuuu\r\n", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "lol
\r\n" @@ -933,7 +957,7 @@ test_content_parse_unordered_list_crlf(void **state) "* zxc\r\n" " 1234\r\n" "\r\n" - "fuuuu\r\n", NULL, NULL); + "fuuuu\r\n", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "lol
\r\n" @@ -949,7 +973,7 @@ test_content_parse_unordered_list_crlf(void **state) html = blogc_content_parse( "* asd\r\n" "* qwe\r\n" - "* zxc", NULL, NULL); + "* zxc", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "\r\n" @@ -969,7 +993,7 @@ test_content_parse_ordered_list(void **state) "\n" "1. asd\n" "2. qwe\n" - "3. zxc", NULL, NULL); + "3. zxc", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "
lol
\n" @@ -984,7 +1008,7 @@ test_content_parse_ordered_list(void **state) "\n" "1. asd\n" "2. qwe\n" - "3. zxc\n", NULL, NULL); + "3. zxc\n", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "lol
\n" @@ -1001,7 +1025,7 @@ test_content_parse_ordered_list(void **state) "2. qwe\n" "3. zxc\n" "\n" - "fuuuu\n", NULL, NULL); + "fuuuu\n", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "lol
\n" @@ -1021,7 +1045,7 @@ test_content_parse_ordered_list(void **state) "3. zxc\n" " 1234\n" "\n" - "fuuuu\n", NULL, NULL); + "fuuuu\n", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "lol
\n" @@ -1037,7 +1061,7 @@ test_content_parse_ordered_list(void **state) html = blogc_content_parse( "1. asd\n" "2. qwe\n" - "3. zxc", NULL, NULL); + "3. zxc", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "\n" @@ -1057,7 +1081,7 @@ test_content_parse_ordered_list_crlf(void **state) "\r\n" "1. asd\r\n" "2. qwe\r\n" - "3. zxc", NULL, NULL); + "3. zxc", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "
lol
\r\n" @@ -1072,7 +1096,7 @@ test_content_parse_ordered_list_crlf(void **state) "\r\n" "1. asd\r\n" "2. qwe\r\n" - "3. zxc\r\n", NULL, NULL); + "3. zxc\r\n", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "lol
\r\n" @@ -1089,7 +1113,7 @@ test_content_parse_ordered_list_crlf(void **state) "2. qwe\r\n" "3. zxc\r\n" "\r\n" - "fuuuu\r\n", NULL, NULL); + "fuuuu\r\n", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "lol
\r\n" @@ -1109,7 +1133,7 @@ test_content_parse_ordered_list_crlf(void **state) "3. zxc\r\n" " 1234\r\n" "\r\n" - "fuuuu\r\n", NULL, NULL); + "fuuuu\r\n", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "lol
\r\n" @@ -1125,7 +1149,7 @@ test_content_parse_ordered_list_crlf(void **state) html = blogc_content_parse( "1. asd\r\n" "2. qwe\r\n" - "3. zxc", NULL, NULL); + "3. zxc", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "\r\n" @@ -1137,6 +1161,154 @@ test_content_parse_ordered_list_crlf(void **state) } +static void +test_content_parse_title(void **state) +{ + char *t = NULL; + char *html = blogc_content_parse("# foo", NULL, &t, NULL); + assert_non_null(html); + assert_string_equal(html, "
foo
\n"); + assert_non_null(t); + assert_string_equal(t, "foo"); + free(html); + free(t); + t = NULL; + html = blogc_content_parse("# foo\n", NULL, &t, NULL); + assert_non_null(html); + assert_string_equal(html, "foo
\n"); + assert_non_null(t); + assert_string_equal(t, "foo"); + free(html); + free(t); + t = NULL; + html = blogc_content_parse( + "# foo\n" + "## bar\n" + "### baz", NULL, &t, NULL); + assert_non_null(html); + assert_string_equal(html, + "foo
\n" + "bar
\n" + "baz
\n"); + assert_non_null(t); + assert_string_equal(t, "foo"); + free(html); + free(t); + t = NULL; + html = blogc_content_parse( + "# foo\n" + "## bar\n" + "### baz\n", NULL, &t, NULL); + assert_non_null(html); + assert_string_equal(html, + "foo
\n" + "bar
\n" + "baz
\n"); + assert_non_null(t); + assert_string_equal(t, "foo"); + free(html); + free(t); + t = NULL; + html = blogc_content_parse( + "## bar\n" + "# foo\n" + "### baz", NULL, &t, NULL); + assert_non_null(html); + assert_string_equal(html, + "bar
\n" + "foo
\n" + "baz
\n"); + assert_non_null(t); + assert_string_equal(t, "bar"); + free(html); + free(t); + t = NULL; + html = blogc_content_parse( + "## bar\n" + "# foo\n" + "### baz\n", NULL, &t, NULL); + assert_non_null(html); + assert_string_equal(html, + "bar
\n" + "foo
\n" + "baz
\n"); + assert_non_null(t); + assert_string_equal(t, "bar"); + free(html); + free(t); +} + + +static void +test_content_parse_title_crlf(void **state) +{ + char *t = NULL; + char *html = blogc_content_parse("# foo\r\n", NULL, &t, NULL); + assert_non_null(html); + assert_string_equal(html, "foo
\r\n"); + assert_non_null(t); + assert_string_equal(t, "foo"); + free(html); + free(t); + t = NULL; + html = blogc_content_parse( + "# foo\r\n" + "## bar\r\n" + "### baz", NULL, &t, NULL); + assert_non_null(html); + assert_string_equal(html, + "foo
\r\n" + "bar
\r\n" + "baz
\r\n"); + assert_non_null(t); + assert_string_equal(t, "foo"); + free(html); + free(t); + t = NULL; + html = blogc_content_parse( + "# foo\r\n" + "## bar\r\n" + "### baz\r\n", NULL, &t, NULL); + assert_non_null(html); + assert_string_equal(html, + "foo
\r\n" + "bar
\r\n" + "baz
\r\n"); + assert_non_null(t); + assert_string_equal(t, "foo"); + free(html); + free(t); + t = NULL; + html = blogc_content_parse( + "## bar\r\n" + "# foo\r\n" + "### baz", NULL, &t, NULL); + assert_non_null(html); + assert_string_equal(html, + "bar
\r\n" + "foo
\r\n" + "baz
\r\n"); + assert_non_null(t); + assert_string_equal(t, "bar"); + free(html); + free(t); + t = NULL; + html = blogc_content_parse( + "## bar\r\n" + "# foo\r\n" + "### baz\r\n", NULL, &t, NULL); + assert_non_null(html); + assert_string_equal(html, + "bar
\r\n" + "foo
\r\n" + "baz
\r\n"); + assert_non_null(t); + assert_string_equal(t, "bar"); + free(html); + free(t); +} + + static void test_content_parse_description(void **state) { @@ -1144,7 +1316,7 @@ test_content_parse_description(void **state) char *html = blogc_content_parse( "# foo\n" "\n" - "bar", NULL, &d); + "bar", NULL, NULL, &d); assert_non_null(html); assert_string_equal(html, "foo
\n" @@ -1157,7 +1329,7 @@ test_content_parse_description(void **state) html = blogc_content_parse( "# foo\n" "\n" - "bar\n", NULL, &d); + "bar\n", NULL, NULL, &d); assert_non_null(html); assert_string_equal(html, "foo
\n" @@ -1171,7 +1343,7 @@ test_content_parse_description(void **state) "# foo\n" "\n" "qwe\n" - "bar\n", NULL, &d); + "bar\n", NULL, NULL, &d); assert_non_null(html); assert_string_equal(html, "foo
\n" @@ -1187,7 +1359,7 @@ test_content_parse_description(void **state) "\n" "> qwe\n" "\n" - "bar\n", NULL, &d); + "bar\n", NULL, NULL, &d); assert_non_null(html); assert_string_equal(html, "foo
\n" @@ -1205,7 +1377,7 @@ test_content_parse_description(void **state) "> qwe\n" "> zxc\n" "\n" - "bar\n", NULL, &d); + "bar\n", NULL, NULL, &d); assert_non_null(html); assert_string_equal(html, "foo
\n" @@ -1227,7 +1399,7 @@ test_content_parse_description_crlf(void **state) char *html = blogc_content_parse( "# foo\r\n" "\r\n" - "bar", NULL, &d); + "bar", NULL, NULL, &d); assert_non_null(html); assert_string_equal(html, "foo
\r\n" @@ -1240,7 +1412,7 @@ test_content_parse_description_crlf(void **state) html = blogc_content_parse( "# foo\r\n" "\r\n" - "bar\r\n", NULL, &d); + "bar\r\n", NULL, NULL, &d); assert_non_null(html); assert_string_equal(html, "foo
\r\n" @@ -1254,7 +1426,7 @@ test_content_parse_description_crlf(void **state) "# foo\r\n" "\r\n" "qwe\r\n" - "bar\r\n", NULL, &d); + "bar\r\n", NULL, NULL, &d); assert_non_null(html); assert_string_equal(html, "foo
\r\n" @@ -1270,7 +1442,7 @@ test_content_parse_description_crlf(void **state) "\r\n" "> qwe\r\n" "\r\n" - "bar\r\n", NULL, &d); + "bar\r\n", NULL, NULL, &d); assert_non_null(html); assert_string_equal(html, "foo
\r\n" @@ -1288,7 +1460,7 @@ test_content_parse_description_crlf(void **state) "> qwe\r\n" "> zxc\r\n" "\r\n" - "bar\r\n", NULL, &d); + "bar\r\n", NULL, NULL, &d); assert_non_null(html); assert_string_equal(html, "foo
\r\n" @@ -1315,7 +1487,7 @@ test_content_parse_invalid_excerpt(void **state) "..\n" "\n" "guda\n" - "lol", &l, &d); + "lol", &l, NULL, &d); assert_non_null(html); assert_int_equal(l, 0); assert_non_null(d); @@ -1337,7 +1509,7 @@ test_content_parse_invalid_excerpt(void **state) "\n" "...\n" "guda\n" - "lol", &l, &d); + "lol", &l, NULL, &d); assert_non_null(html); assert_int_equal(l, 0); assert_non_null(d); @@ -1358,7 +1530,7 @@ test_content_parse_invalid_excerpt(void **state) "chunda..\n" "\n" "guda\n" - "lol", &l, &d); + "lol", &l, NULL, &d); assert_non_null(html); assert_int_equal(l, 0); assert_non_null(d); @@ -1378,7 +1550,7 @@ test_content_parse_invalid_excerpt(void **state) "chunda\n" "\n" "...guda\n" - "lol", &l, &d); + "lol", &l, NULL, &d); assert_non_null(html); assert_int_equal(l, 0); assert_non_null(d); @@ -1399,7 +1571,7 @@ test_content_parse_invalid_header(void **state) char *html = blogc_content_parse( "asd\n" "\n" - "##bola\n", NULL, NULL); + "##bola\n", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "asd
\n" @@ -1416,7 +1588,7 @@ test_content_parse_invalid_header_empty(void **state) "\n" "##\n" "\n" - "qwe\n", NULL, NULL); + "qwe\n", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "asd
\n" @@ -1433,7 +1605,7 @@ test_content_parse_invalid_blockquote(void **state) char *html = blogc_content_parse( "> asd\n" "> bola\n" - "> foo\n", NULL, NULL); + "> foo\n", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "> asd\n" @@ -1442,7 +1614,7 @@ test_content_parse_invalid_blockquote(void **state) free(html); html = blogc_content_parse( "> asd\n" - "> bola", NULL, NULL); + "> bola", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "
> asd\n" @@ -1457,7 +1629,7 @@ test_content_parse_invalid_code(void **state) char *html = blogc_content_parse( " asd\n" " bola\n" - " foo\n", NULL, NULL); + " foo\n", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "
asd\n" @@ -1467,7 +1639,7 @@ test_content_parse_invalid_code(void **state) html = blogc_content_parse( " asd\n" " bola\n" - " foo", NULL, NULL); + " foo", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "
asd\n" @@ -1480,11 +1652,11 @@ test_content_parse_invalid_code(void **state) static void test_content_parse_invalid_horizontal_rule(void **state) { - char *html = blogc_content_parse("** asd", NULL, NULL); + char *html = blogc_content_parse("** asd", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "
** asd
\n"); free(html); - html = blogc_content_parse("** asd\n", NULL, NULL); + html = blogc_content_parse("** asd\n", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "** asd
\n"); free(html); @@ -1496,7 +1668,7 @@ test_content_parse_invalid_unordered_list(void **state) { char *html = blogc_content_parse( "* asd\n" - "1. qwe", NULL, NULL); + "1. qwe", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "* asd\n" @@ -1505,7 +1677,7 @@ test_content_parse_invalid_unordered_list(void **state) html = blogc_content_parse( "* asd\n" "1. qwe\n" - "\n", NULL, NULL); + "\n", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "
* asd\n" @@ -1513,7 +1685,7 @@ test_content_parse_invalid_unordered_list(void **state) free(html); html = blogc_content_parse( "* asd\n" - "1. qwe\n", NULL, NULL); + "1. qwe\n", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "
* asd\n" @@ -1522,7 +1694,7 @@ test_content_parse_invalid_unordered_list(void **state) free(html); html = blogc_content_parse( "* asd\n" - "1. qwe\n", NULL, NULL); + "1. qwe\n", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "
* asd\n" @@ -1535,7 +1707,7 @@ test_content_parse_invalid_unordered_list(void **state) "* asd\n" "1. qwe\n" "\n" - "poi\n", NULL, NULL); + "poi\n", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "
chunda
\n" @@ -1551,7 +1723,7 @@ test_content_parse_invalid_ordered_list(void **state) { char *html = blogc_content_parse( "1. asd\n" - "* qwe", NULL, NULL); + "* qwe", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "1. asd\n" @@ -1560,7 +1732,7 @@ test_content_parse_invalid_ordered_list(void **state) html = blogc_content_parse( "1. asd\n" "* qwe\n" - "\n", NULL, NULL); + "\n", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "
1. asd\n" @@ -1568,7 +1740,7 @@ test_content_parse_invalid_ordered_list(void **state) free(html); html = blogc_content_parse( "1. asd\n" - "* qwe\n", NULL, NULL); + "* qwe\n", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "
1. asd\n" @@ -1577,7 +1749,7 @@ test_content_parse_invalid_ordered_list(void **state) free(html); html = blogc_content_parse( "1. asd\n" - "* qwe\n", NULL, NULL); + "* qwe\n", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "
1. asd\n" @@ -1590,7 +1762,7 @@ test_content_parse_invalid_ordered_list(void **state) "1. asd\n" "* qwe\n" "\n" - "poi\n", NULL, NULL); + "poi\n", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "
chunda
\n" @@ -1600,7 +1772,7 @@ test_content_parse_invalid_ordered_list(void **state) free(html); html = blogc_content_parse( "1 asd\n" - "* qwe\n", NULL, NULL); + "* qwe\n", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "1 asd\n" @@ -1608,7 +1780,7 @@ test_content_parse_invalid_ordered_list(void **state) free(html); html = blogc_content_parse( "a. asd\n" - "2. qwe\n", NULL, NULL); + "2. qwe\n", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "
a. asd\n" @@ -1616,18 +1788,18 @@ test_content_parse_invalid_ordered_list(void **state) free(html); html = blogc_content_parse( "1.\nasd\n" - "2. qwe\n", NULL, NULL); + "2. qwe\n", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "
1.\n" "asd\n" "2. qwe
\n"); free(html); - html = blogc_content_parse("1.\n", NULL, NULL); + html = blogc_content_parse("1.\n", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "1.
\n"); free(html); - html = blogc_content_parse("1 ", NULL, NULL); + html = blogc_content_parse("1 ", NULL, NULL, NULL); assert_non_null(html); assert_string_equal(html, "1
\n"); free(html); @@ -2183,6 +2355,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_title), + unit_test(test_content_parse_title_crlf), unit_test(test_content_parse_description), unit_test(test_content_parse_description_crlf), unit_test(test_content_parse_invalid_excerpt), diff --git a/tests/blogc/check_source_parser.c b/tests/blogc/check_source_parser.c index 16acd96..e6ff955 100644 --- a/tests/blogc/check_source_parser.c +++ b/tests/blogc/check_source_parser.c @@ -30,7 +30,7 @@ test_source_parse(void **state) bc_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(err); assert_non_null(source); - assert_int_equal(bc_trie_size(source), 6); + assert_int_equal(bc_trie_size(source), 7); assert_string_equal(bc_trie_lookup(source, "VAR1"), "asd asd"); assert_string_equal(bc_trie_lookup(source, "VAR2"), "123chunda"); assert_string_equal(bc_trie_lookup(source, "EXCERPT"), @@ -43,6 +43,7 @@ test_source_parse(void **state) "# This is a test\n" "\n" "bola\n"); + assert_string_equal(bc_trie_lookup(source, "TITLE"), "This is a test"); assert_string_equal(bc_trie_lookup(source, "DESCRIPTION"), "bola"); bc_trie_free(source); } @@ -62,7 +63,7 @@ test_source_parse_crlf(void **state) bc_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(err); assert_non_null(source); - assert_int_equal(bc_trie_size(source), 6); + assert_int_equal(bc_trie_size(source), 7); assert_string_equal(bc_trie_lookup(source, "VAR1"), "asd asd"); assert_string_equal(bc_trie_lookup(source, "VAR2"), "123chunda"); assert_string_equal(bc_trie_lookup(source, "EXCERPT"), @@ -75,6 +76,7 @@ test_source_parse_crlf(void **state) "# This is a test\r\n" "\r\n" "bola\r\n"); + assert_string_equal(bc_trie_lookup(source, "TITLE"), "This is a test"); assert_string_equal(bc_trie_lookup(source, "DESCRIPTION"), "bola"); bc_trie_free(source); } @@ -96,7 +98,7 @@ test_source_parse_with_spaces(void **state) bc_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(err); assert_non_null(source); - assert_int_equal(bc_trie_size(source), 6); + assert_int_equal(bc_trie_size(source), 7); assert_string_equal(bc_trie_lookup(source, "VAR1"), "chunda"); assert_string_equal(bc_trie_lookup(source, "BOLA"), "guda"); assert_string_equal(bc_trie_lookup(source, "EXCERPT"), @@ -109,6 +111,7 @@ test_source_parse_with_spaces(void **state) "# This is a test\n" "\n" "bola\n"); + assert_string_equal(bc_trie_lookup(source, "TITLE"), "This is a test"); assert_string_equal(bc_trie_lookup(source, "DESCRIPTION"), "bola"); bc_trie_free(source); } @@ -133,7 +136,7 @@ test_source_parse_with_excerpt(void **state) bc_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(err); assert_non_null(source); - assert_int_equal(bc_trie_size(source), 6); + assert_int_equal(bc_trie_size(source), 7); assert_string_equal(bc_trie_lookup(source, "VAR1"), "asd asd"); assert_string_equal(bc_trie_lookup(source, "VAR2"), "123chunda"); assert_string_equal(bc_trie_lookup(source, "EXCERPT"), @@ -153,6 +156,41 @@ test_source_parse_with_excerpt(void **state) "\n" "guda\n" "yay"); + assert_string_equal(bc_trie_lookup(source, "TITLE"), "This is a test"); + assert_string_equal(bc_trie_lookup(source, "DESCRIPTION"), "bola"); + bc_trie_free(source); +} + + +static void +test_source_parse_with_title(void **state) +{ + const char *a = + "VAR1: asd asd\n" + "VAR2: 123chunda\n" + "TITLE: THIS IS CHUNDA!\n" + "----------\n" + "# This is a test\n" + "\n" + "bola\n"; + bc_error_t *err = NULL; + bc_trie_t *source = blogc_source_parse(a, strlen(a), &err); + assert_null(err); + assert_non_null(source); + assert_int_equal(bc_trie_size(source), 7); + assert_string_equal(bc_trie_lookup(source, "VAR1"), "asd asd"); + assert_string_equal(bc_trie_lookup(source, "VAR2"), "123chunda"); + assert_string_equal(bc_trie_lookup(source, "EXCERPT"), + "This is a test
\n" + "bola
\n"); + assert_string_equal(bc_trie_lookup(source, "CONTENT"), + "This is a test
\n" + "bola
\n"); + assert_string_equal(bc_trie_lookup(source, "RAW_CONTENT"), + "# This is a test\n" + "\n" + "bola\n"); + assert_string_equal(bc_trie_lookup(source, "TITLE"), "THIS IS CHUNDA!"); assert_string_equal(bc_trie_lookup(source, "DESCRIPTION"), "bola"); bc_trie_free(source); } @@ -173,7 +211,7 @@ test_source_parse_with_description(void **state) bc_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(err); assert_non_null(source); - assert_int_equal(bc_trie_size(source), 6); + assert_int_equal(bc_trie_size(source), 7); assert_string_equal(bc_trie_lookup(source, "VAR1"), "asd asd"); assert_string_equal(bc_trie_lookup(source, "VAR2"), "123chunda"); assert_string_equal(bc_trie_lookup(source, "EXCERPT"), @@ -186,6 +224,7 @@ test_source_parse_with_description(void **state) "# This is a test\n" "\n" "bola\n"); + assert_string_equal(bc_trie_lookup(source, "TITLE"), "This is a test"); assert_string_equal(bc_trie_lookup(source, "DESCRIPTION"), "huehuehuebrbr"); bc_trie_free(source); } @@ -517,6 +556,7 @@ main(void) unit_test(test_source_parse_crlf), unit_test(test_source_parse_with_spaces), unit_test(test_source_parse_with_excerpt), + unit_test(test_source_parse_with_title), unit_test(test_source_parse_with_description), unit_test(test_source_parse_config_empty), unit_test(test_source_parse_config_invalid_key), -- cgit v1.2.3-18-g5258