From 1faa52052624e7c03256df0c63c43f5d40ddb57a Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Mon, 2 Nov 2015 03:58:09 -0200 Subject: content-parser: added basic rst-like directives support this patch adds support to something similar to reStructuredText directives [1]. the directive loader isn't implemented yet. also, the current implementation is stricter and differs a lot from the reStructuredText spec. documentation pending. this patch also fixes a few old parser bugs. [1] http://docutils.sourceforge.net/docs/ref/rst/directives.html --- tests/check_content_parser.c | 620 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 616 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/check_content_parser.c b/tests/check_content_parser.c index 994e900..5d13564 100644 --- a/tests/check_content_parser.c +++ b/tests/check_content_parser.c @@ -1014,6 +1014,405 @@ test_content_parse_ordered_list_crlf(void **state) } +char* +__wrap_blogc_directive_loader(const char *name, const char *argument, + b_trie_t *params) +{ + assert_string_equal(name, mock_type(const char*)); + const char *arg = mock_type(const char*); + if (arg == NULL) + assert_null(argument); + else + assert_string_equal(argument, arg); + assert_int_equal(b_trie_size(params), mock_type(unsigned int)); + + for (unsigned int i = 0; i < b_trie_size(params); i++) + assert_string_equal(b_trie_lookup(params, mock_type(const char*)), + mock_type(const char*)); + + return b_strdup("CHUNDA\n"); +} + + +static void +test_content_parse_directive(void **state) +{ + will_return(__wrap_blogc_directive_loader, "bola"); + will_return(__wrap_blogc_directive_loader, NULL); + will_return(__wrap_blogc_directive_loader, 0); + char *html = blogc_content_parse( + ".. bola::", + NULL); + assert_non_null(html); + assert_string_equal(html, + "CHUNDA\n"); + free(html); + + will_return(__wrap_blogc_directive_loader, "bola"); + will_return(__wrap_blogc_directive_loader, NULL); + will_return(__wrap_blogc_directive_loader, 0); + html = blogc_content_parse( + ".. bola::\n", + NULL); + assert_non_null(html); + assert_string_equal(html, + "CHUNDA\n"); + free(html); + + will_return(__wrap_blogc_directive_loader, "bola"); + will_return(__wrap_blogc_directive_loader, NULL); + will_return(__wrap_blogc_directive_loader, 0); + html = blogc_content_parse( + ".. bola:: ", + NULL); + assert_non_null(html); + assert_string_equal(html, + "CHUNDA\n"); + free(html); + + will_return(__wrap_blogc_directive_loader, "bola"); + will_return(__wrap_blogc_directive_loader, NULL); + will_return(__wrap_blogc_directive_loader, 0); + html = blogc_content_parse( + ".. bola:: \n", + NULL); + assert_non_null(html); + assert_string_equal(html, + "CHUNDA\n"); + free(html); + + will_return(__wrap_blogc_directive_loader, "bola"); + will_return(__wrap_blogc_directive_loader, NULL); + will_return(__wrap_blogc_directive_loader, 0); + html = blogc_content_parse( + ".. bola::\r\n", + NULL); + assert_non_null(html); + assert_string_equal(html, + "CHUNDA\n"); + free(html); + + will_return(__wrap_blogc_directive_loader, "bola"); + will_return(__wrap_blogc_directive_loader, NULL); + will_return(__wrap_blogc_directive_loader, 1); + will_return(__wrap_blogc_directive_loader, "asd"); + will_return(__wrap_blogc_directive_loader, "qwe"); + html = blogc_content_parse( + ".. bola::\n" + " :asd: qwe", + NULL); + assert_non_null(html); + assert_string_equal(html, + "CHUNDA\n"); + free(html); + + will_return(__wrap_blogc_directive_loader, "bola"); + will_return(__wrap_blogc_directive_loader, NULL); + will_return(__wrap_blogc_directive_loader, 1); + will_return(__wrap_blogc_directive_loader, "asd"); + will_return(__wrap_blogc_directive_loader, "qwe"); + html = blogc_content_parse( + ".. bola::\n" + " :asd: qwe\n", + NULL); + assert_non_null(html); + assert_string_equal(html, + "CHUNDA\n"); + free(html); + + will_return(__wrap_blogc_directive_loader, "bola"); + will_return(__wrap_blogc_directive_loader, NULL); + will_return(__wrap_blogc_directive_loader, 1); + will_return(__wrap_blogc_directive_loader, "asd"); + will_return(__wrap_blogc_directive_loader, "qwe"); + html = blogc_content_parse( + ".. bola::\r\n" + " :asd: qwe\r\n", + NULL); + assert_non_null(html); + assert_string_equal(html, + "CHUNDA\n"); + free(html); + + will_return(__wrap_blogc_directive_loader, "bola"); + will_return(__wrap_blogc_directive_loader, NULL); + will_return(__wrap_blogc_directive_loader, 2); + will_return(__wrap_blogc_directive_loader, "asd"); + will_return(__wrap_blogc_directive_loader, "qwe"); + will_return(__wrap_blogc_directive_loader, "zxc"); + will_return(__wrap_blogc_directive_loader, "vbn"); + html = blogc_content_parse( + ".. bola::\n" + " :asd: qwe\n" + " :zxc: vbn", + NULL); + assert_non_null(html); + assert_string_equal(html, + "CHUNDA\n"); + free(html); + + will_return(__wrap_blogc_directive_loader, "bola"); + will_return(__wrap_blogc_directive_loader, NULL); + will_return(__wrap_blogc_directive_loader, 2); + will_return(__wrap_blogc_directive_loader, "asd"); + will_return(__wrap_blogc_directive_loader, "qwe"); + will_return(__wrap_blogc_directive_loader, "zxc"); + will_return(__wrap_blogc_directive_loader, "vbn"); + html = blogc_content_parse( + ".. bola::\n" + " :asd: qwe\n" + " :zxc: vbn\n", + NULL); + assert_non_null(html); + assert_string_equal(html, + "CHUNDA\n"); + free(html); + + will_return(__wrap_blogc_directive_loader, "bola"); + will_return(__wrap_blogc_directive_loader, NULL); + will_return(__wrap_blogc_directive_loader, 2); + will_return(__wrap_blogc_directive_loader, "asd"); + will_return(__wrap_blogc_directive_loader, "qwe"); + will_return(__wrap_blogc_directive_loader, "zxc"); + will_return(__wrap_blogc_directive_loader, "vbn"); + html = blogc_content_parse( + ".. bola::\r\n" + " :asd: qwe\r\n" + " :zxc: vbn\r\n", + NULL); + assert_non_null(html); + assert_string_equal(html, + "CHUNDA\n"); + free(html); + + will_return(__wrap_blogc_directive_loader, "bola"); + will_return(__wrap_blogc_directive_loader, NULL); + will_return(__wrap_blogc_directive_loader, 3); + will_return(__wrap_blogc_directive_loader, "asd"); + will_return(__wrap_blogc_directive_loader, "qwe"); + will_return(__wrap_blogc_directive_loader, "ert"); + will_return(__wrap_blogc_directive_loader, "zxvc"); + will_return(__wrap_blogc_directive_loader, "qwe"); + will_return(__wrap_blogc_directive_loader, "bola"); + html = blogc_content_parse( + "# foo\n" + "\n" + ".. bola::\n" + " :asd: qwe\n" + " :ert: zxvc\n" + " :qwe: bola\n" + "\n" + "bola", NULL); + assert_non_null(html); + assert_string_equal(html, + "

