From adc3e6d77117d095e485ec64a93f1b64ffbf2cea Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Tue, 2 Apr 2019 22:57:33 +0200 Subject: blogc: added `-e` cli option and `listing_entry` template block --- tests/blogc/check_blogc.sh.in | 97 +++++++++++++++++++++- tests/blogc/check_renderer.c | 160 ++++++++++++++++++++++++++++++------ tests/blogc/check_template_parser.c | 13 ++- 3 files changed, 241 insertions(+), 29 deletions(-) (limited to 'tests') diff --git a/tests/blogc/check_blogc.sh.in b/tests/blogc/check_blogc.sh.in index 56d66e0..fcd7172 100755 --- a/tests/blogc/check_blogc.sh.in +++ b/tests/blogc/check_blogc.sh.in @@ -29,6 +29,13 @@ DATE: 2010-01-01 22:22:22 bar? EOF +cat > "${TEMP}/post3.txt" < "${TEMP}/atom.tmpl" < @@ -163,7 +170,7 @@ cat > "${TEMP}/main.tmpl" <{% block entry %}{{ TITLE }}{% endblock %}{% block listing_once %}{{ SITE_TITLE }}{% endblock %} -
{{ SITE_TITLE }}
+
{{ SITE_TITLE }}
{% block listing_entry %}{{ CONTENT }}{% endblock %} {% block listing_once %}
@@ -370,6 +377,94 @@ echo -e "${TEMP}/post1.txt" | ${TESTS_ENVIRONMENT} @abs_top_builddir@/blogc \ diff -uN "${TEMP}/output8.html" "${TEMP}/expected-output2.html" +cat > "${TEMP}/expected-output3.html" < + + + Chunda's website + + +
Chunda's website

bar?

+ + +
+
+
+
Blog
+
    + + +
  • +
    Jan 01, 2010, 11:11 AM GMT
    +
    foo
    +
  • + +
  • +
    Jan 01, 2010, 10:22 PM GMT
    +
    bar
    +
  • + + +
