From 8e12ae57ebe87d25c2c34ec304047fec3013da85 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Sat, 16 May 2020 03:33:22 +0200 Subject: blogc: added listing_empty template block --- tests/blogc/check_blogc.sh.in | 41 ++++++++++++++++++++++++++++++++++++- tests/blogc/check_renderer.c | 30 +++++++++++++++++++-------- tests/blogc/check_template_parser.c | 20 +++++++++++++----- 3 files changed, 77 insertions(+), 14 deletions(-) (limited to 'tests') diff --git a/tests/blogc/check_blogc.sh.in b/tests/blogc/check_blogc.sh.in index 87b71fa..208524d 100755 --- a/tests/blogc/check_blogc.sh.in +++ b/tests/blogc/check_blogc.sh.in @@ -183,7 +183,7 @@ cat > "${TEMP}/main.tmpl" <{{ DATE_FORMATTED }}
{{ TITLE }}
- {% endblock %} + {% endblock %}{% block listing_empty %}vazio{% endblock %} {% block listing_once %} @@ -576,6 +576,45 @@ ${TESTS_ENVIRONMENT} @abs_top_builddir@/blogc \ diff -uN "${TEMP}/output14.html" "${TEMP}/expected-output5.html" + +cat > "${TEMP}/expected-output6.html" < + + + Chunda's website + + +
Chunda's website
+ +
+
+
+
Blog
+
    + + vazio + +
