From 9385055b8bfc6a8eaa7f543b0cd42373c4751ba2 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Wed, 27 May 2015 04:00:15 -0300 Subject: content-parser: random fixes and more tests for inline content parser --- tests/check_content_parser.c | 200 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 200 insertions(+) (limited to 'tests/check_content_parser.c') diff --git a/tests/check_content_parser.c b/tests/check_content_parser.c index 4f46be8..9ed8a0e 100644 --- a/tests/check_content_parser.c +++ b/tests/check_content_parser.c @@ -610,6 +610,7 @@ test_content_parse_inline(void **state) char *html = blogc_content_parse_inline( "**bola***asd* [![lol](http://google.com/lol.png) **lol** " "\\[asd\\]\\(qwe\\)](http://google.com) ``chunda``"); + assert_non_null(html); assert_string_equal(html, "bolaasd " "chunda"); free(html); html = blogc_content_parse_inline("*bola*"); + assert_non_null(html); + assert_string_equal(html, "bola"); + free(html); +} + + +void +test_content_parse_inline_em(void **state) +{ + char *html = blogc_content_parse_inline("*bola*"); + assert_non_null(html); assert_string_equal(html, "bola"); free(html); + html = blogc_content_parse_inline("*bola*\n"); + assert_non_null(html); + assert_string_equal(html, "bola\n"); + free(html); + html = blogc_content_parse_inline("_bola_"); + assert_non_null(html); + assert_string_equal(html, "bola"); + free(html); + html = blogc_content_parse_inline("_bola_\n"); + assert_non_null(html); + 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); + // this is not really valid + html = blogc_content_parse_inline("_**bola\n"); + assert_non_null(html); + assert_string_equal(html, "bola\n"); + free(html); +} + + +void +test_content_parse_inline_strong(void **state) +{ + char *html = blogc_content_parse_inline("**bola**"); + assert_non_null(html); + assert_string_equal(html, "bola"); + free(html); + html = blogc_content_parse_inline("**bola**\n"); + assert_non_null(html); + assert_string_equal(html, "bola\n"); + free(html); + html = blogc_content_parse_inline("__bola__"); + assert_non_null(html); + assert_string_equal(html, "bola"); + free(html); + html = blogc_content_parse_inline("__bola__\n"); + assert_non_null(html); + 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); + // this is not really valid + html = blogc_content_parse_inline("__*bola\n"); + assert_non_null(html); + assert_string_equal(html, "bola\n"); + free(html); +} + + +void +test_content_parse_inline_code(void **state) +{ + char *html = blogc_content_parse_inline("``bola``"); + assert_non_null(html); + assert_string_equal(html, "bola"); + free(html); + html = blogc_content_parse_inline("``bola``\n"); + assert_non_null(html); + assert_string_equal(html, "bola\n"); + free(html); + html = blogc_content_parse_inline("`bola`"); + assert_non_null(html); + assert_string_equal(html, "bola"); + free(html); + html = blogc_content_parse_inline("`bola`\n"); + assert_non_null(html); + assert_string_equal(html, "bola\n"); + free(html); + html = blogc_content_parse_inline("``bo*la``\n"); + assert_non_null(html); + assert_string_equal(html, "bo*la\n"); + free(html); + // invalid + html = blogc_content_parse_inline("``bola\n"); + assert_non_null(html); + 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); + html = blogc_content_parse_inline("``bola`\n"); + assert_non_null(html); + assert_string_equal(html, "bola\n"); + free(html); +} + + +void +test_content_parse_inline_link(void **state) +{ + char *html = blogc_content_parse_inline("[bola](http://example.org/)"); + assert_non_null(html); + assert_string_equal(html, "bola"); + free(html); + html = blogc_content_parse_inline("[bola](http://example.org/)\n"); + assert_non_null(html); + assert_string_equal(html, "bola\n"); + free(html); + html = blogc_content_parse_inline("[bola]\n(http://example.org/)\n"); + assert_non_null(html); + assert_string_equal(html, "bola\n"); + free(html); + html = blogc_content_parse_inline("[bo\nla](http://example.org/)\n"); + assert_non_null(html); + assert_string_equal(html, "bo\nla\n"); + free(html); + // "invalid" + html = blogc_content_parse_inline("[bola](\nhttp://example.org/)\n"); + assert_non_null(html); + assert_string_equal(html, "bola\n"); + free(html); + // invalid + html = blogc_content_parse_inline("[bola](http://example.org/\n"); + assert_non_null(html); + assert_string_equal(html, ""); // FIXME + free(html); +} + + +void +test_content_parse_inline_image(void **state) +{ + char *html = blogc_content_parse_inline("![bola](http://example.org/)"); + assert_non_null(html); + assert_string_equal(html, "\"bola\""); + free(html); + html = blogc_content_parse_inline("![bola](http://example.org/)\n"); + assert_non_null(html); + assert_string_equal(html, "\"bola\"\n"); + free(html); + html = blogc_content_parse_inline("![bola]\n(http://example.org/)\n"); + assert_non_null(html); + assert_string_equal(html, "\"bola\"\n"); + free(html); + // "invalid" + html = blogc_content_parse_inline("![bo\nla](http://example.org/)\n"); + assert_non_null(html); + assert_string_equal(html, "\"bo\nla\"\n"); + free(html); + html = blogc_content_parse_inline("![bola](\nhttp://example.org/)\n"); + assert_non_null(html); + assert_string_equal(html, "\"bola\"\n"); + free(html); + // invalid + html = blogc_content_parse_inline("![bola](http://example.org/\n"); + assert_non_null(html); + assert_string_equal(html, ""); // FIXME + free(html); +} + + +void +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
\n"); + free(html); + html = blogc_content_parse_inline("asd "); + assert_non_null(html); + assert_string_equal(html, "asd
\n"); + free(html); + html = blogc_content_parse_inline("asd "); + assert_non_null(html); + assert_string_equal(html, "asd
\n"); + free(html); + // invalid + html = blogc_content_parse_inline("asd "); + assert_non_null(html); + assert_string_equal(html, "asd "); + free(html); + html = blogc_content_parse_inline("asd \n"); + assert_non_null(html); + assert_string_equal(html, "asd \n"); + free(html); } @@ -642,6 +836,12 @@ main(void) unit_test(test_content_parse_invalid_unordered_list), unit_test(test_content_parse_invalid_ordered_list), unit_test(test_content_parse_inline), + unit_test(test_content_parse_inline_em), + unit_test(test_content_parse_inline_strong), + unit_test(test_content_parse_inline_code), + unit_test(test_content_parse_inline_link), + unit_test(test_content_parse_inline_image), + unit_test(test_content_parse_inline_line_break), }; return run_tests(tests); } -- cgit v1.2.3-18-g5258