From 8404096582103dccb8885b0c404f0a756685e913 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Wed, 22 Apr 2020 02:06:37 +0200 Subject: blogc: allow passing multiple -e options --- tests/blogc/check_blogc.sh.in | 109 ++++++++++++++++++++++++++++++++++- tests/blogc/check_renderer.c | 131 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 237 insertions(+), 3 deletions(-) (limited to 'tests') 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" <{% ifdef FOO1 %}{{ FOO1 }} {% endif %}{% block entry %}{{ TITLE }}{% endblock %}{% block listing_once %}{{ SITE_TITLE }}{% endblock %} -
{{ SITE_TITLE }}
{% block listing_entry %}{{ CONTENT }}{% endblock %} +
{{ SITE_TITLE }}
{% block listing_entry %}{{ CONTENT }}{% endblock %}{% block listing_entry %}{{ CONTENT }}{% endblock %} {% block listing_once %}
@@ -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" < + + + Chunda's website + + +
Chunda's website

foo?

+ + +
+
+
+
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 "" \ + -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" < + + + Chunda's website + + +
Chunda's website

foo?

+

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}/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" @@ -264,6 +326,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) { @@ -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), -- cgit v1.2.3-18-g5258