aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2017-02-14 23:51:36 +0100
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2017-02-14 23:51:36 +0100
commit80017f034146b50fdc441c96636f1098adf7037e (patch)
treecbac45bca69cf635c2ad633ea1bcd6f40ba97a9f
parent99ef1c93f0359741fd18217cd81cf2c3e0beaf7b (diff)
downloadblogc-80017f034146b50fdc441c96636f1098adf7037e.tar.gz
blogc-80017f034146b50fdc441c96636f1098adf7037e.tar.bz2
blogc-80017f034146b50fdc441c96636f1098adf7037e.zip
content-parser: source-parser: extract TITLE from content header
this patch implements support to using the first header found in source file as the TITLE variable. please note that if the TITLE variable is defined on the source file's variable section it takes precedence. this patch changes the old behaviour and can break some users' websites. if you have some '{% ifdef TITLE %}' blocks in your template, they will evaluate to true if you don't defined TITLE manually, but have a header in your content.
-rw-r--r--src/blogc/content-parser.c9
-rw-r--r--src/blogc/content-parser.h2
-rw-r--r--src/blogc/source-parser.c15
-rw-r--r--tests/blogc/check_content_parser.c376
-rw-r--r--tests/blogc/check_source_parser.c50
5 files changed, 341 insertions, 111 deletions
diff --git a/src/blogc/content-parser.c b/src/blogc/content-parser.c
index 23586bb..415e5ee 100644
--- a/src/blogc/content-parser.c
+++ b/src/blogc/content-parser.c
@@ -674,7 +674,8 @@ blogc_is_ordered_list_item(const char *str, size_t prefix_len)
char*
-blogc_content_parse(const char *src, size_t *end_excerpt, char **description)
+blogc_content_parse(const char *src, size_t *end_excerpt, char **title,
+ char **description)
{
// src is always nul-terminated.
size_t src_len = strlen(src);
@@ -834,6 +835,8 @@ blogc_content_parse(const char *src, size_t *end_excerpt, char **description)
end = is_last && c != '\n' && c != '\r' ? src_len :
(real_end != 0 ? real_end : current);
tmp = bc_strndup(src + start, end - start);
+ if (title != NULL && *title == NULL)
+ *title = bc_strdup(tmp);
parsed = blogc_content_parse_inline(tmp);
slug = blogc_slugify(tmp);
if (slug == NULL)
@@ -915,10 +918,10 @@ blogc_content_parse(const char *src, size_t *end_excerpt, char **description)
for (bc_slist_t *l = lines; l != NULL; l = l->next)
bc_string_append_printf(tmp_str, "%s%s", l->data,
line_ending);
- // do not propagate description to blockquote parsing,
+ // do not propagate title and description to blockquote parsing,
// because we just want paragraphs from first level of
// content.
- tmp = blogc_content_parse(tmp_str->str, NULL, NULL);
+ tmp = blogc_content_parse(tmp_str->str, NULL, NULL, NULL);
bc_string_append_printf(rv, "<blockquote>%s</blockquote>%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)
"<p>&ndash; asd</p>\n"
"<p>&mdash; lol</p>\n");
free(html);
+ free(t);
free(d);
}
@@ -215,6 +219,7 @@ static void
test_content_parse_crlf(void **state)
{
size_t l = 0;
+ char *t = NULL;
char *d = NULL;
char *html = blogc_content_parse(
"# um\r\n"
@@ -257,9 +262,11 @@ test_content_parse_crlf(void **state)
"\r\n"
"-- asd\r\n"
"\r\n"
- "--- lol\r\n", &l, &d);
+ "--- lol\r\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,
@@ -299,6 +306,7 @@ test_content_parse_crlf(void **state)
"<p>&ndash; asd</p>\r\n"
"<p>&mdash; lol</p>\r\n");
free(html);
+ free(t);
free(d);
}
@@ -307,6 +315,7 @@ static void
test_content_parse_with_excerpt(void **state)
{
size_t l = 0;
+ char *t = NULL;
char *d = NULL;
char *html = blogc_content_parse(
"# test\n"
@@ -316,9 +325,11 @@ test_content_parse_with_excerpt(void **state)
"..\n"
"\n"
"guda\n"
- "lol", &l, &d);
+ "lol", &l, &t, &d);
assert_non_null(html);
assert_int_equal(l, 38);
+ assert_non_null(t);
+ assert_string_equal(t, "test");
assert_non_null(d);
assert_string_equal(d, "chunda");
assert_string_equal(html,
@@ -328,7 +339,9 @@ test_content_parse_with_excerpt(void **state)
"lol</p>\n");
free(html);
l = 0;
+ free(t);
free(d);
+ t = NULL;
d = NULL;
html = blogc_content_parse(
"# test\n"
@@ -338,9 +351,11 @@ test_content_parse_with_excerpt(void **state)
"...\n"
"\n"
"guda\n"
- "lol", &l, &d);
+ "lol", &l, &t, &d);
assert_non_null(html);
assert_int_equal(l, 38);
+ assert_non_null(t);
+ assert_string_equal(t, "test");
assert_non_null(d);
assert_string_equal(d, "chunda");
assert_string_equal(html,
@@ -349,6 +364,7 @@ test_content_parse_with_excerpt(void **state)
"<p>guda\n"
"lol</p>\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</p>\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)
"<p>guda\r\n"
"lol</p>\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, "<h2 id=\"bola\">bola</h2>\n");
free(html);
- html = blogc_content_parse("## bola\n", NULL, NULL);
+ html = blogc_content_parse("## bola\n", NULL, NULL, NULL);
assert_non_null(html);
assert_string_equal(html, "<h2 id=\"bola\">bola</h2>\n");
free(html);
@@ -419,7 +443,7 @@ test_content_parse_header(void **state)
"\n"
"## bola\n"
"\n"
- "guda\n", NULL, NULL);
+ "guda\n", NULL, NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>bola</p>\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, "<h2 id=\"bola\">bola</h2>\n");
free(html);
- html = blogc_content_parse("## bola\r\n", NULL, NULL);
+ html = blogc_content_parse("## bola\r\n", NULL, NULL, NULL);
assert_non_null(html);
assert_string_equal(html, "<h2 id=\"bola\">bola</h2>\r\n");
free(html);
@@ -445,7 +469,7 @@ test_content_parse_header_crlf(void **state)
"\r\n"
"## bola\r\n"
"\r\n"
- "guda\r\n", NULL, NULL);
+ "guda\r\n", NULL, NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>bola</p>\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("<div>\n</div>", NULL, NULL);
+ char *html = blogc_content_parse("<div>\n</div>", NULL, 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, NULL);
+ html = blogc_content_parse("<div>\n</div>\n", NULL, NULL, NULL);
assert_non_null(html);
assert_string_equal(html, "<div>\n</div>\n");
free(html);
@@ -472,7 +496,7 @@ test_content_parse_html(void **state)
"<div>\n"
"</div>\n"
"\n"
- "chunda\n", NULL, NULL);
+ "chunda\n", NULL, NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>bola</p>\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("<div>\r\n</div>", NULL, NULL);
+ char *html = blogc_content_parse("<div>\r\n</div>", NULL, 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, NULL);
+ html = blogc_content_parse("<div>\r\n</div>\r\n", NULL, NULL, NULL);
assert_non_null(html);
assert_string_equal(html, "<div>\r\n</div>\r\n");
free(html);
@@ -499,7 +523,7 @@ test_content_parse_html_crlf(void **state)
"<div>\r\n"
"</div>\r\n"
"\r\n"
- "chunda\r\n", NULL, NULL);
+ "chunda\r\n", NULL, NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>bola</p>\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,
"<blockquote><p>bola\n"
"guda</p>\n"
"</blockquote>\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,
"<blockquote><p>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,
"<p>bola</p>\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,
"<p>bola</p>\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,
"<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, NULL);
+ html = blogc_content_parse("> bola\r\n> guda\r\n", NULL, NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<blockquote><p>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,
"<p>bola</p>\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,
"<p>bola</p>\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,
"<pre><code>bola\n"
"guda</code></pre>\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,
"<pre><code>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,
"<p>bola</p>\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,
"<pre><code>bola\r\n"
"guda</code></pre>\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,
"<pre><code>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,
"<p>bola</p>\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,
"<p>bola\n"
"guda</p>\n"
"<hr />\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,
"<p>bola\n"
"guda</p>\n"
"<hr />\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,
"<p>bola\n"
"guda</p>\n"
"<hr />\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,
"<p>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,
"<p>bola</p>\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,
"<p>bola</p>\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,
"<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, NULL);
+ html = blogc_content_parse("bola\r\nguda\r\n\r\n++++", NULL, 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, 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,
"<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, 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,
"<p>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,
"<p>bola</p>\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,
"<p>bola</p>\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,
"<p>lol</p>\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,
"<p>lol</p>\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,
"<p>lol</p>\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,
"<p>lol</p>\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,
"<ul>\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,
"<p>lol</p>\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,
"<p>lol</p>\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,
"<p>lol</p>\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,
"<p>lol</p>\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,
"<ul>\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,
"<p>lol</p>\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,
"<p>lol</p>\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,
"<p>lol</p>\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,
"<p>lol</p>\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,
"<ol>\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,
"<p>lol</p>\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,
"<p>lol</p>\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,
"<p>lol</p>\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,
"<p>lol</p>\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,
"<ol>\r\n"
@@ -1138,13 +1162,161 @@ 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, "<h1 id=\"foo\">foo</h1>\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, "<h1 id=\"foo\">foo</h1>\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,
+ "<h1 id=\"foo\">foo</h1>\n"
+ "<h2 id=\"bar\">bar</h2>\n"
+ "<h3 id=\"baz\">baz</h3>\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,
+ "<h1 id=\"foo\">foo</h1>\n"
+ "<h2 id=\"bar\">bar</h2>\n"
+ "<h3 id=\"baz\">baz</h3>\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,
+ "<h2 id=\"bar\">bar</h2>\n"
+ "<h1 id=\"foo\">foo</h1>\n"
+ "<h3 id=\"baz\">baz</h3>\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,
+ "<h2 id=\"bar\">bar</h2>\n"
+ "<h1 id=\"foo\">foo</h1>\n"
+ "<h3 id=\"baz\">baz</h3>\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, "<h1 id=\"foo\">foo</h1>\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,
+ "<h1 id=\"foo\">foo</h1>\r\n"
+ "<h2 id=\"bar\">bar</h2>\r\n"
+ "<h3 id=\"baz\">baz</h3>\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,
+ "<h1 id=\"foo\">foo</h1>\r\n"
+ "<h2 id=\"bar\">bar</h2>\r\n"
+ "<h3 id=\"baz\">baz</h3>\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,
+ "<h2 id=\"bar\">bar</h2>\r\n"
+ "<h1 id=\"foo\">foo</h1>\r\n"
+ "<h3 id=\"baz\">baz</h3>\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,
+ "<h2 id=\"bar\">bar</h2>\r\n"
+ "<h1 id=\"foo\">foo</h1>\r\n"
+ "<h3 id=\"baz\">baz</h3>\r\n");
+ assert_non_null(t);
+ assert_string_equal(t, "bar");
+ free(html);
+ free(t);
+}
+
+
+static void
test_content_parse_description(void **state)
{
char *d = NULL;
char *html = blogc_content_parse(
"# foo\n"
"\n"
- "bar", NULL, &d);
+ "bar", NULL, NULL, &d);
assert_non_null(html);
assert_string_equal(html,
"<h1 id=\"foo\">foo</h1>\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,
"<h1 id=\"foo\">foo</h1>\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,
"<h1 id=\"foo\">foo</h1>\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,
"<h1 id=\"foo\">foo</h1>\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,
"<h1 id=\"foo\">foo</h1>\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,
"<h1 id=\"foo\">foo</h1>\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,
"<h1 id=\"foo\">foo</h1>\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,
"<h1 id=\"foo\">foo</h1>\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,
"<h1 id=\"foo\">foo</h1>\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,
"<h1 id=\"foo\">foo</h1>\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,
"<p>asd</p>\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,
"<p>asd</p>\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,
"<p>&gt; 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,
"<p>&gt; 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,
"<p> 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,
"<p> 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, "<p>** asd</p>\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, "<p>** asd</p>\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,
"<p>* 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,
"<p>* 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,
"<p>* 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,
"<p>* 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,
"<p>chunda</p>\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,
"<p>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,
"<p>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,
"<p>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,
"<p>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,
"<p>chunda</p>\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,
"<p>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,
"<p>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,
"<p>1.\n"
"asd\n"
"2. qwe</p>\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, "<p>1.</p>\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, "<p>1 </p>\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"),
+ "<h1 id=\"this-is-a-test\">This is a test</h1>\n"
+ "<p>bola</p>\n");
+ assert_string_equal(bc_trie_lookup(source, "CONTENT"),
+ "<h1 id=\"this-is-a-test\">This is a test</h1>\n"
+ "<p>bola</p>\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),