From 49ed30a5e87e510fd0c14b367110175f9d2fb144 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Sat, 9 Feb 2019 02:29:05 +0100 Subject: blogc: template: allow whitespaces in template tags, not just spaces --- tests/blogc/check_template_parser.c | 130 ++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) (limited to 'tests') diff --git a/tests/blogc/check_template_parser.c b/tests/blogc/check_template_parser.c index bf9f6d7..0121f73 100644 --- a/tests/blogc/check_template_parser.c +++ b/tests/blogc/check_template_parser.c @@ -338,6 +338,135 @@ test_template_parse_html(void **state) } +static void +test_template_parse_html_whitespace(void **state) +{ + const char *a = + "\n" + " \n" + " {%\n block entry\n%}\n" + " My cool blog >> {{ TITLE }}\n" + " {% \vendblock\v %}\n" + " {% \r\nblock listing_once\n%}\n" + " My cool blog - Main page\n" + " {%\t endblock\t%}\n" + " \n" + " \n" + "

My cool blog

\n" + " {%\t\t\tblock entry\n%}\n" + "

{{\tTITLE\n}}

\n" + " {%\nifdef DATE\v%}

Published in: {{\tDATE\t}}

{%\fendif\f%}\n" + "
{{\tCONTENT\n}}
\n" + " {%\n\n \nendblock\f\f\n\t%}\n" + " {%\nblock\n\nlisting_once\t%}{%\nendblock\n%}\n" + " \n" + "\n"; + bc_error_t *err = NULL; + bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err); + assert_null(err); + assert_non_null(ast); + blogc_assert_template_node(ast, "\n \n ", + BLOGC_TEMPLATE_NODE_CONTENT); + blogc_assert_template_node(ast->next, "entry", + BLOGC_TEMPLATE_NODE_BLOCK); + blogc_assert_template_node(ast->next->next, + "\n My cool blog >> ", BLOGC_TEMPLATE_NODE_CONTENT); + blogc_assert_template_node(ast->next->next->next, "TITLE", + BLOGC_TEMPLATE_NODE_VARIABLE); + blogc_assert_template_node(ast->next->next->next->next, + "\n ", BLOGC_TEMPLATE_NODE_CONTENT); + blogc_assert_template_node(ast->next->next->next->next->next, NULL, + BLOGC_TEMPLATE_NODE_ENDBLOCK); + blogc_assert_template_node(ast->next->next->next->next->next->next, + "\n ", BLOGC_TEMPLATE_NODE_CONTENT); + blogc_assert_template_node(ast->next->next->next->next->next->next->next, + "listing_once", BLOGC_TEMPLATE_NODE_BLOCK); + bc_slist_t *tmp = ast->next->next->next->next->next->next->next->next; + blogc_assert_template_node(tmp, + "\n My cool blog - Main page\n ", + BLOGC_TEMPLATE_NODE_CONTENT); + blogc_assert_template_node(tmp->next, NULL, BLOGC_TEMPLATE_NODE_ENDBLOCK); + blogc_assert_template_node(tmp->next->next, + "\n \n \n

My cool blog

\n ", + BLOGC_TEMPLATE_NODE_CONTENT); + blogc_assert_template_node(tmp->next->next->next, "entry", + BLOGC_TEMPLATE_NODE_BLOCK); + blogc_assert_template_node(tmp->next->next->next->next, + "\n

", BLOGC_TEMPLATE_NODE_CONTENT); + blogc_assert_template_node(tmp->next->next->next->next->next, + "TITLE", BLOGC_TEMPLATE_NODE_VARIABLE); + blogc_assert_template_node(tmp->next->next->next->next->next->next, + "

\n ", BLOGC_TEMPLATE_NODE_CONTENT); + blogc_assert_template_node(tmp->next->next->next->next->next->next->next, + "DATE", BLOGC_TEMPLATE_NODE_IFDEF); + tmp = tmp->next->next->next->next->next->next->next->next; + blogc_assert_template_node(tmp, "

Published in: ", + BLOGC_TEMPLATE_NODE_CONTENT); + blogc_assert_template_node(tmp->next, "DATE", BLOGC_TEMPLATE_NODE_VARIABLE); + blogc_assert_template_node(tmp->next->next, "

", + BLOGC_TEMPLATE_NODE_CONTENT); + blogc_assert_template_node(tmp->next->next->next, NULL, + BLOGC_TEMPLATE_NODE_ENDIF); + blogc_assert_template_node(tmp->next->next->next->next, "\n
",
+        BLOGC_TEMPLATE_NODE_CONTENT);
+    blogc_assert_template_node(tmp->next->next->next->next->next,
+        "CONTENT", BLOGC_TEMPLATE_NODE_VARIABLE);
+    blogc_assert_template_node(tmp->next->next->next->next->next->next,
+        "
\n ", BLOGC_TEMPLATE_NODE_CONTENT); + blogc_assert_template_node(tmp->next->next->next->next->next->next->next, + NULL, BLOGC_TEMPLATE_NODE_ENDBLOCK); + tmp = tmp->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_once", + BLOGC_TEMPLATE_NODE_BLOCK); + blogc_assert_template_node(tmp->next->next, "", + BLOGC_TEMPLATE_NODE_CONTENT); + blogc_assert_template_node(tmp->next->next->next->next, NULL, + BLOGC_TEMPLATE_NODE_ENDBLOCK); + blogc_assert_template_node(tmp->next->next->next->next->next, + "\n \n\n", BLOGC_TEMPLATE_NODE_CONTENT); + assert_null(tmp->next->next->next->next->next->next); + blogc_template_free_ast(ast); +} + + static void test_template_parse_ifdef_and_var_outside_block(void **state) { @@ -1137,6 +1266,7 @@ main(void) unit_test(test_template_parse), unit_test(test_template_parse_crlf), unit_test(test_template_parse_html), + unit_test(test_template_parse_html_whitespace), unit_test(test_template_parse_ifdef_and_var_outside_block), unit_test(test_template_parse_nested_else), unit_test(test_template_parse_invalid_block_start), -- cgit v1.2.3-18-g5258