From 07d3a1f7a2bdfa4f5918b515d617eecbd6e081db Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Thu, 13 Aug 2015 22:05:20 -0300 Subject: content-parser: implemented multiline support for lists --- tests/check_content_parser.c | 96 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 89 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/check_content_parser.c b/tests/check_content_parser.c index 1eb2aa5..b9f83b0 100644 --- a/tests/check_content_parser.c +++ b/tests/check_content_parser.c @@ -19,6 +19,24 @@ #include "../src/utils/utils.h" +static void +test_is_ordered_list_item(void **state) +{ + assert_true(blogc_is_ordered_list_item("1.bola", 2)); + assert_true(blogc_is_ordered_list_item("1. bola", 3)); + assert_true(blogc_is_ordered_list_item("12. bola", 4)); + assert_true(blogc_is_ordered_list_item("123. bola", 5)); + assert_true(blogc_is_ordered_list_item("1. bola", 6)); + assert_true(blogc_is_ordered_list_item("1. bola", 5)); + assert_false(blogc_is_ordered_list_item("1bola", 1)); + assert_false(blogc_is_ordered_list_item("12bola", 2)); + assert_false(blogc_is_ordered_list_item("1 . bola", 6)); + assert_false(blogc_is_ordered_list_item("1. bola", 6)); + assert_false(blogc_is_ordered_list_item("1.", 2)); + assert_false(blogc_is_ordered_list_item(NULL, 2)); +} + + static void test_content_parse(void **state) { @@ -368,6 +386,40 @@ test_content_parse_unordered_list(void **state) "\n" "

fuuuu

\n"); free(html); + html = blogc_content_parse( + "lol\n" + "\n" + "* asd\n" + " cvb\n" + "* qwe\n" + "* zxc\n" + " 1234\n" + "\n" + "fuuuu\n", NULL); + assert_non_null(html); + assert_string_equal(html, + "

lol

\n" + "\n" + "

fuuuu

\n"); + free(html); + html = blogc_content_parse( + "* asd\n" + "* qwe\n" + "* zxc", NULL); + assert_non_null(html); + assert_string_equal(html, + "\n"); + free(html); } @@ -423,21 +475,37 @@ test_content_parse_ordered_list(void **state) "

fuuuu

\n"); free(html); html = blogc_content_parse( - "1.\nasd\n" - "2. qwe\n", NULL); + "lol\n" + "\n" + "1. asd\n" + " cvb\n" + "2. qwe\n" + "3. zxc\n" + " 1234\n" + "\n" + "fuuuu\n", NULL); assert_non_null(html); assert_string_equal(html, - "

1.\n" - "asd

\n" + "

lol

\n" "
    \n" + "
  1. asd\n" + "cvb
  2. \n" "
  3. qwe
  4. \n" - "
\n"); + "
  • zxc\n" + "1234
  • \n" + "\n" + "

    fuuuu

    \n"); free(html); - html = blogc_content_parse("1.\n", NULL); + html = blogc_content_parse( + "1. asd\n" + "2. qwe\n" + "3. zxc", NULL); assert_non_null(html); assert_string_equal(html, "
      \n" - "
    1. \n" + "
    2. asd
    3. \n" + "
    4. qwe
    5. \n" + "
    6. zxc
    7. \n" "
    \n"); free(html); } @@ -719,6 +787,19 @@ test_content_parse_invalid_ordered_list(void **state) "

    a. asd\n" "2. qwe

    \n"); free(html); + html = blogc_content_parse( + "1.\nasd\n" + "2. qwe\n", 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); + assert_non_null(html); + assert_string_equal(html, "

    1.

    \n"); + free(html); } @@ -1038,6 +1119,7 @@ int main(void) { const UnitTest tests[] = { + unit_test(test_is_ordered_list_item), unit_test(test_content_parse), unit_test(test_content_parse_with_excerpt), unit_test(test_content_parse_header), -- cgit v1.2.3-18-g5258