From 9b2a563b4931ca39cd6dd14bf85cda627714a4b2 Mon Sep 17 00:00:00 2001
From: "Rafael G. Martins" – asd — lol – asd — lol chunda%s
%s",
tmp, line_ending);
free(tmp);
@@ -1019,6 +1015,8 @@ blogc_content_parse(const char *src, size_t *end_excerpt)
state = CONTENT_PARAGRAPH_END;
end = is_last && c != '\n' && c != '\r' ? src_len :
(real_end != 0 ? real_end : current);
+ if (description != NULL && *description == NULL)
+ *description = sb_strndup(src + start, end - start);
}
if (!is_last)
break;
diff --git a/src/content-parser.h b/src/content-parser.h
index 6617bb4..148d5ed 100644
--- a/src/content-parser.h
+++ b/src/content-parser.h
@@ -16,6 +16,7 @@ char* blogc_slugify(const char *str);
char* blogc_htmlentities(const char *str);
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 **description);
#endif /* _CONTENT_PARSER_H */
diff --git a/src/source-parser.c b/src/source-parser.c
index 1047f06..6e026d2 100644
--- a/src/source-parser.c
+++ b/src/source-parser.c
@@ -154,7 +154,19 @@ blogc_source_parse(const char *src, size_t src_len, sb_error_t **err)
if (current == (src_len - 1)) {
tmp = sb_strndup(src + start, src_len - start);
sb_trie_insert(rv, "RAW_CONTENT", tmp);
- content = blogc_content_parse(tmp, &end_excerpt);
+ char *description = NULL;
+ content = blogc_content_parse(tmp, &end_excerpt, &description);
+ if (description != NULL) {
+ // do not override source-provided description.
+ if (NULL == sb_trie_lookup(rv, "DESCRIPTION")) {
+ // no need to free, because we are transfering memory
+ // ownership to the trie.
+ sb_trie_insert(rv, "DESCRIPTION", description);
+ }
+ else {
+ free(description);
+ }
+ }
sb_trie_insert(rv, "CONTENT", content);
sb_trie_insert(rv, "EXCERPT", end_excerpt == 0 ?
sb_strdup(content) : sb_strndup(content, end_excerpt));
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,
"um
\n"
"dois
\n"
@@ -162,6 +165,7 @@ test_content_parse(void **state)
"um
\r\n"
"dois
\r\n"
@@ -250,6 +257,7 @@ test_content_parse_crlf(void **state)
"test
\n"
"
chunda
\n" "guda\n" "lol
\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, "chunda
\r\n" @@ -317,6 +336,8 @@ test_content_parse_with_excerpt_crlf(void **state) "lol\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, "chunda
\r\n" "guda\r\n" "lol
\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, "bola
\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, "bola
\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("bola
\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("bola
\r\n" @@ -446,27 +470,40 @@ 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, "\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, "bola\n" "guda
\n" "
\n"); free(html); + html = blogc_content_parse( + "bola\n" + "\n" + "> bola\n" + "\n" + "chunda\n", NULL, NULL); + assert_non_null(html); + assert_string_equal(html, + "bola\n" "guda
\n" "
bola
\n" + "\n" + "bola
\n" + "
chunda
\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, "bola
\n" @@ -481,27 +518,40 @@ 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, "\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, "bola\r\n" "guda
\r\n" "
\r\n"); free(html); + html = blogc_content_parse( + "bola\r\n" + "\r\n" + "> bola\r\n" + "\r\n" + "chunda\r\n", NULL, NULL); + assert_non_null(html); + assert_string_equal(html, + "bola\r\n" "guda
\r\n" "
bola
\r\n" + "\r\n" + "bola
\r\n" + "
chunda
\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, "bola
\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, "bola\n"
"guda
\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,
"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,
"bola
\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,
"bola\r\n"
"guda
\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,
"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,
"bola
\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,
"bola\n"
"guda
\n"
"
\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,
"bola\n"
"guda
\n"
"
\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,
"bola\n"
"guda
\n"
"
\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,
"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,
"
bola
\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,
"bola
\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,
"bola\r\n"
"guda
\r\n"
"
\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,
"bola\r\n"
"guda
\r\n"
"
\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,
"bola\r\n"
"guda
\r\n"
"
\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,
"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,
"
bola
\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,
"bola
\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,
"lol
\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,
"lol
\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,
"lol
\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,
"lol
\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,
"\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,
"lol
\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,
"lol
\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,
"lol
\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,
"lol
\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,
"\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,
"lol
\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,
"lol
\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,
"lol
\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,
"lol
\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,
"\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,
"lol
\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,
"lol
\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,
"lol
\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,
"lol
\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,
"\r\n"
@@ -1045,10 +1095,177 @@ 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,
+ "foo
\n"
+ "bar
\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,
+ "foo
\n"
+ "bar
\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,
+ "foo
\n"
+ "qwe\n"
+ "bar
\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,
+ "foo
\n"
+ "qwe
\n"
+ "
\n"
+ "bar
\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,
+ "foo
\n"
+ "qwe\n"
+ "zxc
\n"
+ "
\n"
+ "bar
\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,
+ "foo
\r\n"
+ "bar
\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,
+ "foo
\r\n"
+ "bar
\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,
+ "foo
\r\n"
+ "qwe\r\n"
+ "bar
\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,
+ "foo
\r\n"
+ "qwe
\r\n"
+ "
\r\n"
+ "bar
\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,
+ "foo
\r\n"
+ "qwe\r\n"
+ "zxc
\r\n"
+ "
\r\n"
+ "bar
\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,
"test
\n"
"chunda\n"
@@ -1067,6 +1286,8 @@ test_content_parse_invalid_excerpt(void **state)
"lol
\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,
"test
\n"
"chunda
\n"
@@ -1085,15 +1308,19 @@ test_content_parse_invalid_excerpt(void **state)
"lol\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,
"test
\n"
"chunda..
\n"
@@ -1101,21 +1328,26 @@ test_content_parse_invalid_excerpt(void **state)
"lol\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,
"test
\n"
"chunda
\n"
"...guda\n"
"lol
\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,
"asd
\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,
"asd
\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,
"> 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,
"
> 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,
"
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,
"
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, "
asd
\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, " asd
\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,
" 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,
" 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,
" 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,
" 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,
"chunda
\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,
"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,
"
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,
"
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,
"
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,
"
chunda
\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,
"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,
"
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,
"
1.\n"
"asd\n"
"2. qwe
\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, "1.
\n");
free(html);
- html = blogc_content_parse("1 ", NULL);
+ html = blogc_content_parse("1 ", NULL, NULL);
assert_non_null(html);
assert_string_equal(html, "1
\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),
diff --git a/tests/check_loader.c b/tests/check_loader.c
index 0db6194..c0e30df 100644
--- a/tests/check_loader.c
+++ b/tests/check_loader.c
@@ -113,12 +113,13 @@ test_source_parse_from_file(void **state)
sb_trie_t *t = blogc_source_parse_from_file("bola.txt", &err);
assert_null(err);
assert_non_null(t);
- assert_int_equal(sb_trie_size(t), 5);
+ assert_int_equal(sb_trie_size(t), 6);
assert_string_equal(sb_trie_lookup(t, "ASD"), "123");
assert_string_equal(sb_trie_lookup(t, "FILENAME"), "bola");
assert_string_equal(sb_trie_lookup(t, "EXCERPT"), "bola
\n");
assert_string_equal(sb_trie_lookup(t, "CONTENT"), "bola
\n");
assert_string_equal(sb_trie_lookup(t, "RAW_CONTENT"), "bola");
+ assert_string_equal(sb_trie_lookup(t, "DESCRIPTION"), "bola");
sb_trie_free(t);
}
diff --git a/tests/check_source_parser.c b/tests/check_source_parser.c
index fba997a..a2a3ddc 100644
--- a/tests/check_source_parser.c
+++ b/tests/check_source_parser.c
@@ -34,7 +34,7 @@ test_source_parse(void **state)
sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(err);
assert_non_null(source);
- assert_int_equal(sb_trie_size(source), 5);
+ assert_int_equal(sb_trie_size(source), 6);
assert_string_equal(sb_trie_lookup(source, "VAR1"), "asd asd");
assert_string_equal(sb_trie_lookup(source, "VAR2"), "123chunda");
assert_string_equal(sb_trie_lookup(source, "EXCERPT"),
@@ -47,6 +47,7 @@ test_source_parse(void **state)
"# This is a test\n"
"\n"
"bola\n");
+ assert_string_equal(sb_trie_lookup(source, "DESCRIPTION"), "bola");
sb_trie_free(source);
}
@@ -65,7 +66,7 @@ test_source_parse_crlf(void **state)
sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(err);
assert_non_null(source);
- assert_int_equal(sb_trie_size(source), 5);
+ assert_int_equal(sb_trie_size(source), 6);
assert_string_equal(sb_trie_lookup(source, "VAR1"), "asd asd");
assert_string_equal(sb_trie_lookup(source, "VAR2"), "123chunda");
assert_string_equal(sb_trie_lookup(source, "EXCERPT"),
@@ -78,6 +79,7 @@ test_source_parse_crlf(void **state)
"# This is a test\r\n"
"\r\n"
"bola\r\n");
+ assert_string_equal(sb_trie_lookup(source, "DESCRIPTION"), "bola");
sb_trie_free(source);
}
@@ -98,7 +100,7 @@ test_source_parse_with_spaces(void **state)
sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(err);
assert_non_null(source);
- assert_int_equal(sb_trie_size(source), 5);
+ assert_int_equal(sb_trie_size(source), 6);
assert_string_equal(sb_trie_lookup(source, "VAR1"), "chunda");
assert_string_equal(sb_trie_lookup(source, "BOLA"), "guda");
assert_string_equal(sb_trie_lookup(source, "EXCERPT"),
@@ -111,6 +113,7 @@ test_source_parse_with_spaces(void **state)
"# This is a test\n"
"\n"
"bola\n");
+ assert_string_equal(sb_trie_lookup(source, "DESCRIPTION"), "bola");
sb_trie_free(source);
}
@@ -134,7 +137,7 @@ test_source_parse_with_excerpt(void **state)
sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(err);
assert_non_null(source);
- assert_int_equal(sb_trie_size(source), 5);
+ assert_int_equal(sb_trie_size(source), 6);
assert_string_equal(sb_trie_lookup(source, "VAR1"), "asd asd");
assert_string_equal(sb_trie_lookup(source, "VAR2"), "123chunda");
assert_string_equal(sb_trie_lookup(source, "EXCERPT"),
@@ -154,6 +157,40 @@ test_source_parse_with_excerpt(void **state)
"\n"
"guda\n"
"yay");
+ assert_string_equal(sb_trie_lookup(source, "DESCRIPTION"), "bola");
+ sb_trie_free(source);
+}
+
+
+static void
+test_source_parse_with_description(void **state)
+{
+ const char *a =
+ "VAR1: asd asd\n"
+ "VAR2: 123chunda\n"
+ "DESCRIPTION: huehuehuebrbr\n"
+ "----------\n"
+ "# This is a test\n"
+ "\n"
+ "bola\n";
+ sb_error_t *err = NULL;
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ assert_null(err);
+ assert_non_null(source);
+ assert_int_equal(sb_trie_size(source), 6);
+ assert_string_equal(sb_trie_lookup(source, "VAR1"), "asd asd");
+ assert_string_equal(sb_trie_lookup(source, "VAR2"), "123chunda");
+ assert_string_equal(sb_trie_lookup(source, "EXCERPT"),
+ "This is a test
\n"
+ "bola
\n");
+ assert_string_equal(sb_trie_lookup(source, "CONTENT"),
+ "This is a test
\n"
+ "bola
\n");
+ assert_string_equal(sb_trie_lookup(source, "RAW_CONTENT"),
+ "# This is a test\n"
+ "\n"
+ "bola\n");
+ assert_string_equal(sb_trie_lookup(source, "DESCRIPTION"), "huehuehuebrbr");
sb_trie_free(source);
}
@@ -484,6 +521,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_description),
unit_test(test_source_parse_config_empty),
unit_test(test_source_parse_config_invalid_key),
unit_test(test_source_parse_config_no_key),
--
cgit v1.2.3-18-g5258