foo

\n" + "CHUNDA\n" + "

bola

\n"); + free(html); + + will_return(__wrap_blogc_directive_loader, "bola"); + will_return(__wrap_blogc_directive_loader, NULL); + will_return(__wrap_blogc_directive_loader, 3); + will_return(__wrap_blogc_directive_loader, "asd"); + will_return(__wrap_blogc_directive_loader, "qwe"); + will_return(__wrap_blogc_directive_loader, "ert"); + will_return(__wrap_blogc_directive_loader, "zxvc"); + will_return(__wrap_blogc_directive_loader, "qwe"); + will_return(__wrap_blogc_directive_loader, "bola"); + html = blogc_content_parse( + "# foo\r\n" + "\r\n" + ".. bola::\r\n" + " :asd: qwe\r\n" + " :ert: zxvc\r\n" + " :qwe: bola\r\n" + "\r\n" + "bola", NULL); + assert_non_null(html); + assert_string_equal(html, + "

foo

\r\n" + "CHUNDA\n" + "

bola

\r\n"); + free(html); + + will_return(__wrap_blogc_directive_loader, "bola"); + will_return(__wrap_blogc_directive_loader, "chunda"); + will_return(__wrap_blogc_directive_loader, 0); + html = blogc_content_parse( + ".. bola:: chunda", + NULL); + assert_non_null(html); + assert_string_equal(html, + "CHUNDA\n"); + free(html); + + will_return(__wrap_blogc_directive_loader, "bola"); + will_return(__wrap_blogc_directive_loader, "chunda"); + will_return(__wrap_blogc_directive_loader, 0); + html = blogc_content_parse( + ".. bola:: chunda\n", + NULL); + assert_non_null(html); + assert_string_equal(html, + "CHUNDA\n"); + free(html); + + will_return(__wrap_blogc_directive_loader, "bola"); + will_return(__wrap_blogc_directive_loader, "chunda"); + will_return(__wrap_blogc_directive_loader, 0); + html = blogc_content_parse( + ".. bola:: chunda\r\n", + NULL); + assert_non_null(html); + assert_string_equal(html, + "CHUNDA\n"); + free(html); + + will_return(__wrap_blogc_directive_loader, "bola"); + will_return(__wrap_blogc_directive_loader, "chunda"); + will_return(__wrap_blogc_directive_loader, 1); + will_return(__wrap_blogc_directive_loader, "asd"); + will_return(__wrap_blogc_directive_loader, "qwe"); + html = blogc_content_parse( + ".. bola:: chunda\n" + " :asd: qwe", + NULL); + assert_non_null(html); + assert_string_equal(html, + "CHUNDA\n"); + free(html); + + will_return(__wrap_blogc_directive_loader, "bola"); + will_return(__wrap_blogc_directive_loader, "chunda"); + will_return(__wrap_blogc_directive_loader, 1); + will_return(__wrap_blogc_directive_loader, "asd"); + will_return(__wrap_blogc_directive_loader, "qwe"); + html = blogc_content_parse( + ".. bola:: chunda\n" + " :asd: qwe\n", + NULL); + assert_non_null(html); + assert_string_equal(html, + "CHUNDA\n"); + free(html); + + will_return(__wrap_blogc_directive_loader, "bola"); + will_return(__wrap_blogc_directive_loader, "chunda"); + will_return(__wrap_blogc_directive_loader, 1); + will_return(__wrap_blogc_directive_loader, "asd"); + will_return(__wrap_blogc_directive_loader, "qwe"); + html = blogc_content_parse( + ".. bola:: chunda\r\n" + " :asd: qwe\r\n", + NULL); + assert_non_null(html); + assert_string_equal(html, + "CHUNDA\n"); + free(html); + + will_return(__wrap_blogc_directive_loader, "bola"); + will_return(__wrap_blogc_directive_loader, "chunda"); + will_return(__wrap_blogc_directive_loader, 2); + will_return(__wrap_blogc_directive_loader, "asd"); + will_return(__wrap_blogc_directive_loader, "qwe"); + will_return(__wrap_blogc_directive_loader, "zxc"); + will_return(__wrap_blogc_directive_loader, "vbn"); + html = blogc_content_parse( + ".. bola:: chunda\n" + " :asd: qwe\n" + " :zxc: vbn", + NULL); + assert_non_null(html); + assert_string_equal(html, + "CHUNDA\n"); + free(html); + + will_return(__wrap_blogc_directive_loader, "bola"); + will_return(__wrap_blogc_directive_loader, "chunda"); + will_return(__wrap_blogc_directive_loader, 2); + will_return(__wrap_blogc_directive_loader, "asd"); + will_return(__wrap_blogc_directive_loader, "qwe"); + will_return(__wrap_blogc_directive_loader, "zxc"); + will_return(__wrap_blogc_directive_loader, "vbn"); + html = blogc_content_parse( + ".. bola:: chunda\n" + " :asd: qwe\n" + " :zxc: vbn\n", + NULL); + assert_non_null(html); + assert_string_equal(html, + "CHUNDA\n"); + free(html); + + will_return(__wrap_blogc_directive_loader, "bola"); + will_return(__wrap_blogc_directive_loader, "chunda"); + will_return(__wrap_blogc_directive_loader, 2); + will_return(__wrap_blogc_directive_loader, "asd"); + will_return(__wrap_blogc_directive_loader, "qwe"); + will_return(__wrap_blogc_directive_loader, "zxc"); + will_return(__wrap_blogc_directive_loader, "vbn"); + html = blogc_content_parse( + ".. bola:: chunda\r\n" + " :asd: qwe\r\n" + " :zxc: vbn\r\n", + NULL); + assert_non_null(html); + assert_string_equal(html, + "CHUNDA\n"); + free(html); + + will_return(__wrap_blogc_directive_loader, "bola"); + will_return(__wrap_blogc_directive_loader, "chunda"); + will_return(__wrap_blogc_directive_loader, 3); + will_return(__wrap_blogc_directive_loader, "asd"); + will_return(__wrap_blogc_directive_loader, "qwe"); + will_return(__wrap_blogc_directive_loader, "ert"); + will_return(__wrap_blogc_directive_loader, "zxvc"); + will_return(__wrap_blogc_directive_loader, "qwe"); + will_return(__wrap_blogc_directive_loader, "bola"); + html = blogc_content_parse( + "# foo\n" + "\n" + ".. bola:: chunda\n" + " :asd: qwe\n" + " :ert: zxvc\n" + " :qwe: bola\n" + "\n" + "bola", NULL); + assert_non_null(html); + assert_string_equal(html, + "

