aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2020-05-16 03:33:22 +0200
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2020-05-16 03:33:22 +0200
commit8e12ae57ebe87d25c2c34ec304047fec3013da85 (patch)
treefc7f974219f6d60d8e866a540da45f69e696546b /tests
parentf5db671822b7b6dc74166c1c9e34a900c7f0d0cb (diff)
downloadblogc-8e12ae57ebe87d25c2c34ec304047fec3013da85.tar.gz
blogc-8e12ae57ebe87d25c2c34ec304047fec3013da85.tar.bz2
blogc-8e12ae57ebe87d25c2c34ec304047fec3013da85.zip
blogc: added listing_empty template block
Diffstat (limited to 'tests')
-rwxr-xr-xtests/blogc/check_blogc.sh.in41
-rw-r--r--tests/blogc/check_renderer.c30
-rw-r--r--tests/blogc/check_template_parser.c20
3 files changed, 77 insertions, 14 deletions
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" <<EOF
<div class="meta">{{ DATE_FORMATTED }}</div>
<a href="{{ BASE_URL }}/post/{{ FILENAME }}/"><div>{{ TITLE }}</div></a>
</li>
- {% endblock %}
+ {% endblock %}{% block listing_empty %}vazio{% endblock %}
{% block listing_once %}
</ul>
</div>
@@ -576,6 +576,45 @@ ${TESTS_ENVIRONMENT} @abs_top_builddir@/blogc \
diff -uN "${TEMP}/output14.html" "${TEMP}/expected-output5.html"
+
+cat > "${TEMP}/expected-output6.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>
+
+ <section class="main">
+ <div class="container">
+ <div class="content">
+ <div class="page-heading">Blog</div>
+ <ul>
+
+ vazio
+
+ </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" \
+ -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);
}