diff options
| author | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2015-06-13 03:32:21 -0300 | 
|---|---|---|
| committer | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2015-06-13 03:32:21 -0300 | 
| commit | 3aeccf252c8c266b51c1a2cc1dc9e9e3d5bf2f90 (patch) | |
| tree | bc7a75a51d2fbf180c9d63ee1164b93ca21b9b6f /tests | |
| parent | 168de93a068e489eb96c541172de5e43e13a5873 (diff) | |
| download | blogc-3aeccf252c8c266b51c1a2cc1dc9e9e3d5bf2f90.tar.gz blogc-3aeccf252c8c266b51c1a2cc1dc9e9e3d5bf2f90.tar.bz2 blogc-3aeccf252c8c266b51c1a2cc1dc9e9e3d5bf2f90.zip  | |
content-parser: implemented excerpt, and now for good!
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/check_content_parser.c | 210 | ||||
| -rw-r--r-- | tests/check_loader.c | 3 | ||||
| -rw-r--r-- | tests/check_source_parser.c | 54 | 
3 files changed, 219 insertions, 48 deletions
diff --git a/tests/check_content_parser.c b/tests/check_content_parser.c index 9b1d318..f19d7dc 100644 --- a/tests/check_content_parser.c +++ b/tests/check_content_parser.c @@ -22,6 +22,7 @@  static void  test_content_parse(void **state)  { +    size_t l = 0;      char *html = blogc_content_parse(          "# um\n"          "## dois\n" @@ -57,8 +58,9 @@ test_content_parse(void **state)          "guda\n"          "yay\n"          "\n" -        "**bola**\n"); +        "**bola**\n", &l);      assert_non_null(html); +    assert_int_equal(l, 0);      assert_string_equal(html,          "<h1>um</h1>\n"          "<h2>dois</h2>\n" @@ -95,14 +97,56 @@ test_content_parse(void **state)  } +static void +test_content_parse_with_excerpt(void **state) +{ +    size_t l = 0; +    char *html = blogc_content_parse( +        "# test\n" +        "\n" +        "chunda\n" +        "\n" +        "..\n" +        "\n" +        "guda\n" +        "lol", &l); +    assert_non_null(html); +    assert_int_equal(l, 28); +    assert_string_equal(html, +        "<h1>test</h1>\n" +        "<p>chunda</p>\n" +        "<p>guda\n" +        "lol</p>\n"); +    free(html); +    l = 0; +    html = blogc_content_parse( +        "# test\n" +        "\n" +        "chunda\n" +        "\n" +        "...\n" +        "\n" +        "guda\n" +        "lol", &l); +    assert_non_null(html); +    assert_int_equal(l, 28); +    assert_string_equal(html, +        "<h1>test</h1>\n" +        "<p>chunda</p>\n" +        "<p>guda\n" +        "lol</p>\n"); +    free(html); +} + +  void  test_content_parse_header(void **state)  { -    char *html = blogc_content_parse("## bola"); +    char *html = blogc_content_parse("## bola", NULL);      assert_non_null(html);      assert_string_equal(html, "<h2>bola</h2>\n");      free(html); -    html = blogc_content_parse("## bola\n"); +    html = blogc_content_parse("## bola\n", NULL);      assert_non_null(html);      assert_string_equal(html, "<h2>bola</h2>\n");      free(html); @@ -111,7 +155,7 @@ test_content_parse_header(void **state)          "\n"          "## bola\n"          "\n" -        "guda\n"); +        "guda\n", NULL);      assert_non_null(html);      assert_string_equal(html,          "<p>bola</p>\n" @@ -124,11 +168,11 @@ test_content_parse_header(void **state)  void  test_content_parse_html(void **state)  { -    char *html = blogc_content_parse("<div>\n</div>"); +    char *html = blogc_content_parse("<div>\n</div>", NULL);      assert_non_null(html);      assert_string_equal(html, "<div>\n</div>\n");      free(html); -    html = blogc_content_parse("<div>\n</div>\n"); +    html = blogc_content_parse("<div>\n</div>\n", NULL);      assert_non_null(html);      assert_string_equal(html, "<div>\n</div>\n");      free(html); @@ -138,7 +182,7 @@ test_content_parse_html(void **state)          "<div>\n"          "</div>\n"          "\n" -        "chunda\n"); +        "chunda\n", NULL);      assert_non_null(html);      assert_string_equal(html,          "<p>bola</p>\n" @@ -151,14 +195,14 @@ test_content_parse_html(void **state)  void  test_content_parse_blockquote(void **state)  { -    char *html = blogc_content_parse(">  bola\n>  guda"); +    char *html = blogc_content_parse(">  bola\n>  guda", NULL);      assert_non_null(html);      assert_string_equal(html,          "<blockquote><p>bola\n"          "guda</p>\n"          "</blockquote>\n");      free(html); -    html = blogc_content_parse(">  bola\n>  guda\n"); +    html = blogc_content_parse(">  bola\n>  guda\n", NULL);      assert_non_null(html);      assert_string_equal(html,          "<blockquote><p>bola\n" @@ -171,7 +215,7 @@ test_content_parse_blockquote(void **state)          ">   bola\n"          ">   guda\n"          "\n" -        "chunda\n"); +        "chunda\n", NULL);      assert_non_null(html);      assert_string_equal(html,          "<p>bola</p>\n" @@ -186,13 +230,13 @@ test_content_parse_blockquote(void **state)  void  test_content_parse_code(void **state)  { -    char *html = blogc_content_parse("  bola\n  guda"); +    char *html = blogc_content_parse("  bola\n  guda", NULL);      assert_non_null(html);      assert_string_equal(html,          "<pre><code>bola\n"          "guda</code></pre>\n");      free(html); -    html = blogc_content_parse("  bola\n  guda\n"); +    html = blogc_content_parse("  bola\n  guda\n", NULL);      assert_non_null(html);      assert_string_equal(html,          "<pre><code>bola\n" @@ -204,7 +248,7 @@ test_content_parse_code(void **state)          "   bola\n"          "   guda\n"          "\n" -        "chunda\n"); +        "chunda\n", NULL);      assert_non_null(html);      assert_string_equal(html,          "<p>bola</p>\n" @@ -218,28 +262,28 @@ test_content_parse_code(void **state)  void  test_content_parse_horizontal_rule(void **state)  { -    char *html = blogc_content_parse("bola\nguda\n\n**"); +    char *html = blogc_content_parse("bola\nguda\n\n**", NULL);      assert_non_null(html);      assert_string_equal(html,          "<p>bola\n"          "guda</p>\n"          "<hr />\n");      free(html); -    html = blogc_content_parse("bola\nguda\n\n++++"); +    html = blogc_content_parse("bola\nguda\n\n++++", NULL);      assert_non_null(html);      assert_string_equal(html,          "<p>bola\n"          "guda</p>\n"          "<hr />\n");      free(html); -    html = blogc_content_parse("bola\nguda\n\n--\n"); +    html = blogc_content_parse("bola\nguda\n\n--\n", NULL);      assert_non_null(html);      assert_string_equal(html,          "<p>bola\n"          "guda</p>\n"          "<hr />\n");      free(html); -    html = blogc_content_parse("bola\nguda\n\n****\n"); +    html = blogc_content_parse("bola\nguda\n\n****\n", NULL);      assert_non_null(html);      assert_string_equal(html,          "<p>bola\n" @@ -251,7 +295,7 @@ test_content_parse_horizontal_rule(void **state)          "\n"          "**\n"          "\n" -        "chunda\n"); +        "chunda\n", NULL);      assert_non_null(html);      assert_string_equal(html,          "<p>bola</p>\n" @@ -263,7 +307,7 @@ test_content_parse_horizontal_rule(void **state)          "\n"          "----\n"          "\n" -        "chunda\n"); +        "chunda\n", NULL);      assert_non_null(html);      assert_string_equal(html,          "<p>bola</p>\n" @@ -281,7 +325,7 @@ test_content_parse_unordered_list(void **state)          "\n"          "*  asd\n"          "*  qwe\n" -        "*  zxc"); +        "*  zxc", NULL);      assert_non_null(html);      assert_string_equal(html,          "<p>lol</p>\n" @@ -296,7 +340,7 @@ test_content_parse_unordered_list(void **state)          "\n"          "*  asd\n"          "*  qwe\n" -        "*  zxc\n"); +        "*  zxc\n", NULL);      assert_non_null(html);      assert_string_equal(html,          "<p>lol</p>\n" @@ -313,7 +357,7 @@ test_content_parse_unordered_list(void **state)          "*  qwe\n"          "*  zxc\n"          "\n" -        "fuuuu\n"); +        "fuuuu\n", NULL);      assert_non_null(html);      assert_string_equal(html,          "<p>lol</p>\n" @@ -335,7 +379,7 @@ test_content_parse_ordered_list(void **state)          "\n"          "1.  asd\n"          "2.  qwe\n" -        "3.  zxc"); +        "3.  zxc", NULL);      assert_non_null(html);      assert_string_equal(html,          "<p>lol</p>\n" @@ -350,7 +394,7 @@ test_content_parse_ordered_list(void **state)          "\n"          "1.  asd\n"          "2.  qwe\n" -        "3.  zxc\n"); +        "3.  zxc\n", NULL);      assert_non_null(html);      assert_string_equal(html,          "<p>lol</p>\n" @@ -367,7 +411,7 @@ test_content_parse_ordered_list(void **state)          "2.  qwe\n"          "3.  zxc\n"          "\n" -        "fuuuu\n"); +        "fuuuu\n", NULL);      assert_non_null(html);      assert_string_equal(html,          "<p>lol</p>\n" @@ -380,7 +424,7 @@ test_content_parse_ordered_list(void **state)      free(html);      html = blogc_content_parse(          "1.\nasd\n" -        "2. qwe\n"); +        "2. qwe\n", NULL);      assert_non_null(html);      assert_string_equal(html,          "<p>1.\n" @@ -389,7 +433,7 @@ test_content_parse_ordered_list(void **state)          "<li>qwe</li>\n"          "</ol>\n");      free(html); -    html = blogc_content_parse("1.\n"); +    html = blogc_content_parse("1.\n", NULL);      assert_non_null(html);      assert_string_equal(html,          "<ol>\n" @@ -399,13 +443,87 @@ test_content_parse_ordered_list(void **state)  } +static void +test_content_parse_invalid_excerpt(void **state) +{ +    size_t l = 0; +    char *html = blogc_content_parse( +        "# test\n" +        "\n" +        "chunda\n" +        "..\n" +        "\n" +        "guda\n" +        "lol", &l); +    assert_non_null(html); +    assert_int_equal(l, 0); +    assert_string_equal(html, +        "<h1>test</h1>\n" +        "<p>chunda\n" +        "..</p>\n" +        "<p>guda\n" +        "lol</p>\n"); +    free(html); +    l = 0; +    html = blogc_content_parse( +        "# test\n" +        "\n" +        "chunda\n" +        "\n" +        "...\n" +        "guda\n" +        "lol", &l); +    assert_non_null(html); +    assert_int_equal(l, 0); +    assert_string_equal(html, +        "<h1>test</h1>\n" +        "<p>chunda</p>\n" +        "<p>...\n" +        "guda\n" +        "lol</p>\n"); +    free(html); +    l = 0; +    html = blogc_content_parse( +        "# test\n" +        "\n" +        "chunda..\n" +        "\n" +        "guda\n" +        "lol", &l); +    assert_non_null(html); +    assert_int_equal(l, 0); +    assert_string_equal(html, +        "<h1>test</h1>\n" +        "<p>chunda..</p>\n" +        "<p>guda\n" +        "lol</p>\n"); +    free(html); +    l = 0; +    html = blogc_content_parse( +        "# test\n" +        "\n" +        "chunda\n" +        "\n" +        "...guda\n" +        "lol", &l); +    assert_non_null(html); +    assert_int_equal(l, 0); +    assert_string_equal(html, +        "<h1>test</h1>\n" +        "<p>chunda</p>\n" +        "<p>...guda\n" +        "lol</p>\n"); +    free(html); +} + +  void  test_content_parse_invalid_header(void **state)  {      char *html = blogc_content_parse(          "asd\n"          "\n" -        "##bola\n"); +        "##bola\n", NULL);      assert_non_null(html);      assert_string_equal(html,          "<p>asd</p>\n" @@ -422,7 +540,7 @@ test_content_parse_invalid_header_empty(void **state)          "\n"          "##\n"          "\n" -        "qwe\n"); +        "qwe\n", NULL);      assert_non_null(html);      assert_string_equal(html,          "<p>asd</p>\n" @@ -439,7 +557,7 @@ test_content_parse_invalid_blockquote(void **state)      char *html = blogc_content_parse(          ">   asd\n"          "> bola\n" -        ">   foo\n"); +        ">   foo\n", NULL);      assert_non_null(html);      assert_string_equal(html,          "<p>>   asd\n" @@ -455,7 +573,7 @@ test_content_parse_invalid_code(void **state)      char *html = blogc_content_parse(          "    asd\n"          "  bola\n" -        "    foo\n"); +        "    foo\n", NULL);      assert_non_null(html);      assert_string_equal(html,          "<p>    asd\n" @@ -469,11 +587,11 @@ void  test_content_parse_invalid_horizontal_rule(void **state)  {      // this generates invalid html, but... -    char *html = blogc_content_parse("** asd"); +    char *html = blogc_content_parse("** asd", NULL);      assert_non_null(html);      assert_string_equal(html, "<p><strong> asd</p>\n");      free(html); -    html = blogc_content_parse("** asd\n"); +    html = blogc_content_parse("** asd\n", NULL);      assert_non_null(html);      assert_string_equal(html, "<p><strong> asd</p>\n");      free(html); @@ -486,7 +604,7 @@ test_content_parse_invalid_unordered_list(void **state)      // more invalid html      char *html = blogc_content_parse(          "*  asd\n" -        "1. qwe"); +        "1. qwe", NULL);      assert_non_null(html);      assert_string_equal(html,          "<p><em>  asd\n" @@ -495,7 +613,7 @@ test_content_parse_invalid_unordered_list(void **state)      html = blogc_content_parse(          "*  asd\n"          "1. qwe\n" -        "\n"); +        "\n", NULL);      assert_non_null(html);      assert_string_equal(html,          "<p><em>  asd\n" @@ -503,7 +621,7 @@ test_content_parse_invalid_unordered_list(void **state)      free(html);      html = blogc_content_parse(          "*  asd\n" -        "1. qwe\n"); +        "1. qwe\n", NULL);      assert_non_null(html);      assert_string_equal(html,          "<p><em>  asd\n" @@ -511,7 +629,7 @@ test_content_parse_invalid_unordered_list(void **state)      free(html);      html = blogc_content_parse(          "* asd\n" -        "1. qwe\n"); +        "1. qwe\n", NULL);      assert_non_null(html);      assert_string_equal(html,          "<p><em> asd\n" @@ -523,7 +641,7 @@ test_content_parse_invalid_unordered_list(void **state)          "* asd\n"          "1. qwe\n"          "\n" -        "poi\n"); +        "poi\n", NULL);      assert_non_null(html);      assert_string_equal(html,          "<p>chunda</p>\n" @@ -540,7 +658,7 @@ test_content_parse_invalid_ordered_list(void **state)      // more invalid html      char *html = blogc_content_parse(          "1. asd\n" -        "*  qwe"); +        "*  qwe", NULL);      assert_non_null(html);      assert_string_equal(html,          "<p>1. asd\n" @@ -549,7 +667,7 @@ test_content_parse_invalid_ordered_list(void **state)      html = blogc_content_parse(          "1. asd\n"          "*  qwe\n" -        "\n"); +        "\n", NULL);      assert_non_null(html);      assert_string_equal(html,          "<p>1. asd\n" @@ -557,7 +675,7 @@ test_content_parse_invalid_ordered_list(void **state)      free(html);      html = blogc_content_parse(          "1. asd\n" -        "*  qwe\n"); +        "*  qwe\n", NULL);      assert_non_null(html);      assert_string_equal(html,          "<p>1. asd\n" @@ -565,7 +683,7 @@ test_content_parse_invalid_ordered_list(void **state)      free(html);      html = blogc_content_parse(          "1. asd\n" -        "*  qwe\n"); +        "*  qwe\n", NULL);      assert_non_null(html);      assert_string_equal(html,          "<p>1. asd\n" @@ -577,7 +695,7 @@ test_content_parse_invalid_ordered_list(void **state)          "1. asd\n"          "*  qwe\n"          "\n" -        "poi\n"); +        "poi\n", NULL);      assert_non_null(html);      assert_string_equal(html,          "<p>chunda</p>\n" @@ -587,7 +705,7 @@ test_content_parse_invalid_ordered_list(void **state)      free(html);      html = blogc_content_parse(          "1 asd\n" -        "* qwe\n"); +        "* qwe\n", NULL);      assert_non_null(html);      assert_string_equal(html,          "<p>1 asd\n" @@ -595,7 +713,7 @@ test_content_parse_invalid_ordered_list(void **state)      free(html);      html = blogc_content_parse(          "a. asd\n" -        "2. qwe\n"); +        "2. qwe\n", NULL);      assert_non_null(html);      assert_string_equal(html,          "<p>a. asd\n" @@ -913,6 +1031,7 @@ main(void)  {      const UnitTest tests[] = {          unit_test(test_content_parse), +        unit_test(test_content_parse_with_excerpt),          unit_test(test_content_parse_header),          unit_test(test_content_parse_html),          unit_test(test_content_parse_blockquote), @@ -920,6 +1039,7 @@ main(void)          unit_test(test_content_parse_horizontal_rule),          unit_test(test_content_parse_unordered_list),          unit_test(test_content_parse_ordered_list), +        unit_test(test_content_parse_invalid_excerpt),          unit_test(test_content_parse_invalid_header),          unit_test(test_content_parse_invalid_header_empty),          unit_test(test_content_parse_invalid_blockquote), diff --git a/tests/check_loader.c b/tests/check_loader.c index 865d598..f5be3e7 100644 --- a/tests/check_loader.c +++ b/tests/check_loader.c @@ -113,9 +113,10 @@ test_source_parse_from_file(void **state)      b_trie_t *t = blogc_source_parse_from_file("bola.txt", &err);      assert_null(err);      assert_non_null(t); -    assert_int_equal(b_trie_size(t), 4); +    assert_int_equal(b_trie_size(t), 5);      assert_string_equal(b_trie_lookup(t, "ASD"), "123");      assert_string_equal(b_trie_lookup(t, "FILENAME"), "bola"); +    assert_string_equal(b_trie_lookup(t, "EXCERPT"), "<p>bola</p>\n");      assert_string_equal(b_trie_lookup(t, "CONTENT"), "<p>bola</p>\n");      assert_string_equal(b_trie_lookup(t, "RAW_CONTENT"), "bola");      b_trie_free(t); diff --git a/tests/check_source_parser.c b/tests/check_source_parser.c index 0cec364..79ca10f 100644 --- a/tests/check_source_parser.c +++ b/tests/check_source_parser.c @@ -34,9 +34,12 @@ test_source_parse(void **state)      b_trie_t *source = blogc_source_parse(a, strlen(a), &err);      assert_null(err);      assert_non_null(source); -    assert_int_equal(b_trie_size(source), 4); +    assert_int_equal(b_trie_size(source), 5);      assert_string_equal(b_trie_lookup(source, "VAR1"), "asd asd");      assert_string_equal(b_trie_lookup(source, "VAR2"), "123chunda"); +    assert_string_equal(b_trie_lookup(source, "EXCERPT"), +        "<h1>This is a test</h1>\n" +        "<p>bola</p>\n");      assert_string_equal(b_trie_lookup(source, "CONTENT"),          "<h1>This is a test</h1>\n"          "<p>bola</p>\n"); @@ -64,9 +67,12 @@ test_source_parse_with_spaces(void **state)      b_trie_t *source = blogc_source_parse(a, strlen(a), &err);      assert_null(err);      assert_non_null(source); -    assert_int_equal(b_trie_size(source), 4); +    assert_int_equal(b_trie_size(source), 5);      assert_string_equal(b_trie_lookup(source, "VAR1"), "chunda");      assert_string_equal(b_trie_lookup(source, "BOLA"), "guda"); +    assert_string_equal(b_trie_lookup(source, "EXCERPT"), +        "<h1>This is a test</h1>\n" +        "<p>bola</p>\n");      assert_string_equal(b_trie_lookup(source, "CONTENT"),          "<h1>This is a test</h1>\n"          "<p>bola</p>\n"); @@ -79,6 +85,49 @@ test_source_parse_with_spaces(void **state)  static void +test_source_parse_with_excerpt(void **state) +{ +    const char *a = +        "VAR1: asd asd\n" +        "VAR2: 123chunda\n" +        "----------\n" +        "# This is a test\n" +        "\n" +        "bola\n" +        "\n" +        "...\n" +        "\n" +        "guda\n" +        "yay"; +    blogc_error_t *err = NULL; +    b_trie_t *source = blogc_source_parse(a, strlen(a), &err); +    assert_null(err); +    assert_non_null(source); +    assert_int_equal(b_trie_size(source), 5); +    assert_string_equal(b_trie_lookup(source, "VAR1"), "asd asd"); +    assert_string_equal(b_trie_lookup(source, "VAR2"), "123chunda"); +    assert_string_equal(b_trie_lookup(source, "EXCERPT"), +        "<h1>This is a test</h1>\n" +        "<p>bola</p>\n"); +    assert_string_equal(b_trie_lookup(source, "CONTENT"), +        "<h1>This is a test</h1>\n" +        "<p>bola</p>\n" +        "<p>guda\n" +        "yay</p>\n"); +    assert_string_equal(b_trie_lookup(source, "RAW_CONTENT"), +        "# This is a test\n" +        "\n" +        "bola\n" +        "\n" +        "...\n" +        "\n" +        "guda\n" +        "yay"); +    b_trie_free(source); +} + + +static void  test_source_parse_config_empty(void **state)  {      const char *a = ""; @@ -381,6 +430,7 @@ main(void)      const UnitTest tests[] = {          unit_test(test_source_parse),          unit_test(test_source_parse_with_spaces), +        unit_test(test_source_parse_with_excerpt),          unit_test(test_source_parse_config_empty),          unit_test(test_source_parse_config_invalid_key),          unit_test(test_source_parse_config_no_key),  | 