foo

\n" + "CHUNDA\n" + "

bola

\n"); + free(html); + + will_return(__wrap_blogc_directive_loader, "bola"); + will_return(__wrap_blogc_directive_loader, "chunda"); + will_return(__wrap_blogc_directive_loader, 3); + will_return(__wrap_blogc_directive_loader, "asd"); + will_return(__wrap_blogc_directive_loader, "qwe"); + will_return(__wrap_blogc_directive_loader, "ert"); + will_return(__wrap_blogc_directive_loader, "zxvc"); + will_return(__wrap_blogc_directive_loader, "qwe"); + will_return(__wrap_blogc_directive_loader, "bola"); + html = blogc_content_parse( + "# foo\r\n" + "\r\n" + ".. bola:: chunda\r\n" + " :asd: qwe\r\n" + " :ert: zxvc\r\n" + " :qwe: bola\r\n" + "\r\n" + "bola", NULL); + assert_non_null(html); + assert_string_equal(html, + "

foo

\r\n" + "CHUNDA\n" + "

bola

\r\n"); + free(html); +} + + static void test_content_parse_invalid_excerpt(void **state) { @@ -1135,6 +1534,14 @@ test_content_parse_invalid_blockquote(void **state) "> bola\n" "> foo

\n"); free(html); + html = blogc_content_parse( + "> asd\n" + "> bola", NULL); + assert_non_null(html); + assert_string_equal(html, + "

