diff options
Diffstat (limited to 'tests/check_template_parser.c')
-rw-r--r-- | tests/check_template_parser.c | 48 |
1 files changed, 34 insertions, 14 deletions
diff --git a/tests/check_template_parser.c b/tests/check_template_parser.c index f9fd71a..f655896 100644 --- a/tests/check_template_parser.c +++ b/tests/check_template_parser.c @@ -51,27 +51,27 @@ test_template_parse(void **state) const char *a = "Test\n" "\n" - " {% block entry %}\n" + " {%- block entry -%}\n" "{% ifdef CHUNDA %}\n" "bola\n" "{% endif %}\n" "{% ifndef BOLA %}\n" "bolao\n" - "{% endif %}\n" + "{%- endif %}\n" "{% endblock %}\n" "{% block listing %}{{ BOLA }}{% endblock %}\n" "{% block listing_once %}asd{% endblock %}\n" - "{% foreach BOLA %}hahaha{% endforeach %}\n" + "{%- foreach BOLA %}hahaha{% endforeach %}\n" "{% if BOLA == \"1\\\"0\" %}aee{% endif %}"; blogc_error_t *err = NULL; b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_null(err); assert_non_null(stmts); - blogc_assert_template_stmt(stmts, "Test\n\n ", + blogc_assert_template_stmt(stmts, "Test", BLOGC_TEMPLATE_CONTENT_STMT); blogc_assert_template_stmt(stmts->next, "entry", BLOGC_TEMPLATE_BLOCK_STMT); - blogc_assert_template_stmt(stmts->next->next, "\n", + blogc_assert_template_stmt(stmts->next->next, "", BLOGC_TEMPLATE_CONTENT_STMT); blogc_assert_template_stmt(stmts->next->next->next, "CHUNDA", BLOGC_TEMPLATE_IFDEF_STMT); @@ -83,7 +83,7 @@ test_template_parse(void **state) BLOGC_TEMPLATE_CONTENT_STMT); b_slist_t *tmp = stmts->next->next->next->next->next->next->next; blogc_assert_template_stmt(tmp, "BOLA", BLOGC_TEMPLATE_IFNDEF_STMT); - blogc_assert_template_stmt(tmp->next, "\nbolao\n", BLOGC_TEMPLATE_CONTENT_STMT); + blogc_assert_template_stmt(tmp->next, "\nbolao", BLOGC_TEMPLATE_CONTENT_STMT); blogc_assert_template_stmt(tmp->next->next, NULL, BLOGC_TEMPLATE_ENDIF_STMT); blogc_assert_template_stmt(tmp->next->next->next, "\n", BLOGC_TEMPLATE_CONTENT_STMT); @@ -105,7 +105,7 @@ test_template_parse(void **state) blogc_assert_template_stmt(tmp->next->next->next->next->next->next->next->next, NULL, BLOGC_TEMPLATE_ENDBLOCK_STMT); blogc_assert_template_stmt(tmp->next->next->next->next->next->next->next->next->next, - "\n", BLOGC_TEMPLATE_CONTENT_STMT); + "", BLOGC_TEMPLATE_CONTENT_STMT); tmp = tmp->next->next->next->next->next->next->next->next->next->next; blogc_assert_template_stmt(tmp, "BOLA", BLOGC_TEMPLATE_FOREACH_STMT); blogc_assert_template_stmt(tmp->next, "hahaha", @@ -131,27 +131,27 @@ test_template_parse_crlf(void **state) const char *a = "Test\r\n" "\r\n" - " {% block entry %}\r\n" + " {%- block entry -%}\r\n" "{% ifdef CHUNDA %}\r\n" "bola\r\n" "{% endif %}\r\n" "{% ifndef BOLA %}\r\n" "bolao\r\n" - "{% endif %}\r\n" + "{%- endif %}\r\n" "{% endblock %}\r\n" "{% block listing %}{{ BOLA }}{% endblock %}\r\n" "{% block listing_once %}asd{% endblock %}\r\n" - "{% foreach BOLA %}hahaha{% endforeach %}\r\n" + "{%- foreach BOLA %}hahaha{% endforeach %}\r\n" "{% if BOLA == \"1\\\"0\" %}aee{% endif %}"; blogc_error_t *err = NULL; b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_null(err); assert_non_null(stmts); - blogc_assert_template_stmt(stmts, "Test\r\n\r\n ", + blogc_assert_template_stmt(stmts, "Test", BLOGC_TEMPLATE_CONTENT_STMT); blogc_assert_template_stmt(stmts->next, "entry", BLOGC_TEMPLATE_BLOCK_STMT); - blogc_assert_template_stmt(stmts->next->next, "\r\n", + blogc_assert_template_stmt(stmts->next->next, "", BLOGC_TEMPLATE_CONTENT_STMT); blogc_assert_template_stmt(stmts->next->next->next, "CHUNDA", BLOGC_TEMPLATE_IFDEF_STMT); @@ -163,7 +163,7 @@ test_template_parse_crlf(void **state) BLOGC_TEMPLATE_CONTENT_STMT); b_slist_t *tmp = stmts->next->next->next->next->next->next->next; blogc_assert_template_stmt(tmp, "BOLA", BLOGC_TEMPLATE_IFNDEF_STMT); - blogc_assert_template_stmt(tmp->next, "\r\nbolao\r\n", BLOGC_TEMPLATE_CONTENT_STMT); + blogc_assert_template_stmt(tmp->next, "\r\nbolao", BLOGC_TEMPLATE_CONTENT_STMT); blogc_assert_template_stmt(tmp->next->next, NULL, BLOGC_TEMPLATE_ENDIF_STMT); blogc_assert_template_stmt(tmp->next->next->next, "\r\n", BLOGC_TEMPLATE_CONTENT_STMT); @@ -185,7 +185,7 @@ test_template_parse_crlf(void **state) blogc_assert_template_stmt(tmp->next->next->next->next->next->next->next->next, NULL, BLOGC_TEMPLATE_ENDBLOCK_STMT); blogc_assert_template_stmt(tmp->next->next->next->next->next->next->next->next->next, - "\r\n", BLOGC_TEMPLATE_CONTENT_STMT); + "", BLOGC_TEMPLATE_CONTENT_STMT); tmp = tmp->next->next->next->next->next->next->next->next->next->next; blogc_assert_template_stmt(tmp, "BOLA", BLOGC_TEMPLATE_FOREACH_STMT); blogc_assert_template_stmt(tmp->next, "hahaha", @@ -381,6 +381,26 @@ test_template_parse_invalid_block_start(void **state) "Invalid statement syntax. Must begin with lowercase letter.\n" "Error occurred near line 1, position 4: {% ASD %}"); blogc_error_free(err); + a = "{%-- block entry %}\n"; + err = NULL; + stmts = blogc_template_parse(a, strlen(a), &err); + assert_non_null(err); + assert_null(stmts); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); + assert_string_equal(err->msg, + "Invalid statement syntax. Duplicated whitespace cleaner before statement.\n" + "Error occurred near line 1, position 4: {%-- block entry %}"); + blogc_error_free(err); + a = "{% block entry --%}\n"; + err = NULL; + stmts = blogc_template_parse(a, strlen(a), &err); + assert_non_null(err); + assert_null(stmts); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); + assert_string_equal(err->msg, + "Invalid statement syntax. Duplicated whitespace cleaner after statement.\n" + "Error occurred near line 1, position 17: {% block entry --%}"); + blogc_error_free(err); } |