+
+
+
+ + + + +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}/post3.txt" \ + -t "${TEMP}/main.tmpl" \ + -o "${TEMP}/output9.html" \ + -l \ + "${TEMP}/post1.txt" "${TEMP}/post2.txt" + +diff -uN "${TEMP}/output9.html" "${TEMP}/expected-output3.html" + +echo -e "${TEMP}/post1.txt\n${TEMP}/post2.txt" | ${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}/post3.txt" \ + -t "${TEMP}/main.tmpl" \ + -o "${TEMP}/output10.html" \ + -l \ + -i + +diff -uN "${TEMP}/output10.html" "${TEMP}/expected-output3.html" + +${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}/post3.txt" \ + -t "${TEMP}/main.tmpl" \ + -l \ + "${TEMP}/post1.txt" "${TEMP}/post2.txt" > "${TEMP}/output11.html" + +diff -uN "${TEMP}/output11.html" "${TEMP}/expected-output3.html" + +echo -e "${TEMP}/post1.txt\n${TEMP}/post2.txt" | ${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}/post3.txt" \ + -t "${TEMP}/main.tmpl" \ + -l \ + -i > "${TEMP}/output12.html" + +diff -uN "${TEMP}/output12.html" "${TEMP}/expected-output3.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 1e2d1e5..479c239 100644 --- a/tests/blogc/check_renderer.c +++ b/tests/blogc/check_renderer.c @@ -82,7 +82,7 @@ test_render_entry(void **state) assert_null(err); bc_slist_t *s = create_sources(1); assert_non_null(s); - char *out = blogc_render(l, s, NULL, false); + char *out = blogc_render(l, s, NULL, NULL, false); assert_string_equal(out, "foo\n" "\n" @@ -129,7 +129,7 @@ test_render_listing(void **state) assert_null(err); bc_slist_t *s = create_sources(3); assert_non_null(s); - char *out = blogc_render(l, s, NULL, true); + char *out = blogc_render(l, s, NULL, NULL, true); assert_string_equal(out, "foo\n" "fuuu\n" @@ -156,6 +156,114 @@ test_render_listing(void **state) } +static void +test_render_listing_entry(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 %}asd{% 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); + char *out = blogc_render(l, s, NULL, NULL, true); + assert_string_equal(out, + "foo\n" + "fuuu\n" + "\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_entry2(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")); + char *out = blogc_render(l, s, entry, NULL, true); + bc_trie_free(entry); + assert_string_equal(out, + "foo\n" + "fuuu\n" + "\n" + "XD\n" + ":p\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) { @@ -175,7 +283,7 @@ test_render_listing_empty(void **state) bc_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); - char *out = blogc_render(l, NULL, NULL, true); + char *out = blogc_render(l, NULL, NULL, NULL, true); assert_string_equal(out, "foo\n" "fuuu\n" @@ -204,7 +312,7 @@ test_render_ifdef(void **state) assert_null(err); bc_slist_t *s = create_sources(1); assert_non_null(s); - char *out = blogc_render(l, s, NULL, false); + char *out = blogc_render(l, s, NULL, NULL, false); assert_string_equal(out, "\n" "\n" @@ -233,7 +341,7 @@ test_render_ifdef2(void **state) assert_null(err); bc_slist_t *s = create_sources(1); assert_non_null(s); - char *out = blogc_render(l, s, NULL, false); + char *out = blogc_render(l, s, NULL, NULL, false); assert_string_equal(out, "\n" "guda\n" @@ -264,7 +372,7 @@ test_render_ifdef3(void **state) assert_null(err); bc_slist_t *s = create_sources(1); assert_non_null(s); - char *out = blogc_render(l, s, NULL, false); + char *out = blogc_render(l, s, NULL, NULL, false); assert_string_equal(out, "\n" "guda\n" @@ -299,7 +407,7 @@ test_render_ifdef4(void **state) assert_null(err); bc_slist_t *s = create_sources(1); assert_non_null(s); - char *out = blogc_render(l, s, NULL, false); + char *out = blogc_render(l, s, NULL, NULL, false); assert_string_equal(out, "\n" "guda\n" @@ -335,7 +443,7 @@ test_render_ifdef5(void **state) assert_null(err); bc_slist_t *s = create_sources(1); assert_non_null(s); - char *out = blogc_render(l, s, NULL, false); + char *out = blogc_render(l, s, NULL, NULL, false); assert_string_equal(out, "\n" "guda\n" @@ -369,7 +477,7 @@ test_render_ifdef6(void **state) assert_null(err); bc_slist_t *s = create_sources(1); assert_non_null(s); - char *out = blogc_render(l, s, NULL, false); + char *out = blogc_render(l, s, NULL, NULL, false); assert_string_equal(out, "\n" "lol\n" @@ -402,7 +510,7 @@ test_render_ifdef7(void **state) assert_null(err); bc_slist_t *s = create_sources(1); assert_non_null(s); - char *out = blogc_render(l, s, NULL, false); + char *out = blogc_render(l, s, NULL, NULL, false); assert_string_equal(out, "\n" "guda\n" @@ -438,7 +546,7 @@ test_render_ifndef(void **state) assert_null(err); bc_slist_t *s = create_sources(1); assert_non_null(s); - char *out = blogc_render(l, s, NULL, false); + char *out = blogc_render(l, s, NULL, NULL, false); assert_string_equal(out, "\n" "chunda\n" @@ -474,7 +582,7 @@ test_render_if_eq(void **state) assert_null(err); bc_slist_t *s = create_sources(1); assert_non_null(s); - char *out = blogc_render(l, s, NULL, false); + char *out = blogc_render(l, s, NULL, NULL, false); assert_string_equal(out, "\n" "gudabola\n" @@ -511,7 +619,7 @@ test_render_if_neq(void **state) assert_null(err); bc_slist_t *s = create_sources(1); assert_non_null(s); - char *out = blogc_render(l, s, NULL, false); + char *out = blogc_render(l, s, NULL, NULL, false); assert_string_equal(out, "\n" "gudabola\n" @@ -548,7 +656,7 @@ test_render_if_lt(void **state) assert_null(err); bc_slist_t *s = create_sources(1); assert_non_null(s); - char *out = blogc_render(l, s, NULL, false); + char *out = blogc_render(l, s, NULL, NULL, false); assert_string_equal(out, "\n" "gudabola\n" @@ -585,7 +693,7 @@ test_render_if_gt(void **state) assert_null(err); bc_slist_t *s = create_sources(1); assert_non_null(s); - char *out = blogc_render(l, s, NULL, false); + char *out = blogc_render(l, s, NULL, NULL, false); assert_string_equal(out, "\n" "gudabola\n" @@ -624,7 +732,7 @@ test_render_if_lt_eq(void **state) assert_null(err); bc_slist_t *s = create_sources(1); assert_non_null(s); - char *out = blogc_render(l, s, NULL, false); + char *out = blogc_render(l, s, NULL, NULL, false); assert_string_equal(out, "\n" "gudabola\n" @@ -665,7 +773,7 @@ test_render_if_gt_eq(void **state) assert_null(err); bc_slist_t *s = create_sources(1); assert_non_null(s); - char *out = blogc_render(l, s, NULL, false); + char *out = blogc_render(l, s, NULL, NULL, false); assert_string_equal(out, "\n" "gudabola\n" @@ -697,7 +805,7 @@ test_render_foreach(void **state) assert_null(err); bc_slist_t *s = create_sources(1); assert_non_null(s); - char *out = blogc_render(l, s, NULL, false); + char *out = blogc_render(l, s, NULL, NULL, false); assert_string_equal(out, "\n" " foo bar baz \n" @@ -722,7 +830,7 @@ test_render_foreach_if(void **state) assert_null(err); bc_slist_t *s = create_sources(1); assert_non_null(s); - char *out = blogc_render(l, s, NULL, false); + char *out = blogc_render(l, s, NULL, NULL, false); assert_string_equal(out, "\n" " bar \n" @@ -748,7 +856,7 @@ test_render_foreach_if_else(void **state) assert_null(err); bc_slist_t *s = create_sources(1); assert_non_null(s); - char *out = blogc_render(l, s, NULL, false); + char *out = blogc_render(l, s, NULL, NULL, false); assert_string_equal(out, "\n" "foo yay baz \n" @@ -762,7 +870,7 @@ test_render_foreach_if_else(void **state) static void test_render_null(void **state) { - assert_null(blogc_render(NULL, NULL, NULL, false)); + assert_null(blogc_render(NULL, NULL, NULL, NULL, false)); } @@ -781,7 +889,7 @@ test_render_outside_block(void **state) assert_non_null(s); bc_trie_t *c = bc_trie_new(free); bc_trie_insert(c, "GUDA", bc_strdup("asd")); - char *out = blogc_render(l, s, c, false); + char *out = blogc_render(l, s, NULL, c, false); assert_string_equal(out, "bola\n" "\n" @@ -815,7 +923,7 @@ test_render_prefer_local_variable(void **state) bc_trie_t *c = bc_trie_new(free); bc_trie_insert(c, "GUDA", bc_strdup("hehe")); bc_trie_insert(c, "LOL", bc_strdup("hmm")); - char *out = blogc_render(l, s, c, false); + char *out = blogc_render(l, s, NULL, c, false); assert_string_equal(out, "\n" "hmm\n" @@ -849,7 +957,7 @@ test_render_respect_variable_scope(void **state) bc_slist_t *s = create_sources(1); assert_non_null(s); bc_trie_t *c = bc_trie_new(free); - char *out = blogc_render(l, s, c, false); + char *out = blogc_render(l, s, NULL, c, false); assert_string_equal(out, "\n" "\n" @@ -882,7 +990,7 @@ test_render_ifcount_bug(void **state) s = bc_slist_append(s, bc_trie_new(free)); bc_trie_insert(s->data, "TITLE", bc_strdup("bola")); bc_trie_t *c = bc_trie_new(free); - char *out = blogc_render(l, s, c, false); + char *out = blogc_render(l, s, NULL, c, false); assert_string_equal(out, "\n" "

bola

\n" @@ -1117,6 +1225,8 @@ main(void) const UnitTest tests[] = { unit_test(test_render_entry), unit_test(test_render_listing), + unit_test(test_render_listing_entry), + unit_test(test_render_listing_entry2), unit_test(test_render_listing_empty), unit_test(test_render_ifdef), unit_test(test_render_ifdef2), diff --git a/tests/blogc/check_template_parser.c b/tests/blogc/check_template_parser.c index 0121f73..15ef7c4 100644 --- a/tests/blogc/check_template_parser.c +++ b/tests/blogc/check_template_parser.c @@ -58,7 +58,8 @@ test_template_parse(void **state) "{% block listing %}{{ BOLA }}{% endblock %}\n" "{% block listing_once %}asd{% endblock %}\n" "{%- foreach BOLA %}hahaha{% endforeach %}\n" - "{% if BOLA == \"1\\\"0\" %}aee{% else %}fffuuuuuuu{% endif %}"; + "{% if BOLA == \"1\\\"0\" %}aee{% else %}fffuuuuuuu{% endif %}\n" + "{% block listing_entry %}lol{% endblock %}"; bc_error_t *err = NULL; bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err); assert_null(err); @@ -120,7 +121,12 @@ test_template_parse(void **state) "fffuuuuuuu", BLOGC_TEMPLATE_NODE_CONTENT); blogc_assert_template_node(tmp->next->next->next->next->next->next->next->next, NULL, BLOGC_TEMPLATE_NODE_ENDIF); - assert_null(tmp->next->next->next->next->next->next->next->next->next); + tmp = tmp->next->next->next->next->next->next->next->next->next; + 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_template_free_ast(ast); } @@ -835,7 +841,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' and 'listing_once'.\n" + "Invalid block type. Allowed types are: 'entry', 'listing', 'listing_once' " + "and 'listing_entry'.\n" "Error occurred near line 1, position 16: {% block chunda %}"); bc_error_free(err); } -- cgit v1.2.3-18-g5258