diff options
author | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2020-04-22 02:06:37 +0200 |
---|---|---|
committer | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2020-04-22 02:06:37 +0200 |
commit | 8404096582103dccb8885b0c404f0a756685e913 (patch) | |
tree | 97d74ba2dd9591f55bd4284de6d40ba673eb8bec /tests | |
parent | 67c856608a746b5205300d3f8141a6a29d3cc89e (diff) | |
download | blogc-8404096582103dccb8885b0c404f0a756685e913.tar.gz blogc-8404096582103dccb8885b0c404f0a756685e913.tar.bz2 blogc-8404096582103dccb8885b0c404f0a756685e913.zip |
blogc: allow passing multiple -e options
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/blogc/check_blogc.sh.in | 109 | ||||
-rw-r--r-- | tests/blogc/check_renderer.c | 131 |
2 files changed, 237 insertions, 3 deletions
diff --git a/tests/blogc/check_blogc.sh.in b/tests/blogc/check_blogc.sh.in index 3e0b8d7..87b71fa 100755 --- a/tests/blogc/check_blogc.sh.in +++ b/tests/blogc/check_blogc.sh.in @@ -170,7 +170,7 @@ cat > "${TEMP}/main.tmpl" <<EOF <title>{% ifdef FOO1 %}{{ FOO1 }} {% endif %}{% block entry %}{{ TITLE }}{% endblock %}{% block listing_once %}{{ SITE_TITLE }}{% endblock %}</title> </head> <body> - <a href="{{ BASE_URL }}/"><div class="name">{{ SITE_TITLE }}</div></a>{% block listing_entry %}{{ CONTENT }}{% endblock %} + <a href="{{ BASE_URL }}/"><div class="name">{{ SITE_TITLE }}</div></a>{% block listing_entry %}{{ CONTENT }}{% endblock %}{% block listing_entry %}{{ CONTENT }}{% endblock %} {% block listing_once %} <section class="main"> <div class="container"> @@ -469,6 +469,113 @@ echo -e "${TEMP}/post1.txt\n${TEMP}/post2.txt" | ${TESTS_ENVIRONMENT} @abs_top_b diff -uN "${TEMP}/output12.html" "${TEMP}/expected-output3.html" +cat > "${TEMP}/expected-output4.html" <<EOF +<!DOCTYPE html> +<html lang="en"> + <head> + <title>Chunda's website</title> + </head> + <body> + <a href="/"><div class="name">Chunda's website</div></a><p>foo?</p> + + + <section class="main"> + <div class="container"> + <div class="content"> + <div class="page-heading">Blog</div> + <ul> + + + <li class="post-item"> + <div class="meta">Jan 01, 2010, 11:11 AM GMT</div> + <a href="/post/post1/"><div>foo</div></a> + </li> + + <li class="post-item"> + <div class="meta">Jan 01, 2010, 10:22 PM GMT</div> + <a href="/post/post2/"><div>bar</div></a> + </li> + + + </ul> + </div> + </div> + </section> + + + </body> +</html> +EOF + +${TESTS_ENVIRONMENT} @abs_top_builddir@/blogc \ + -D BASE_DOMAIN=http://bola.com/ \ + -D BASE_URL= \ + -D SITE_TITLE="Chunda's website" \ + -D DATE_FORMAT="%b %d, %Y, %I:%M %p GMT" \ + -e "" \ + -e "${TEMP}/post1.txt" \ + -e "${TEMP}/post3.txt" \ + -t "${TEMP}/main.tmpl" \ + -o "${TEMP}/output13.html" \ + -l \ + "${TEMP}/post1.txt" "${TEMP}/post2.txt" + +diff -uN "${TEMP}/output13.html" "${TEMP}/expected-output4.html" + + +cat > "${TEMP}/expected-output5.html" <<EOF +<!DOCTYPE html> +<html lang="en"> + <head> + <title>Chunda's website</title> + </head> + <body> + <a href="/"><div class="name">Chunda's website</div></a><p>foo?</p> +<p>bar?</p> + + + <section class="main"> + <div class="container"> + <div class="content"> + <div class="page-heading">Blog</div> + <ul> + + + <li class="post-item"> + <div class="meta">Jan 01, 2010, 11:11 AM GMT</div> + <a href="/post/post1/"><div>foo</div></a> + </li> + + <li class="post-item"> + <div class="meta">Jan 01, 2010, 10:22 PM GMT</div> + <a href="/post/post2/"><div>bar</div></a> + </li> + + + </ul> + </div> + </div> + </section> + + + </body> +</html> +EOF + +${TESTS_ENVIRONMENT} @abs_top_builddir@/blogc \ + -D BASE_DOMAIN=http://bola.com/ \ + -D BASE_URL= \ + -D SITE_TITLE="Chunda's website" \ + -D DATE_FORMAT="%b %d, %Y, %I:%M %p GMT" \ + -e "${TEMP}/post1.txt" \ + -e "${TEMP}/post3.txt" \ + -t "${TEMP}/main.tmpl" \ + -o "${TEMP}/output14.html" \ + -l \ + "${TEMP}/post1.txt" "${TEMP}/post2.txt" + +diff -uN "${TEMP}/output14.html" "${TEMP}/expected-output5.html" + echo "{% block listig %}foo{% endblock %}\n" > "${TEMP}/error.tmpl" ${TESTS_ENVIRONMENT} @abs_top_builddir@/blogc \ diff --git a/tests/blogc/check_renderer.c b/tests/blogc/check_renderer.c index 479c239..c1a9f9d 100644 --- a/tests/blogc/check_renderer.c +++ b/tests/blogc/check_renderer.c @@ -234,13 +234,75 @@ test_render_listing_entry2(void **state) bc_trie_t *entry = bc_trie_new(free); bc_trie_insert(entry, "FUUUUU", bc_strdup("XD")); bc_trie_insert(entry, "BAAAAA", bc_strdup(":p")); - char *out = blogc_render(l, s, entry, NULL, true); - bc_trie_free(entry); + bc_slist_t *e = NULL; + e = bc_slist_append(e, entry); + char *out = blogc_render(l, s, e, NULL, true); + bc_slist_free_full(e, (bc_free_func_t) bc_trie_free); assert_string_equal(out, "foo\n" "fuuu\n" "\n" "XD\n" + "\n" + "\n" + "03:04\n" + "bola: asd\n" + "lol foo haha lol bar haha lol baz haha \n" + "\n" + "\n" + "2014-02-03 04:05:06\n" + "bola: asd2\n" + "\n" + "\n" + "\n" + "2013-01-02 03:04:05\n" + "bola: asd3\n" + "\n" + "\n" + "\n"); + blogc_template_free_ast(l); + bc_slist_free_full(s, (bc_free_func_t) bc_trie_free); + free(out); +} + + +static void +test_render_listing_entry3(void **state) +{ + const char *str = + "foo\n" + "{% block listing_once %}fuuu{% endblock %}\n" + "{% block entry %}\n" + "{% ifdef GUDA %}{{ GUDA }}{% endif %}\n" + "{% ifdef CHUNDA %}{{ CHUNDA }}{% endif %}\n" + "{% endblock %}\n" + "{% block listing_entry %}{{ FUUUUU }}{% endblock %}\n" + "{% block listing_entry %}{{ BAAAAA }}{% endblock %}\n" + "{% block listing %}\n" + "{% ifdef DATE_FORMATTED %}{{ DATE_FORMATTED }}{% endif %}\n" + "bola: {% ifdef BOLA %}{{ BOLA }}{% endif %}\n" + "{% foreach TAGS %}lol {{ FOREACH_ITEM }} haha {% endforeach %}\n" + "{% foreach TAGS_ASD %}yay{% endforeach %}\n" + "{% endblock %}\n"; + bc_error_t *err = NULL; + bc_slist_t *l = blogc_template_parse(str, strlen(str), &err); + assert_non_null(l); + assert_null(err); + bc_slist_t *s = create_sources(3); + assert_non_null(s); + bc_trie_t *entry = bc_trie_new(free); + bc_trie_insert(entry, "FUUUUU", bc_strdup("XD")); + bc_trie_insert(entry, "BAAAAA", bc_strdup(":p")); + bc_slist_t *e = NULL; + e = bc_slist_append(e, NULL); + e = bc_slist_append(e, entry); + char *out = blogc_render(l, s, e, NULL, true); + bc_slist_free_full(e, (bc_free_func_t) bc_trie_free); + assert_string_equal(out, + "foo\n" + "fuuu\n" + "\n" + "\n" ":p\n" "\n" "03:04\n" @@ -265,6 +327,69 @@ test_render_listing_entry2(void **state) static void +test_render_listing_entry4(void **state) +{ + const char *str = + "foo\n" + "{% block listing_once %}fuuu{% endblock %}\n" + "{% block entry %}\n" + "{% ifdef GUDA %}{{ GUDA }}{% endif %}\n" + "{% ifdef CHUNDA %}{{ CHUNDA }}{% endif %}\n" + "{% endblock %}\n" + "{% block listing_entry %}{{ FUUUUU }}{% endblock %}\n" + "{% block listing_entry %}{{ DDDDDD }}{% endblock %}\n" + "{% block listing %}\n" + "{% ifdef DATE_FORMATTED %}{{ DATE_FORMATTED }}{% endif %}\n" + "bola: {% ifdef BOLA %}{{ BOLA }}{% endif %}\n" + "{% foreach TAGS %}lol {{ FOREACH_ITEM }} haha {% endforeach %}\n" + "{% foreach TAGS_ASD %}yay{% endforeach %}\n" + "{% endblock %}\n"; + bc_error_t *err = NULL; + bc_slist_t *l = blogc_template_parse(str, strlen(str), &err); + assert_non_null(l); + assert_null(err); + bc_slist_t *s = create_sources(3); + assert_non_null(s); + bc_trie_t *entry1 = bc_trie_new(free); + bc_trie_insert(entry1, "FUUUUU", bc_strdup("XD")); + bc_trie_insert(entry1, "BAAAAA", bc_strdup(":p")); + bc_trie_t *entry2 = bc_trie_new(free); + bc_trie_insert(entry2, "CCCCCC", bc_strdup("er")); + bc_trie_insert(entry2, "DDDDDD", bc_strdup("ty")); + bc_slist_t *e = NULL; + e = bc_slist_append(e, entry1); + e = bc_slist_append(e, entry2); + char *out = blogc_render(l, s, e, NULL, true); + bc_slist_free_full(e, (bc_free_func_t) bc_trie_free); + assert_string_equal(out, + "foo\n" + "fuuu\n" + "\n" + "XD\n" + "ty\n" + "\n" + "03:04\n" + "bola: asd\n" + "lol foo haha lol bar haha lol baz haha \n" + "\n" + "\n" + "2014-02-03 04:05:06\n" + "bola: asd2\n" + "\n" + "\n" + "\n" + "2013-01-02 03:04:05\n" + "bola: asd3\n" + "\n" + "\n" + "\n"); + blogc_template_free_ast(l); + bc_slist_free_full(s, (bc_free_func_t) bc_trie_free); + free(out); +} + + +static void test_render_listing_empty(void **state) { const char *str = @@ -1227,6 +1352,8 @@ main(void) unit_test(test_render_listing), unit_test(test_render_listing_entry), unit_test(test_render_listing_entry2), + unit_test(test_render_listing_entry3), + unit_test(test_render_listing_entry4), unit_test(test_render_listing_empty), unit_test(test_render_ifdef), unit_test(test_render_ifdef2), |