+
+
+
+ + + + +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" \ + -t "${TEMP}/main.tmpl" \ + -o "${TEMP}/output15.html" \ + -l + +diff -uN "${TEMP}/output15.html" "${TEMP}/expected-output6.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 c1a9f9d..81e4a67 100644 --- a/tests/blogc/check_renderer.c +++ b/tests/blogc/check_renderer.c @@ -75,7 +75,8 @@ test_render_entry(void **state) "{% if GUDA > \"zxd\" %}LOL3{% else %}ELSE{% endif %}\n" "{% if GUDA <= \"zxc\" %}LOL4{% endif %}\n" "{% foreach TAGS %}lol {{ FOREACH_ITEM }} haha {% endforeach %}\n" - "{% foreach TAGS_ASD %}yay{% endforeach %}\n"; + "{% foreach TAGS_ASD %}yay{% endforeach %}\n" + "{% block listing_empty %}vazio{% endblock %}\n"; bc_error_t *err = NULL; bc_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); @@ -100,6 +101,7 @@ test_render_entry(void **state) "ELSE\n" "LOL4\n" "lol foo haha lol bar haha lol baz haha \n" + "\n" "\n"); blogc_template_free_ast(l); bc_slist_free_full(s, (bc_free_func_t) bc_trie_free); @@ -122,7 +124,8 @@ test_render_listing(void **state) "bola: {% ifdef BOLA %}{{ BOLA }}{% endif %}\n" "{% foreach TAGS %}lol {{ FOREACH_ITEM }} haha {% endforeach %}\n" "{% foreach TAGS_ASD %}yay{% endforeach %}\n" - "{% endblock %}\n"; + "{% endblock %}\n" + "{% block listing_empty %}vazio{% endblock %}\n"; bc_error_t *err = NULL; bc_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); @@ -149,6 +152,7 @@ test_render_listing(void **state) "bola: asd3\n" "\n" "\n" + "\n" "\n"); blogc_template_free_ast(l); bc_slist_free_full(s, (bc_free_func_t) bc_trie_free); @@ -172,7 +176,8 @@ test_render_listing_entry(void **state) "bola: {% ifdef BOLA %}{{ BOLA }}{% endif %}\n" "{% foreach TAGS %}lol {{ FOREACH_ITEM }} haha {% endforeach %}\n" "{% foreach TAGS_ASD %}yay{% endforeach %}\n" - "{% endblock %}\n"; + "{% endblock %}\n" + "{% block listing_empty %}vazio{% endblock %}\n"; bc_error_t *err = NULL; bc_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); @@ -200,6 +205,7 @@ test_render_listing_entry(void **state) "bola: asd3\n" "\n" "\n" + "\n" "\n"); blogc_template_free_ast(l); bc_slist_free_full(s, (bc_free_func_t) bc_trie_free); @@ -224,7 +230,8 @@ test_render_listing_entry2(void **state) "bola: {% ifdef BOLA %}{{ BOLA }}{% endif %}\n" "{% foreach TAGS %}lol {{ FOREACH_ITEM }} haha {% endforeach %}\n" "{% foreach TAGS_ASD %}yay{% endforeach %}\n" - "{% endblock %}\n"; + "{% endblock %}\n" + "{% block listing_empty %}vazio{% endblock %}\n"; bc_error_t *err = NULL; bc_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); @@ -259,6 +266,7 @@ test_render_listing_entry2(void **state) "bola: asd3\n" "\n" "\n" + "\n" "\n"); blogc_template_free_ast(l); bc_slist_free_full(s, (bc_free_func_t) bc_trie_free); @@ -283,7 +291,8 @@ test_render_listing_entry3(void **state) "bola: {% ifdef BOLA %}{{ BOLA }}{% endif %}\n" "{% foreach TAGS %}lol {{ FOREACH_ITEM }} haha {% endforeach %}\n" "{% foreach TAGS_ASD %}yay{% endforeach %}\n" - "{% endblock %}\n"; + "{% endblock %}\n" + "{% block listing_empty %}vazio{% endblock %}\n"; bc_error_t *err = NULL; bc_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); @@ -319,6 +328,7 @@ test_render_listing_entry3(void **state) "bola: asd3\n" "\n" "\n" + "\n" "\n"); blogc_template_free_ast(l); bc_slist_free_full(s, (bc_free_func_t) bc_trie_free); @@ -343,7 +353,8 @@ test_render_listing_entry4(void **state) "bola: {% ifdef BOLA %}{{ BOLA }}{% endif %}\n" "{% foreach TAGS %}lol {{ FOREACH_ITEM }} haha {% endforeach %}\n" "{% foreach TAGS_ASD %}yay{% endforeach %}\n" - "{% endblock %}\n"; + "{% endblock %}\n" + "{% block listing_empty %}vazio{% endblock %}\n"; bc_error_t *err = NULL; bc_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); @@ -382,6 +393,7 @@ test_render_listing_entry4(void **state) "bola: asd3\n" "\n" "\n" + "\n" "\n"); blogc_template_free_ast(l); bc_slist_free_full(s, (bc_free_func_t) bc_trie_free); @@ -403,7 +415,8 @@ test_render_listing_empty(void **state) "{% ifdef DATE_FORMATTED %}{{ DATE_FORMATTED }}{% endif %}\n" "bola: {% ifdef BOLA %}{{ BOLA }}{% endif %}\n" "{% foreach TAGS %}lol {{ FOREACH_ITEM }} haha {% endforeach %}\n" - "{% endblock %}\n"; + "{% endblock %}\n" + "{% block listing_empty %}vazio{% endblock %}\n"; bc_error_t *err = NULL; bc_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); @@ -413,7 +426,8 @@ test_render_listing_empty(void **state) "foo\n" "fuuu\n" "\n" - "\n"); + "\n" + "vazio\n"); blogc_template_free_ast(l); free(out); } diff --git a/tests/blogc/check_template_parser.c b/tests/blogc/check_template_parser.c index 15ef7c4..79d41fb 100644 --- a/tests/blogc/check_template_parser.c +++ b/tests/blogc/check_template_parser.c @@ -59,7 +59,8 @@ test_template_parse(void **state) "{% block listing_once %}asd{% endblock %}\n" "{%- foreach BOLA %}hahaha{% endforeach %}\n" "{% if BOLA == \"1\\\"0\" %}aee{% else %}fffuuuuuuu{% endif %}\n" - "{% block listing_entry %}lol{% endblock %}"; + "{% block listing_entry %}lol{% endblock %}\n" + "{% block listing_empty %}empty{% endblock %}"; bc_error_t *err = NULL; bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err); assert_null(err); @@ -125,8 +126,17 @@ test_template_parse(void **state) blogc_assert_template_node(tmp, "\n", BLOGC_TEMPLATE_NODE_CONTENT); blogc_assert_template_node(tmp->next, "listing_entry", BLOGC_TEMPLATE_NODE_BLOCK); blogc_assert_template_node(tmp->next->next, "lol", BLOGC_TEMPLATE_NODE_CONTENT); - blogc_assert_template_node(tmp->next->next->next, NULL, BLOGC_TEMPLATE_NODE_ENDBLOCK); - assert_null(tmp->next->next->next->next); + blogc_assert_template_node(tmp->next->next->next, NULL, + BLOGC_TEMPLATE_NODE_ENDBLOCK); + blogc_assert_template_node(tmp->next->next->next->next, "\n", + BLOGC_TEMPLATE_NODE_CONTENT); + blogc_assert_template_node(tmp->next->next->next->next->next, "listing_empty", + BLOGC_TEMPLATE_NODE_BLOCK); + blogc_assert_template_node(tmp->next->next->next->next->next->next, "empty", + BLOGC_TEMPLATE_NODE_CONTENT); + blogc_assert_template_node(tmp->next->next->next->next->next->next->next, NULL, + BLOGC_TEMPLATE_NODE_ENDBLOCK); + assert_null(tmp->next->next->next->next->next->next->next->next); blogc_template_free_ast(ast); } @@ -841,8 +851,8 @@ test_template_parse_invalid_block_type(void **state) assert_null(ast); assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, - "Invalid block type. Allowed types are: 'entry', 'listing', 'listing_once' " - "and 'listing_entry'.\n" + "Invalid block type. Allowed types are: 'entry', 'listing', 'listing_once', " + "'listing_empty' and 'listing_entry'.\n" "Error occurred near line 1, position 16: {% block chunda %}"); bc_error_free(err); } -- cgit v1.2.3-18-g5258