> asd\n" + "> bola

\n"); + free(html); } @@ -1151,6 +1558,16 @@ test_content_parse_invalid_code(void **state) " bola\n" " foo

\n"); free(html); + html = blogc_content_parse( + " asd\n" + " bola\n" + " foo", NULL); + assert_non_null(html); + assert_string_equal(html, + "

asd\n" + " bola\n" + " foo

\n"); + free(html); } @@ -1196,7 +1613,8 @@ test_content_parse_invalid_unordered_list(void **state) assert_non_null(html); assert_string_equal(html, "

asd\n" - "1. qwe

\n"); + "1. qwe" + "

\n"); free(html); html = blogc_content_parse( "* asd\n" @@ -1204,7 +1622,8 @@ test_content_parse_invalid_unordered_list(void **state) assert_non_null(html); assert_string_equal(html, "

asd\n" - "1. qwe

\n"); + "1. qwe" + "

\n"); free(html); html = blogc_content_parse( "chunda\n" @@ -1250,7 +1669,8 @@ test_content_parse_invalid_ordered_list(void **state) assert_non_null(html); assert_string_equal(html, "

1. asd\n" - " qwe

\n"); + " qwe" + "

\n"); free(html); html = blogc_content_parse( "1. asd\n" @@ -1258,7 +1678,8 @@ test_content_parse_invalid_ordered_list(void **state) assert_non_null(html); assert_string_equal(html, "

1. asd\n" - " qwe

\n"); + " qwe" + "

\n"); free(html); html = blogc_content_parse( "chunda\n" @@ -1303,6 +1724,195 @@ test_content_parse_invalid_ordered_list(void **state) assert_non_null(html); assert_string_equal(html, "

1.

\n"); free(html); + html = blogc_content_parse("1 ", NULL); + assert_non_null(html); + assert_string_equal(html, "

