aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2015-04-27 00:10:26 -0300
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2015-04-27 00:10:26 -0300
commit5205db347cb9f56187c2ad5e767281a7a4016533 (patch)
tree946917c0bbcfd17a6cd02b3bc03fd7f37fdb6cc9
parent2dfa0fbac45122567988cb520e508f24897114fe (diff)
downloadblogc-5205db347cb9f56187c2ad5e767281a7a4016533.tar.gz
blogc-5205db347cb9f56187c2ad5e767281a7a4016533.tar.bz2
blogc-5205db347cb9f56187c2ad5e767281a7a4016533.zip
added global variable support
-rw-r--r--README.md8
-rw-r--r--src/main.c54
-rw-r--r--src/renderer.c80
-rw-r--r--src/renderer.h3
-rw-r--r--src/template-parser.c46
-rw-r--r--tests/check_renderer.c82
-rw-r--r--tests/check_template_parser.c137
7 files changed, 222 insertions, 188 deletions
diff --git a/README.md b/README.md
index c712c78..ad8f40d 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
# blogc
-[![Build Status](https://semaphoreci.com/api/v1/projects/bd67545c-8593-4a37-ba94-ef1187a6d58d/402577/badge.svg)](https://semaphoreci.com/rafaelmartins/blogc)
+[![Build Status](https://semaphoreci.com/api/v1/projects/bd67545c-8593-4a37-ba94-ef1187a6d58d/402577/badge.svg)](https://semaphoreci.com/rafaelmartins/blogc)
A blog compiler.
@@ -22,11 +22,11 @@ The templates can define blocks. These are the block rules:
- ``listing_once`` should be inclueded if more than one source file is provided, but only once, if the compiler is called with ``-l``.
- Template blocks can be defined multiple times in the same template, but can't be nested.
-The variables defined in the source file are only available inside of blocks. If something does not depends on the source files, and is global, it must be hardcoded in the template, for the sake of simplicity.
+The variables defined in source files are only available inside of blocks. The variables defined in the command line are global and available everywhere. Inside blocks, variables defined in source files are always used, even if a global variable with the same name exists.
-The templates can use conditional statements: ``{% if VARIABLE %}`` or ``{% if not VARIABLE %}``, and ``{% endif %}``. They check if a variable is defined or not. As variables are not available outside of blocks, these conditional statements can't be defined outside of blocks as well.
+The templates can use conditional statements: ``{% if VARIABLE %}`` or ``{% if not VARIABLE %}``, and ``{% endif %}``. They check if a variable is defined or not.
-Variables are not available in ``listing_once`` blocks, because it is not possible to guess which source file would provide the variable contents.
+Variables defined in source files are not available in ``listing_once`` blocks, because it is not possible to guess which source file would provide the variable contents. Global variables, defined in the command line are available.
As the compiler is output-agnostic, Atom feeds and sitemaps should be generated using templates as well.
diff --git a/src/main.c b/src/main.c
index e43b71b..0680728 100644
--- a/src/main.c
+++ b/src/main.c
@@ -36,24 +36,25 @@ blogc_print_help(void)
{
printf(
"usage:\n"
- " blogc [-h] [-v] [-l] -t TEMPLATE [-o OUTPUT] SOURCE [SOURCE ...] - A blog compiler.\n"
+ " blogc [-h] [-v] [-l] [-D KEY=VALUE ...] -t TEMPLATE [-o OUTPUT] SOURCE [SOURCE ...] - A blog compiler.\n"
"\n"
"positional arguments:\n"
- " SOURCE source file(s)\n"
+ " SOURCE source file(s)\n"
"\n"
"optional arguments:\n"
- " -h show this help message and exit\n"
- " -v show version and exit\n"
- " -l build listing page, from multiple source files\n"
- " -t TEMPLATE template file\n"
- " -o OUTPUT output file\n");
+ " -h show this help message and exit\n"
+ " -v show version and exit\n"
+ " -l build listing page, from multiple source files\n"
+ " -D KEY=VALUE set global configuration parameter\n"
+ " -t TEMPLATE template file\n"
+ " -o OUTPUT output file\n");
}
static void
blogc_print_usage(void)
{
- printf("usage: blogc [-h] [-v] [-l] -t TEMPLATE [-o OUTPUT] SOURCE [SOURCE ...]\n");
+ printf("usage: blogc [-h] [-v] [-l] [-D KEY=VALUE ...] -t TEMPLATE [-o OUTPUT] SOURCE [SOURCE ...]\n");
}
@@ -100,9 +101,14 @@ main(int argc, char **argv)
bool listing = false;
char *template = NULL;
char *output = NULL;
+ char *tmp = NULL;
+ char **pieces = NULL;
+
b_slist_t *sources = NULL;
+ b_trie_t *config = b_trie_new(free);
for (unsigned int i = 1; i < argc; i++) {
+ tmp = NULL;
if (argv[i][0] == '-') {
switch (argv[i][1]) {
case 'h':
@@ -126,6 +132,35 @@ main(int argc, char **argv)
else if (i + 1 < argc)
output = b_strdup(argv[++i]);
break;
+ case 'D':
+ if (argv[i][2] != '\0')
+ tmp = argv[i] + 2;
+ else if (i + 1 < argc)
+ tmp = argv[++i];
+ if (tmp != NULL) {
+ pieces = b_str_split(tmp, '=', 2);
+ if (b_strv_length(pieces) != 2) {
+ fprintf(stderr, "blogc: error: invalid value for "
+ "-D (must have an '='): %s\n", tmp);
+ b_strv_free(pieces);
+ rv = 2;
+ goto cleanup;
+ }
+ for (unsigned int j = 0; pieces[0][j] != '\0'; j++) {
+ if (!(pieces[0][j] >= 'A' && pieces[0][j] <= 'Z')) {
+ fprintf(stderr, "blogc: error: invalid value "
+ "for -D (configuration key must be uppercase): "
+ "%s\n", pieces[0]);
+ b_strv_free(pieces);
+ rv = 2;
+ goto cleanup;
+ }
+ }
+ b_trie_insert(config, pieces[0], b_strdup(pieces[1]));
+ b_strv_free(pieces);
+ pieces = NULL;
+ }
+ break;
default:
blogc_print_usage();
fprintf(stderr, "blogc: error: invalid argument: -%c\n",
@@ -177,7 +212,7 @@ main(int argc, char **argv)
goto cleanup3;
}
- char *out = blogc_render(l, s, listing);
+ char *out = blogc_render(l, s, config, listing);
bool write_to_stdout = (output == NULL || (0 == strcmp(output, "-")));
@@ -206,6 +241,7 @@ cleanup2:
blogc_template_free_stmts(l);
blogc_error_free(err);
cleanup:
+ b_trie_free(config);
free(template);
free(output);
b_slist_free_full(sources, free);
diff --git a/src/renderer.c b/src/renderer.c
index 92fa7d4..905c42f 100644
--- a/src/renderer.c
+++ b/src/renderer.c
@@ -18,7 +18,7 @@
char*
-blogc_render(b_slist_t *tmpl, b_slist_t *sources, bool listing)
+blogc_render(b_slist_t *tmpl, b_slist_t *sources, b_trie_t *config, bool listing)
{
if (tmpl == NULL || sources == NULL)
return NULL;
@@ -35,6 +35,7 @@ blogc_render(b_slist_t *tmpl, b_slist_t *sources, bool listing)
unsigned int if_skip = 0;
bool if_not = false;
+ bool defined = false;
b_slist_t *tmp = tmpl;
while (tmp != NULL) {
@@ -86,11 +87,25 @@ blogc_render(b_slist_t *tmpl, b_slist_t *sources, bool listing)
break;
case BLOGC_TEMPLATE_VARIABLE_STMT:
- if (stmt->value != NULL && tmp_source != NULL) {
- config_value = b_trie_lookup(tmp_source, stmt->value);
- if (config_value != NULL)
- b_string_append(str, config_value);
- break;
+ if (stmt->value != NULL) {
+
+ // try local config first
+ if (tmp_source != NULL) {
+ config_value = b_trie_lookup(tmp_source, stmt->value);
+ if (config_value != NULL) {
+ b_string_append(str, config_value);
+ break;
+ }
+ }
+
+ // if not found, try global config
+ if (config != NULL) {
+ config_value = b_trie_lookup(config, stmt->value);
+ if (config_value != NULL) {
+ b_string_append(str, config_value);
+ break;
+ }
+ }
}
break;
@@ -110,36 +125,39 @@ blogc_render(b_slist_t *tmpl, b_slist_t *sources, bool listing)
if_not = true;
case BLOGC_TEMPLATE_IF_STMT:
- if (stmt->value != NULL && tmp_source != NULL) {
- if ((!if_not && (b_trie_lookup(tmp_source, stmt->value) == NULL)) ||
- (if_not && (b_trie_lookup(tmp_source, stmt->value) != NULL)))
- {
- if_skip = if_count;
-
- // at this point we can just skip anything, counting the
- // number of 'if's, to know how many 'endif's we need to
- // skip as well.
- while (1) {
- tmp = tmp->next;
- stmt = tmp->data;
- if ((stmt->type == BLOGC_TEMPLATE_IF_STMT) ||
- (stmt->type == BLOGC_TEMPLATE_IF_NOT_STMT))
- {
- if_count++;
+ defined = false;
+ if (stmt->value != NULL) {
+ if (tmp_source != NULL && b_trie_lookup(tmp_source, stmt->value) != NULL)
+ defined = true;
+ if (config != NULL && b_trie_lookup(config, stmt->value) != NULL)
+ defined = true;
+ }
+ if ((!if_not && !defined) || (if_not && defined)) {
+ if_skip = if_count;
+
+ // at this point we can just skip anything, counting the
+ // number of 'if's, to know how many 'endif's we need to
+ // skip as well.
+ while (1) {
+ tmp = tmp->next;
+ stmt = tmp->data;
+ if ((stmt->type == BLOGC_TEMPLATE_IF_STMT) ||
+ (stmt->type == BLOGC_TEMPLATE_IF_NOT_STMT))
+ {
+ if_count++;
+ continue;
+ }
+ if (stmt->type == BLOGC_TEMPLATE_ENDIF_STMT) {
+ if (if_count > if_skip) {
+ if_count--;
continue;
}
- if (stmt->type == BLOGC_TEMPLATE_ENDIF_STMT) {
- if (if_count > if_skip) {
- if_count--;
- continue;
- }
- if (if_count == if_skip)
- break;
- }
+ if (if_count == if_skip)
+ break;
}
}
- if_not = false;
}
+ if_not = false;
break;
case BLOGC_TEMPLATE_ENDIF_STMT:
diff --git a/src/renderer.h b/src/renderer.h
index a6b7a2c..c9a0ed1 100644
--- a/src/renderer.h
+++ b/src/renderer.h
@@ -12,6 +12,7 @@
#include <stdbool.h>
#include "utils/utils.h"
-char* blogc_render(b_slist_t *tmpl, b_slist_t *sources, bool listing);
+char* blogc_render(b_slist_t *tmpl, b_slist_t *sources, b_trie_t *config,
+ bool listing);
#endif /* _RENDERER_H */
diff --git a/src/template-parser.c b/src/template-parser.c
index 69402cf..a91182f 100644
--- a/src/template-parser.c
+++ b/src/template-parser.c
@@ -143,36 +143,22 @@ blogc_template_parse(const char *src, size_t src_len, blogc_error_t **err)
break;
}
else if (0 == strncmp("if", src + start, current - start)) {
- if (block_state == BLOCK_ENTRY || block_state == BLOCK_LISTING) {
- state = TEMPLATE_BLOCK_IF_START;
- type = BLOGC_TEMPLATE_IF_STMT;
- start = current;
- if_count++;
- break;
- }
- *err = blogc_error_parser(BLOGC_ERROR_TEMPLATE_PARSER,
- src, src_len, current,
- "'if' statements only allowed inside 'entry' and "
- "'listing' blocks.");
+ state = TEMPLATE_BLOCK_IF_START;
+ type = BLOGC_TEMPLATE_IF_STMT;
+ start = current;
+ if_count++;
break;
}
else if (0 == strncmp("endif", src + start, current - start)) {
- if (block_state == BLOCK_ENTRY || block_state == BLOCK_LISTING) {
- if (if_count > 0) {
- state = TEMPLATE_BLOCK_END;
- type = BLOGC_TEMPLATE_ENDIF_STMT;
- if_count--;
- break;
- }
- *err = blogc_error_parser(BLOGC_ERROR_TEMPLATE_PARSER,
- src, src_len, current,
- "'endif' statement without an open 'if' statement.");
+ if (if_count > 0) {
+ state = TEMPLATE_BLOCK_END;
+ type = BLOGC_TEMPLATE_ENDIF_STMT;
+ if_count--;
break;
}
*err = blogc_error_parser(BLOGC_ERROR_TEMPLATE_PARSER,
src, src_len, current,
- "'endif' statements only allowed inside 'entry' "
- "and 'listing' blocks.");
+ "'endif' statement without an open 'if' statement.");
break;
}
}
@@ -250,7 +236,6 @@ blogc_template_parse(const char *src, size_t src_len, blogc_error_t **err)
break;
if (c == ' ') {
if (0 == strncmp("not", src + start, current - start)) {
- block_state = BLOCK_ENTRY;
end = current;
state = TEMPLATE_BLOCK_IF_START;
type = BLOGC_TEMPLATE_IF_NOT_STMT;
@@ -293,16 +278,9 @@ blogc_template_parse(const char *src, size_t src_len, blogc_error_t **err)
if (c == ' ')
break;
if (c >= 'A' && c <= 'Z') {
- if (block_state == BLOCK_ENTRY || block_state == BLOCK_LISTING) {
- state = TEMPLATE_VARIABLE;
- type = BLOGC_TEMPLATE_VARIABLE_STMT;
- start = current;
- break;
- }
- *err = blogc_error_parser(BLOGC_ERROR_TEMPLATE_PARSER,
- src, src_len, current,
- "Variable statements only allowed inside 'entry' and "
- "'listing' blocks.");
+ state = TEMPLATE_VARIABLE;
+ type = BLOGC_TEMPLATE_VARIABLE_STMT;
+ start = current;
break;
}
*err = blogc_error_parser(BLOGC_ERROR_TEMPLATE_PARSER, src,
diff --git a/tests/check_renderer.c b/tests/check_renderer.c
index 539d122..f8acc14 100644
--- a/tests/check_renderer.c
+++ b/tests/check_renderer.c
@@ -68,7 +68,7 @@ test_render_entry(void **state)
assert_null(err);
b_slist_t *s = create_sources(1);
assert_non_null(s);
- char *out = blogc_render(l, s, false);
+ char *out = blogc_render(l, s, NULL, false);
assert_string_equal(out,
"foo\n"
"\n"
@@ -102,7 +102,7 @@ test_render_listing(void **state)
assert_null(err);
b_slist_t *s = create_sources(3);
assert_non_null(s);
- char *out = blogc_render(l, s, true);
+ char *out = blogc_render(l, s, NULL, true);
assert_string_equal(out,
"foo\n"
"fuuu\n"
@@ -138,7 +138,7 @@ test_render_if(void **state)
assert_null(err);
b_slist_t *s = create_sources(1);
assert_non_null(s);
- char *out = blogc_render(l, s, false);
+ char *out = blogc_render(l, s, NULL, false);
assert_string_equal(out,
"\n"
"\n"
@@ -167,7 +167,7 @@ test_render_if2(void **state)
assert_null(err);
b_slist_t *s = create_sources(1);
assert_non_null(s);
- char *out = blogc_render(l, s, false);
+ char *out = blogc_render(l, s, NULL, false);
assert_string_equal(out,
"\n"
"guda\n"
@@ -198,7 +198,7 @@ test_render_if3(void **state)
assert_null(err);
b_slist_t *s = create_sources(1);
assert_non_null(s);
- char *out = blogc_render(l, s, false);
+ char *out = blogc_render(l, s, NULL, false);
assert_string_equal(out,
"\n"
"guda\n"
@@ -231,7 +231,7 @@ test_render_if_not(void **state)
assert_null(err);
b_slist_t *s = create_sources(1);
assert_non_null(s);
- char *out = blogc_render(l, s, false);
+ char *out = blogc_render(l, s, NULL, false);
assert_string_equal(out,
"\n"
"chunda\n"
@@ -249,7 +249,73 @@ test_render_if_not(void **state)
static void
test_render_null(void **state)
{
- assert_null(blogc_render(NULL, NULL, false));
+ assert_null(blogc_render(NULL, NULL, NULL, false));
+}
+
+
+static void
+test_render_outside_block(void **state)
+{
+ const char *str =
+ "{% if GUDA %}bola{% endif %}\n"
+ "{{ BOLA }}\n"
+ "{% if not CHUNDA %}lol{% endif %}\n";
+ blogc_error_t *err = NULL;
+ b_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ assert_non_null(l);
+ assert_null(err);
+ b_slist_t *s = create_sources(1);
+ assert_non_null(s);
+ b_trie_t *c = b_trie_new(free);
+ b_trie_insert(c, "GUDA", b_strdup("asd"));
+ char *out = blogc_render(l, s, c, false);
+ assert_string_equal(out,
+ "bola\n"
+ "\n"
+ "lol\n");
+ b_trie_free(c);
+ blogc_template_free_stmts(l);
+ b_slist_free_full(s, (b_free_func_t) b_trie_free);
+ free(out);
+}
+
+
+static void
+test_render_prefer_local_variable(void **state)
+{
+ const char *str =
+ "{% block entry %}\n"
+ "{% if LOL %}{{ LOL }}{% endif %}\n"
+ "{% if not CHUNDA %}chunda\n"
+ "{% if GUDA %}{{ GUDA }}\n"
+ "{% if not BOLA %}bola\n"
+ "{% endif %}\n"
+ "{% endif %}\n"
+ "{% endif %}\n"
+ "{% endblock %}\n";
+ blogc_error_t *err = NULL;
+ b_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ assert_non_null(l);
+ assert_null(err);
+ b_slist_t *s = create_sources(1);
+ assert_non_null(s);
+ b_trie_t *c = b_trie_new(free);
+ b_trie_insert(c, "GUDA", b_strdup("hehe"));
+ b_trie_insert(c, "LOL", b_strdup("hmm"));
+ char *out = blogc_render(l, s, c, false);
+ assert_string_equal(out,
+ "\n"
+ "hmm\n"
+ "chunda\n"
+ "zxc\n"
+ "\n"
+ "\n"
+ "\n"
+ "\n");
+ b_trie_free(c);
+ blogc_template_free_stmts(l);
+ b_slist_free_full(s, (b_free_func_t) b_trie_free);
+ free(out);
}
@@ -263,7 +329,9 @@ main(void)
unit_test(test_render_if2),
unit_test(test_render_if3),
unit_test(test_render_if_not),
+ unit_test(test_render_outside_block),
unit_test(test_render_null),
+ unit_test(test_render_prefer_local_variable),
};
return run_tests(tests);
}
diff --git a/tests/check_template_parser.c b/tests/check_template_parser.c
index 7d0436e..bbef763 100644
--- a/tests/check_template_parser.c
+++ b/tests/check_template_parser.c
@@ -227,6 +227,40 @@ test_template_parse_html(void **state)
static void
+test_template_parse_if_and_var_outside_block(void **state)
+{
+ const char *a =
+ "{% if GUDA %}bola{% endif %}\n"
+ "{{ BOLA }}\n"
+ "{% if not CHUNDA %}{{ CHUNDA }}{% endif %}\n";
+ 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, "GUDA", BLOGC_TEMPLATE_IF_STMT);
+ blogc_assert_template_stmt(stmts->next, "bola",
+ BLOGC_TEMPLATE_CONTENT_STMT);
+ blogc_assert_template_stmt(stmts->next->next, NULL,
+ BLOGC_TEMPLATE_ENDIF_STMT);
+ blogc_assert_template_stmt(stmts->next->next->next, "\n",
+ BLOGC_TEMPLATE_CONTENT_STMT);
+ blogc_assert_template_stmt(stmts->next->next->next->next, "BOLA",
+ BLOGC_TEMPLATE_VARIABLE_STMT);
+ blogc_assert_template_stmt(stmts->next->next->next->next->next, "\n",
+ BLOGC_TEMPLATE_CONTENT_STMT);
+ blogc_assert_template_stmt(stmts->next->next->next->next->next->next,
+ "CHUNDA", BLOGC_TEMPLATE_IF_NOT_STMT);
+ b_slist_t *tmp = stmts->next->next->next->next->next->next->next;
+ blogc_assert_template_stmt(tmp, "CHUNDA", BLOGC_TEMPLATE_VARIABLE_STMT);
+ blogc_assert_template_stmt(tmp->next, NULL, BLOGC_TEMPLATE_ENDIF_STMT);
+ blogc_assert_template_stmt(tmp->next->next, "\n",
+ BLOGC_TEMPLATE_CONTENT_STMT);
+ assert_null(tmp->next->next->next);
+ blogc_template_free_stmts(stmts);
+}
+
+
+static void
test_template_parse_invalid_block_start(void **state)
{
const char *a = "{% ASD %}\n";
@@ -277,38 +311,6 @@ test_template_parse_invalid_block_not_open(void **state)
static void
-test_template_parse_invalid_if_outside_block(void **state)
-{
- const char *a = "{% if BOLA %}";
- blogc_error_t *err = NULL;
- b_slist_t *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,
- "'if' statements only allowed inside 'entry' and 'listing' blocks.\n"
- "Error occurred near to ' BOLA %}'");
- blogc_error_free(err);
-}
-
-
-static void
-test_template_parse_invalid_if_inside_listing_once_block(void **state)
-{
- const char *a = "{% block listing_once %}{% if BOLA %}{% endblock %}";
- blogc_error_t *err = NULL;
- b_slist_t *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,
- "'if' statements only allowed inside 'entry' and 'listing' blocks.\n"
- "Error occurred near to ' BOLA %}{% endblock %}'");
- blogc_error_free(err);
-}
-
-
-static void
test_template_parse_invalid_endif_not_open(void **state)
{
const char *a = "{% block listing %}{% endif %}{% endblock %}\n";
@@ -325,38 +327,6 @@ test_template_parse_invalid_endif_not_open(void **state)
static void
-test_template_parse_invalid_endif_outside_block(void **state)
-{
- const char *a = "{% endif %}\n";
- blogc_error_t *err = NULL;
- b_slist_t *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,
- "'endif' statements only allowed inside 'entry' and 'listing' blocks.\n"
- "Error occurred near to ' %}'");
- blogc_error_free(err);
-}
-
-
-static void
-test_template_parse_invalid_endif_inside_listing_once_block(void **state)
-{
- const char *a = "{% block listing_once %}{% endif %}{% endblock %}\n";
- blogc_error_t *err = NULL;
- b_slist_t *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,
- "'endif' statements only allowed inside 'entry' and 'listing' blocks.\n"
- "Error occurred near to ' %}{% endblock %}'");
- blogc_error_free(err);
-}
-
-
-static void
test_template_parse_invalid_block_name(void **state)
{
const char *a = "{% chunda %}\n";
@@ -469,38 +439,6 @@ test_template_parse_invalid_block_end(void **state)
static void
-test_template_parse_invalid_variable_outside_block(void **state)
-{
- const char *a = "{{ BOLA }}\n";
- blogc_error_t *err = NULL;
- b_slist_t *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,
- "Variable statements only allowed inside 'entry' and 'listing' blocks.\n"
- "Error occurred near to 'BOLA }}'");
- blogc_error_free(err);
-}
-
-
-static void
-test_template_parse_invalid_variable_inside_listing_once_block(void **state)
-{
- const char *a = "{% block listing_once %}{{ BOLA }}{% endblock %}\n";
- blogc_error_t *err = NULL;
- b_slist_t *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,
- "Variable statements only allowed inside 'entry' and 'listing' blocks.\n"
- "Error occurred near to 'BOLA }}{% endblock %}'");
- blogc_error_free(err);
-}
-
-
-static void
test_template_parse_invalid_variable_name(void **state)
{
const char *a = "{% block entry %}{{ bola }}{% endblock %}\n";
@@ -614,14 +552,11 @@ main(void)
const UnitTest tests[] = {
unit_test(test_template_parse),
unit_test(test_template_parse_html),
+ unit_test(test_template_parse_if_and_var_outside_block),
unit_test(test_template_parse_invalid_block_start),
unit_test(test_template_parse_invalid_block_nested),
unit_test(test_template_parse_invalid_block_not_open),
- unit_test(test_template_parse_invalid_if_outside_block),
- unit_test(test_template_parse_invalid_if_inside_listing_once_block),
unit_test(test_template_parse_invalid_endif_not_open),
- unit_test(test_template_parse_invalid_endif_outside_block),
- unit_test(test_template_parse_invalid_endif_inside_listing_once_block),
unit_test(test_template_parse_invalid_block_name),
unit_test(test_template_parse_invalid_block_type_start),
unit_test(test_template_parse_invalid_block_type),
@@ -629,8 +564,6 @@ main(void)
unit_test(test_template_parse_invalid_if_condition),
unit_test(test_template_parse_invalid_if_variable),
unit_test(test_template_parse_invalid_block_end),
- unit_test(test_template_parse_invalid_variable_outside_block),
- unit_test(test_template_parse_invalid_variable_inside_listing_once_block),
unit_test(test_template_parse_invalid_variable_name),
unit_test(test_template_parse_invalid_variable_name2),
unit_test(test_template_parse_invalid_variable_end),