diff options
author | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2015-04-17 01:47:41 -0300 |
---|---|---|
committer | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2015-04-17 01:47:41 -0300 |
commit | 047e4e3753c597628024847a524d44ca67fa1382 (patch) | |
tree | 8c0d63ecd8d395815a4eee155c2ce6283e0e7fab /tests | |
parent | f5da9cc42acc79d7dda78e57fab8a1b8d7aa6a7d (diff) | |
download | blogc-047e4e3753c597628024847a524d44ca67fa1382.tar.gz blogc-047e4e3753c597628024847a524d44ca67fa1382.tar.bz2 blogc-047e4e3753c597628024847a524d44ca67fa1382.zip |
replaced leg-based parser with handmade parser for source files
Diffstat (limited to 'tests')
-rw-r--r-- | tests/check_source_parser.c (renamed from tests/check_source_grammar.c) | 13 | ||||
-rw-r--r-- | tests/check_template_grammar.c | 47 |
2 files changed, 55 insertions, 5 deletions
diff --git a/tests/check_source_grammar.c b/tests/check_source_parser.c index b2f581b..2f5880a 100644 --- a/tests/check_source_grammar.c +++ b/tests/check_source_parser.c @@ -14,19 +14,21 @@ #include <stddef.h> #include <setjmp.h> #include <cmocka.h> -#include "../src/source-grammar.h" +#include <string.h> +#include "../src/source-parser.h" static void test_source_parse(void **state) { - blogc_source_t *source = blogc_source_parse( + const char *a = "VAR1: asd asd\n" "VAR2: 123chunda\n" "----------\n" "# This is a test\n" "\n" - "bola\n"); + "bola\n"; + blogc_source_t *source = blogc_source_parse(a, strlen(a)); assert_non_null(source); assert_int_equal(b_trie_size(source->config), 2); assert_string_equal(b_trie_lookup(source->config, "VAR1"), "asd asd"); @@ -42,7 +44,7 @@ test_source_parse(void **state) static void test_source_parse_with_spaces(void **state) { - blogc_source_t *source = blogc_source_parse( + const char *a = "\n \n" "VAR1: chunda \t \n" "\n\n" @@ -50,7 +52,8 @@ test_source_parse_with_spaces(void **state) "----------\n" "# This is a test\n" "\n" - "bola\n"); + "bola\n"; + blogc_source_t *source = blogc_source_parse(a, strlen(a)); assert_non_null(source); assert_int_equal(b_trie_size(source->config), 2); assert_string_equal(b_trie_lookup(source->config, "VAR1"), "chunda"); diff --git a/tests/check_template_grammar.c b/tests/check_template_grammar.c index ffad8fb..3b4dcca 100644 --- a/tests/check_template_grammar.c +++ b/tests/check_template_grammar.c @@ -88,11 +88,58 @@ test_template_parse(void **state) } +static void +test_template_parse_html(void **state) +{ + b_slist_t *stmts = blogc_template_parse( + "<html>\n" + " <head>\n" + " {% block single_source %}\n" + " <title>My cool blog >> {{ TITLE }}</title>\n" + " {% endblock %}\n" + " {% block multiple_sources %}\n" + " <title>My cool blog - Main page</title>\n" + " {% endblock %}\n" + " </head>\n" + " <body>\n" + " <h1>My cool blog</h1>\n" + " {% block single_source %}\n" + " <h2>{{ TITLE }}</h2>\n" + " {% if DATE %}<h4>Published in: {{ DATE }}</h4>{% endif %}\n" + " <pre>{{ CONTENT }}</pre>\n" + " {% endblock %}\n" + " {% block multiple_sources_once %}<ul>{% endblock %}\n" + " {% block multiple_sources %}<p><a href=\"{{ FILENAME }}.html\">" + "{{ TITLE }}</a>{% if DATE %} - {{ DATE }}{% endif %}</p>{% endblock %}\n" + " {% block multiple_sources_once %}</ul>{% endblock %}\n" + " </body>\n" + "</html>\n"); + assert_non_null(stmts); + blogc_assert_template_stmt(stmts, "<html>\n <head>\n ", + BLOGC_TEMPLATE_CONTENT_STMT); + blogc_assert_template_stmt(stmts->next, "single_source", + BLOGC_TEMPLATE_BLOCK_STMT); + blogc_assert_template_stmt(stmts->next->next, + "\n <title>My cool blog >> ", BLOGC_TEMPLATE_CONTENT_STMT); + blogc_assert_template_stmt(stmts->next->next->next, "TITLE", + BLOGC_TEMPLATE_VARIABLE_STMT); + blogc_assert_template_stmt(stmts->next->next->next->next, + "</title>\n ", BLOGC_TEMPLATE_CONTENT_STMT); + + + + + + blogc_template_free_stmts(stmts); +} + + int main(void) { const UnitTest tests[] = { unit_test(test_template_parse), + unit_test(test_template_parse_html), }; return run_tests(tests); } |