1

\n"); + free(html); +} + + +static void +test_content_parse_invalid_directive(void **state) +{ + char *html = blogc_content_parse( + ".. ", + NULL); + assert_non_null(html); + assert_string_equal(html, + "

..

\n"); + free(html); + + html = blogc_content_parse( + ".. \n", + NULL); + assert_non_null(html); + assert_string_equal(html, + "

..

\n"); + free(html); + + html = blogc_content_parse( + ".. ", + NULL); + assert_non_null(html); + assert_string_equal(html, + "

..

\n"); + free(html); + + html = blogc_content_parse( + ".. \n", + NULL); + assert_non_null(html); + assert_string_equal(html, + "

..

\n"); + free(html); + + html = blogc_content_parse( + ".. a", + NULL); + assert_non_null(html); + assert_string_equal(html, + "

.. a

\n"); + free(html); + + html = blogc_content_parse( + ".. a\n", + NULL); + assert_non_null(html); + assert_string_equal(html, + "

.. a

\n"); + free(html); + + html = blogc_content_parse( + ".. asd", + NULL); + assert_non_null(html); + assert_string_equal(html, + "

.. asd

\n"); + free(html); + + html = blogc_content_parse( + ".. asd\n", + NULL); + assert_non_null(html); + assert_string_equal(html, + "

.. asd

\n"); + free(html); + + html = blogc_content_parse( + ".. asd:", + NULL); + assert_non_null(html); + assert_string_equal(html, + "

.. asd:

\n"); + free(html); + + html = blogc_content_parse( + ".. asd:\n", + NULL); + assert_non_null(html); + assert_string_equal(html, + "

.. asd:

\n"); + free(html); + + html = blogc_content_parse( + ".. asd::\n" + " :", + NULL); + assert_non_null(html); + assert_string_equal(html, + "

.. asd::\n" + " :

\n"); + free(html); + + html = blogc_content_parse( + ".. asd::\n" + " :\n", + NULL); + assert_non_null(html); + assert_string_equal(html, + "

.. asd::\n" + " :

\n"); + free(html); + + html = blogc_content_parse( + ".. asd::\n" + " :a", + NULL); + assert_non_null(html); + assert_string_equal(html, + "

.. asd::\n" + " :a

\n"); + free(html); + + html = blogc_content_parse( + ".. asd::\n" + " :a\n", + NULL); + assert_non_null(html); + assert_string_equal(html, + "

.. asd::\n" + " :a

\n"); + free(html); + + html = blogc_content_parse( + ".. asd::\n" + " :as", + NULL); + assert_non_null(html); + assert_string_equal(html, + "

.. asd::\n" + " :as

\n"); + free(html); + + html = blogc_content_parse( + ".. asd::\n" + " :as\n", + NULL); + assert_non_null(html); + assert_string_equal(html, + "

.. asd::\n" + " :as

\n"); + free(html); + + html = blogc_content_parse( + ".. asd::\n" + " :as:", + NULL); + assert_non_null(html); + assert_string_equal(html, + "

.. asd::\n" + " :as:

\n"); + free(html); + + html = blogc_content_parse( + ".. asd::\n" + " :as:\n", + NULL); + assert_non_null(html); + assert_string_equal(html, + "

.. asd::\n" + " :as:

\n"); + free(html); + + html = blogc_content_parse( + ".. asd::\n" + " :as: ", + NULL); + assert_non_null(html); + assert_string_equal(html, + "

.. asd::\n" + " :as:

\n"); + free(html); + + html = blogc_content_parse( + ".. asd::\n" + " :as: \n", + NULL); + assert_non_null(html); + assert_string_equal(html, + "

.. asd::\n" + " :as:

\n"); + free(html); } @@ -1656,6 +2266,7 @@ 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_directive), unit_test(test_content_parse_invalid_excerpt), unit_test(test_content_parse_invalid_header), unit_test(test_content_parse_invalid_header_empty), @@ -1664,6 +2275,7 @@ main(void) unit_test(test_content_parse_invalid_horizontal_rule), unit_test(test_content_parse_invalid_unordered_list), unit_test(test_content_parse_invalid_ordered_list), + unit_test(test_content_parse_invalid_directive), unit_test(test_content_parse_inline), unit_test(test_content_parse_inline_em), unit_test(test_content_parse_inline_strong), -- cgit v1.2.3-18-g5258