aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2016-06-27 03:01:20 +0200
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2016-06-29 01:35:45 +0200
commit519f1f8031687ebf3853817a8b2e3557c2443d67 (patch)
tree320be2942773ee95c34a798da09685728115045f /tests
parent4cfeb39fbe99be28f22611c6146b1655549f7850 (diff)
downloadblogc-519f1f8031687ebf3853817a8b2e3557c2443d67.tar.gz
blogc-519f1f8031687ebf3853817a8b2e3557c2443d67.tar.bz2
blogc-519f1f8031687ebf3853817a8b2e3557c2443d67.zip
content-parser: rewrote inline parser.
parser is stricter now, and won't produce invalid HTML anymore.
Diffstat (limited to 'tests')
-rw-r--r--tests/check_content_parser.c162
-rw-r--r--tests/check_utils.c33
2 files changed, 161 insertions, 34 deletions
diff --git a/tests/check_content_parser.c b/tests/check_content_parser.c
index 783d3f3..b0272fb 100644
--- a/tests/check_content_parser.c
+++ b/tests/check_content_parser.c
@@ -184,7 +184,7 @@ test_content_parse(void **state)
"<h6 id=\"seis\">seis</h6>\n"
"<p>bola\n"
"chunda</p>\n"
- "<blockquote><p>bola <br />\n"
+ "<blockquote><p>bola<br />\n"
"guda\n"
"buga</p>\n"
"<pre><code>asd</code></pre>\n"
@@ -276,7 +276,7 @@ test_content_parse_crlf(void **state)
"<h6 id=\"seis\">seis</h6>\r\n"
"<p>bola\r\n"
"chunda</p>\r\n"
- "<blockquote><p>bola <br />\r\n"
+ "<blockquote><p>bola<br />\r\n"
"guda\r\n"
"buga</p>\r\n"
"<pre><code>asd</code></pre>\r\n"
@@ -1485,14 +1485,13 @@ test_content_parse_invalid_code(void **state)
static void
test_content_parse_invalid_horizontal_rule(void **state)
{
- // this generates invalid html, but...
char *html = blogc_content_parse("** asd", NULL, NULL);
assert_non_null(html);
- assert_string_equal(html, "<p><strong> asd</p>\n");
+ assert_string_equal(html, "<p>** asd</p>\n");
free(html);
html = blogc_content_parse("** asd\n", NULL, NULL);
assert_non_null(html);
- assert_string_equal(html, "<p><strong> asd</p>\n");
+ assert_string_equal(html, "<p>** asd</p>\n");
free(html);
}
@@ -1500,13 +1499,12 @@ test_content_parse_invalid_horizontal_rule(void **state)
static void
test_content_parse_invalid_unordered_list(void **state)
{
- // more invalid html
char *html = blogc_content_parse(
"* asd\n"
"1. qwe", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
- "<p><em> asd\n"
+ "<p>* asd\n"
"1. qwe</p>\n");
free(html);
html = blogc_content_parse(
@@ -1515,7 +1513,7 @@ test_content_parse_invalid_unordered_list(void **state)
"\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
- "<p><em> asd\n"
+ "<p>* asd\n"
"1. qwe</p>\n");
free(html);
html = blogc_content_parse(
@@ -1523,7 +1521,7 @@ test_content_parse_invalid_unordered_list(void **state)
"1. qwe\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
- "<p><em> asd\n"
+ "<p>* asd\n"
"1. qwe"
"</p>\n");
free(html);
@@ -1532,7 +1530,7 @@ test_content_parse_invalid_unordered_list(void **state)
"1. qwe\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
- "<p><em> asd\n"
+ "<p>* asd\n"
"1. qwe"
"</p>\n");
free(html);
@@ -1546,7 +1544,7 @@ test_content_parse_invalid_unordered_list(void **state)
assert_non_null(html);
assert_string_equal(html,
"<p>chunda</p>\n"
- "<p><em> asd\n"
+ "<p>* asd\n"
"1. qwe</p>\n"
"<p>poi</p>\n");
free(html);
@@ -1556,14 +1554,13 @@ test_content_parse_invalid_unordered_list(void **state)
static void
test_content_parse_invalid_ordered_list(void **state)
{
- // more invalid html
char *html = blogc_content_parse(
"1. asd\n"
"* qwe", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>1. asd\n"
- "<em> qwe</p>\n");
+ "* qwe</p>\n");
free(html);
html = blogc_content_parse(
"1. asd\n"
@@ -1572,7 +1569,7 @@ test_content_parse_invalid_ordered_list(void **state)
assert_non_null(html);
assert_string_equal(html,
"<p>1. asd\n"
- "<em> qwe</p>\n");
+ "* qwe</p>\n");
free(html);
html = blogc_content_parse(
"1. asd\n"
@@ -1580,7 +1577,7 @@ test_content_parse_invalid_ordered_list(void **state)
assert_non_null(html);
assert_string_equal(html,
"<p>1. asd\n"
- "<em> qwe"
+ "* qwe"
"</p>\n");
free(html);
html = blogc_content_parse(
@@ -1589,7 +1586,7 @@ test_content_parse_invalid_ordered_list(void **state)
assert_non_null(html);
assert_string_equal(html,
"<p>1. asd\n"
- "<em> qwe"
+ "* qwe"
"</p>\n");
free(html);
html = blogc_content_parse(
@@ -1603,7 +1600,7 @@ test_content_parse_invalid_ordered_list(void **state)
assert_string_equal(html,
"<p>chunda</p>\n"
"<p>1. asd\n"
- "<em> qwe</p>\n"
+ "* qwe</p>\n"
"<p>poi</p>\n");
free(html);
html = blogc_content_parse(
@@ -1612,7 +1609,7 @@ test_content_parse_invalid_ordered_list(void **state)
assert_non_null(html);
assert_string_equal(html,
"<p>1 asd\n"
- "<em> qwe</p>\n");
+ "* qwe</p>\n");
free(html);
html = blogc_content_parse(
"a. asd\n"
@@ -1677,6 +1674,10 @@ test_content_parse_inline_em(void **state)
assert_non_null(html);
assert_string_equal(html, "<em>bola</em>\n");
free(html);
+ html = blogc_content_parse_inline("*bo\\*la*\n");
+ assert_non_null(html);
+ assert_string_equal(html, "<em>bo*la</em>\n");
+ free(html);
html = blogc_content_parse_inline("_bola_");
assert_non_null(html);
assert_string_equal(html, "<em>bola</em>");
@@ -1685,14 +1686,25 @@ test_content_parse_inline_em(void **state)
assert_non_null(html);
assert_string_equal(html, "<em>bola</em>\n");
free(html);
+ html = blogc_content_parse_inline("_bo\\*la_\n");
+ assert_non_null(html);
+ assert_string_equal(html, "<em>bo*la</em>\n");
+ free(html);
html = blogc_content_parse_inline("_**bola**_\n");
assert_non_null(html);
assert_string_equal(html, "<em><strong>bola</strong></em>\n");
free(html);
- // this is not really valid
+ html = blogc_content_parse_inline("_**bo\\_\\*la**_\n");
+ assert_non_null(html);
+ assert_string_equal(html, "<em><strong>bo_*la</strong></em>\n");
+ free(html);
html = blogc_content_parse_inline("_**bola\n");
assert_non_null(html);
- assert_string_equal(html, "<em><strong>bola\n");
+ assert_string_equal(html, "_**bola\n");
+ free(html);
+ html = blogc_content_parse_inline("**_bola\\*\n");
+ assert_non_null(html);
+ assert_string_equal(html, "**_bola*\n");
free(html);
}
@@ -1708,6 +1720,10 @@ test_content_parse_inline_strong(void **state)
assert_non_null(html);
assert_string_equal(html, "<strong>bola</strong>\n");
free(html);
+ html = blogc_content_parse_inline("**bo\*la**\n");
+ assert_non_null(html);
+ assert_string_equal(html, "<strong>bo*la</strong>\n");
+ free(html);
html = blogc_content_parse_inline("__bola__");
assert_non_null(html);
assert_string_equal(html, "<strong>bola</strong>");
@@ -1716,14 +1732,25 @@ test_content_parse_inline_strong(void **state)
assert_non_null(html);
assert_string_equal(html, "<strong>bola</strong>\n");
free(html);
+ html = blogc_content_parse_inline("__bo\*la__\n");
+ assert_non_null(html);
+ assert_string_equal(html, "<strong>bo*la</strong>\n");
+ free(html);
html = blogc_content_parse_inline("__*bola*__\n");
assert_non_null(html);
assert_string_equal(html, "<strong><em>bola</em></strong>\n");
free(html);
- // this is not really valid
+ html = blogc_content_parse_inline("__*bo\\_\\*la*__\n");
+ assert_non_null(html);
+ assert_string_equal(html, "<strong><em>bo_*la</em></strong>\n");
+ free(html);
html = blogc_content_parse_inline("__*bola\n");
assert_non_null(html);
- assert_string_equal(html, "<strong><em>bola\n");
+ assert_string_equal(html, "__*bola\n");
+ free(html);
+ html = blogc_content_parse_inline("__*bola\\_\n");
+ assert_non_null(html);
+ assert_string_equal(html, "__*bola_\n");
free(html);
}
@@ -1751,18 +1778,29 @@ test_content_parse_inline_code(void **state)
assert_non_null(html);
assert_string_equal(html, "<code>bo*la</code>\n");
free(html);
- // invalid
+ html = blogc_content_parse_inline("``bo<la``\n");
+ assert_non_null(html);
+ assert_string_equal(html, "<code>bo&lt;la</code>\n");
+ free(html);
+ html = blogc_content_parse_inline("`bo\\`\\`la`\n");
+ assert_non_null(html);
+ assert_string_equal(html, "<code>bo``la</code>\n");
+ free(html);
+ html = blogc_content_parse_inline("``bo\\`\\`la``\n");
+ assert_non_null(html);
+ assert_string_equal(html, "<code>bo``la</code>\n");
+ free(html);
html = blogc_content_parse_inline("``bola\n");
assert_non_null(html);
- assert_string_equal(html, "<code>bola\n");
+ assert_string_equal(html, "``bola\n");
free(html);
html = blogc_content_parse_inline("`bola\n");
assert_non_null(html);
- assert_string_equal(html, "<code>bola\n");
+ assert_string_equal(html, "`bola\n");
free(html);
html = blogc_content_parse_inline("``bola`\n");
assert_non_null(html);
- assert_string_equal(html, "<code>bola<code>\n");
+ assert_string_equal(html, "``bola`\n");
free(html);
}
@@ -1802,9 +1840,9 @@ test_content_parse_inline_link(void **state)
assert_non_null(html);
assert_string_equal(html, "<a href=\"http://example.org/\"><code>bola</code></a>\n");
free(html);
- html = blogc_content_parse_inline("[``bola(2)[3]**!\\``](http://example.org/)\n");
+ html = blogc_content_parse_inline("[``bola(2)[3]**!\\```](http://example.org/)\n");
assert_non_null(html);
- assert_string_equal(html, "<a href=\"http://example.org/\"><code>bola(2)[3]**!\\</code></a>\n");
+ assert_string_equal(html, "<a href=\"http://example.org/\"><code>bola(2)[3]**!`</code></a>\n");
free(html);
html = blogc_content_parse_inline("test suite!)\n"
"depends on [cmocka](http://cmocka.org/), though.\n");
@@ -1821,6 +1859,10 @@ test_content_parse_inline_link(void **state)
assert_non_null(html);
assert_string_equal(html, "<a href=\"\nhttp://example.org/\">bola</a>\n");
free(html);
+ html = blogc_content_parse_inline("[bo[]\\[\\]()la](http://example.org/?\\(\\))\n");
+ assert_non_null(html);
+ assert_string_equal(html, "<a href=\"http://example.org/?()\">bo[][]()la</a>\n");
+ free(html);
html = blogc_content_parse_inline("[bola](http://example.org/\n");
assert_non_null(html);
assert_string_equal(html, "[bola](http:&#x2F;&#x2F;example.org&#x2F;\n");
@@ -1863,13 +1905,21 @@ test_content_parse_inline_link_auto(void **state)
assert_non_null(html);
assert_string_equal(html, "<a href=\"guda\">guda</a>\n");
free(html);
+ html = blogc_content_parse_inline("[[http://example.org/?\\[\\]]]\n");
+ assert_non_null(html);
+ assert_string_equal(html, "<a href=\"http://example.org/?[]\">http://example.org/?[]</a>\n");
+ free(html);
+ html = blogc_content_parse_inline("[[http://example.org/?\\[\\]a]]\n");
+ assert_non_null(html);
+ assert_string_equal(html, "<a href=\"http://example.org/?[]a\">http://example.org/?[]a</a>\n");
+ free(html);
html = blogc_content_parse_inline("[[guda]asd]");
assert_non_null(html);
- assert_string_equal(html, "<a href=\"guda\">guda</a>");
+ assert_string_equal(html, "[[guda]asd]");
free(html);
html = blogc_content_parse_inline("[[guda]asd]\n");
assert_non_null(html);
- assert_string_equal(html, "<a href=\"guda\">guda</a>\n");
+ assert_string_equal(html, "[[guda]asd]\n");
free(html);
html = blogc_content_parse_inline("[[guda]asd");
assert_non_null(html);
@@ -1942,6 +1992,10 @@ test_content_parse_inline_image(void **state)
assert_non_null(html);
assert_string_equal(html, "<img src=\"\nhttp://example.org/\" alt=\"bola\">\n");
free(html);
+ html = blogc_content_parse_inline("![bo\\[\\]()la](http://example.org/?\\(\\))\n");
+ assert_non_null(html);
+ assert_string_equal(html, "<img src=\"http://example.org/?()\" alt=\"bo[]()la\">\n");
+ free(html);
html = blogc_content_parse_inline("![bola](http://example.org/\n");
assert_non_null(html);
assert_string_equal(html, "![bola](http:&#x2F;&#x2F;example.org&#x2F;\n");
@@ -1994,15 +2048,15 @@ test_content_parse_inline_line_break(void **state)
{
char *html = blogc_content_parse_inline("asd \n");
assert_non_null(html);
- assert_string_equal(html, "asd <br />\n");
+ assert_string_equal(html, "asd<br />\n");
free(html);
html = blogc_content_parse_inline("asd ");
assert_non_null(html);
- assert_string_equal(html, "asd <br />");
+ assert_string_equal(html, "asd<br />");
free(html);
html = blogc_content_parse_inline("asd ");
assert_non_null(html);
- assert_string_equal(html, "asd <br />");
+ assert_string_equal(html, "asd<br />");
free(html);
// invalid
html = blogc_content_parse_inline("asd ");
@@ -2021,7 +2075,7 @@ test_content_parse_inline_line_break_crlf(void **state)
{
char *html = blogc_content_parse_inline("asd \r\n");
assert_non_null(html);
- assert_string_equal(html, "asd <br />\r\n");
+ assert_string_equal(html, "asd<br />\r\n");
free(html);
html = blogc_content_parse_inline("asd \r\n");
assert_non_null(html);
@@ -2041,6 +2095,46 @@ test_content_parse_inline_endash_emdash(void **state)
assert_non_null(html);
assert_string_equal(html, "foo &mdash; bar");
free(html);
+ html = blogc_content_parse_inline("foo --");
+ assert_non_null(html);
+ assert_string_equal(html, "foo &ndash;");
+ free(html);
+ html = blogc_content_parse_inline("foo ---");
+ assert_non_null(html);
+ assert_string_equal(html, "foo &mdash;");
+ free(html);
+ html = blogc_content_parse_inline("foo \\-\\-");
+ assert_non_null(html);
+ assert_string_equal(html, "foo --");
+ free(html);
+ html = blogc_content_parse_inline("foo \\-\\-\\-");
+ assert_non_null(html);
+ assert_string_equal(html, "foo ---");
+ free(html);
+ html = blogc_content_parse_inline("foo \\---");
+ assert_non_null(html);
+ assert_string_equal(html, "foo -&ndash;");
+ free(html);
+ html = blogc_content_parse_inline("foo \\----");
+ assert_non_null(html);
+ assert_string_equal(html, "foo -&mdash;");
+ free(html);
+ html = blogc_content_parse_inline("foo \\-\\- bar");
+ assert_non_null(html);
+ assert_string_equal(html, "foo -- bar");
+ free(html);
+ html = blogc_content_parse_inline("foo \\-\\-\\- bar");
+ assert_non_null(html);
+ assert_string_equal(html, "foo --- bar");
+ free(html);
+ html = blogc_content_parse_inline("foo \\--- bar");
+ assert_non_null(html);
+ assert_string_equal(html, "foo -&ndash; bar");
+ free(html);
+ html = blogc_content_parse_inline("foo \\---- bar");
+ assert_non_null(html);
+ assert_string_equal(html, "foo -&mdash; bar");
+ free(html);
html = blogc_content_parse_inline("`foo -- bar`");
assert_non_null(html);
assert_string_equal(html, "<code>foo -- bar</code>");
diff --git a/tests/check_utils.c b/tests/check_utils.c
index 6a6ceca..31087f1 100644
--- a/tests/check_utils.c
+++ b/tests/check_utils.c
@@ -257,6 +257,18 @@ test_str_replace(void **state)
static void
+test_str_find(void **state)
+{
+ assert_null(sb_str_find(NULL, 'c'));
+ assert_string_equal(sb_str_find("bola", 'l'), "la");
+ assert_string_equal(sb_str_find("bo\\lalala", 'l'), "lala");
+ assert_string_equal(sb_str_find("bola", '\0'), "");
+ assert_null(sb_str_find("bola", 'g'));
+ assert_null(sb_str_find("bo\\la", 'l'));
+}
+
+
+static void
test_strv_join(void **state)
{
char *pieces[] = {"guda","bola", "chunda", NULL};
@@ -529,6 +541,25 @@ test_string_append_printf(void **state)
static void
+test_string_append_escaped(void **state)
+{
+ sb_string_t *str = sb_string_new();
+ str = sb_string_append_escaped(str, NULL);
+ assert_non_null(str);
+ assert_string_equal(str->str, "");
+ assert_int_equal(str->len, 0);
+ assert_int_equal(str->allocated_len, SB_STRING_CHUNK_SIZE);
+ str = sb_string_append_escaped(str, "foo \\a bar \\\\ lol");
+ assert_non_null(str);
+ assert_string_equal(str->str, "foo a bar \\ lol");
+ assert_int_equal(str->len, 15);
+ assert_int_equal(str->allocated_len, SB_STRING_CHUNK_SIZE);
+ assert_null(sb_string_free(str, true));
+ assert_null(sb_string_append_escaped(NULL, "asd"));
+}
+
+
+static void
test_trie_new(void **state)
{
sb_trie_t *trie = sb_trie_new(free);
@@ -934,6 +965,7 @@ main(void)
unit_test(test_str_strip),
unit_test(test_str_split),
unit_test(test_str_replace),
+ unit_test(test_str_find),
unit_test(test_strv_join),
unit_test(test_strv_length),
@@ -945,6 +977,7 @@ main(void)
unit_test(test_string_append),
unit_test(test_string_append_c),
unit_test(test_string_append_printf),
+ unit_test(test_string_append_escaped),
// trie
unit_test(test_trie_new),