aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2015-04-28 02:31:40 -0300
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2015-04-28 02:31:40 -0300
commit582cbc6cf67919ec189098817ab1e4541c8e761d (patch)
treedd045a9d6ba2a2a59ef161774988f0aedcc5c0cb /tests
parent5205db347cb9f56187c2ad5e767281a7a4016533 (diff)
downloadblogc-582cbc6cf67919ec189098817ab1e4541c8e761d.tar.gz
blogc-582cbc6cf67919ec189098817ab1e4541c8e761d.tar.bz2
blogc-582cbc6cf67919ec189098817ab1e4541c8e761d.zip
implemented datetime parsing/formatting
Diffstat (limited to 'tests')
-rw-r--r--tests/check_renderer.c121
1 files changed, 121 insertions, 0 deletions
diff --git a/tests/check_renderer.c b/tests/check_renderer.c
index f8acc14..681b821 100644
--- a/tests/check_renderer.c
+++ b/tests/check_renderer.c
@@ -28,10 +28,13 @@ create_sources(unsigned int count)
const char *s[] = {
"BOLA: asd\n"
"GUDA: zxc\n"
+ "DATE: 2015-01-02 03:04:05\n"
+ "DATE_FORMAT: %R\n"
"-----\n"
"ahahahahahahahaha",
"BOLA: asd2\n"
"GUDA: zxc2\n"
+ "DATE: 2014-02-03 04:05:06\n"
"-----\n"
"ahahahahahahahaha2",
"BOLA: asd3\n"
@@ -58,6 +61,8 @@ test_render_entry(void **state)
"foo\n"
"{% block listing_once %}fuuu{% endblock %}\n"
"{% block entry %}\n"
+ "{{ DATE }}\n"
+ "{% if DATE_FORMATTED %}{{ DATE_FORMATTED }}{% endif %}\n"
"{% if GUDA %}{{ GUDA }}{% endif %}\n"
"{% if CHUNDA %}{{ CHUNDA }}{% endif %}\n"
"{% endblock %}\n"
@@ -73,6 +78,8 @@ test_render_entry(void **state)
"foo\n"
"\n"
"\n"
+ "2015-01-02 03:04:05\n"
+ "03:04\n"
"zxc\n"
"\n"
"\n"
@@ -94,6 +101,7 @@ test_render_listing(void **state)
"{% if CHUNDA %}{{ CHUNDA }}{% endif %}\n"
"{% endblock %}\n"
"{% block listing %}\n"
+ "{% if DATE_FORMATTED %}{{ DATE_FORMATTED }}{% endif %}\n"
"bola: {% if BOLA %}{{ BOLA }}{% endif %}\n"
"{% endblock %}\n";
blogc_error_t *err = NULL;
@@ -108,10 +116,13 @@ test_render_listing(void **state)
"fuuu\n"
"\n"
"\n"
+ "03:04\n"
"bola: asd\n"
"\n"
+ "2014-02-03 04:05:06\n"
"bola: asd2\n"
"\n"
+ "\n"
"bola: asd3\n"
"\n");
blogc_template_free_stmts(l);
@@ -319,6 +330,109 @@ test_render_prefer_local_variable(void **state)
}
+static void
+test_get_variable(void **state)
+{
+ b_trie_t *g = b_trie_new(free);
+ b_trie_insert(g, "NAME", b_strdup("bola"));
+ b_trie_insert(g, "TITLE", b_strdup("bola2"));
+ b_trie_t *l = b_trie_new(free);
+ b_trie_insert(l, "NAME", b_strdup("chunda"));
+ b_trie_insert(l, "TITLE", b_strdup("chunda2"));
+ assert_string_equal(blogc_get_variable("NAME", g, l), "chunda");
+ assert_string_equal(blogc_get_variable("TITLE", g, l), "chunda2");
+ assert_null(blogc_get_variable("BOLA", g, l));
+ b_trie_free(g);
+ b_trie_free(l);
+}
+
+
+static void
+test_get_variable_only_local(void **state)
+{
+ b_trie_t *g = NULL;
+ b_trie_t *l = b_trie_new(free);
+ b_trie_insert(l, "NAME", b_strdup("chunda"));
+ b_trie_insert(l, "TITLE", b_strdup("chunda2"));
+ assert_string_equal(blogc_get_variable("NAME", g, l), "chunda");
+ assert_string_equal(blogc_get_variable("TITLE", g, l), "chunda2");
+ assert_null(blogc_get_variable("BOLA", g, l));
+ b_trie_free(l);
+}
+
+
+static void
+test_get_variable_only_global(void **state)
+{
+ b_trie_t *g = b_trie_new(free);
+ b_trie_insert(g, "NAME", b_strdup("bola"));
+ b_trie_insert(g, "TITLE", b_strdup("bola2"));
+ b_trie_t *l = NULL;
+ assert_string_equal(blogc_get_variable("NAME", g, l), "bola");
+ assert_string_equal(blogc_get_variable("TITLE", g, l), "bola2");
+ assert_null(blogc_get_variable("BOLA", g, l));
+ b_trie_free(g);
+}
+
+
+static void
+test_format_date(void **state)
+{
+ b_trie_t *g = b_trie_new(free);
+ b_trie_insert(g, "DATE_FORMAT", b_strdup("%H -- %j"));
+ b_trie_t *l = b_trie_new(free);
+ b_trie_insert(l, "DATE", b_strdup("2015-01-02 03:04:05"));
+ b_trie_insert(l, "DATE_FORMAT", b_strdup("%R"));
+ char *date = blogc_format_date(g, l);
+ assert_string_equal(date, "03:04");
+ free(date);
+ b_trie_free(g);
+ b_trie_free(l);
+}
+
+
+static void
+test_format_date_with_global_format(void **state)
+{
+ b_trie_t *g = b_trie_new(free);
+ b_trie_insert(g, "DATE_FORMAT", b_strdup("%H -- %j"));
+ b_trie_t *l = b_trie_new(free);
+ b_trie_insert(l, "DATE", b_strdup("2015-01-02 03:04:05"));
+ char *date = blogc_format_date(g, l);
+ assert_string_equal(date, "03 -- 002");
+ free(date);
+ b_trie_free(g);
+ b_trie_free(l);
+}
+
+
+static void
+test_format_date_without_format(void **state)
+{
+ b_trie_t *g = b_trie_new(free);
+ b_trie_t *l = b_trie_new(free);
+ b_trie_insert(l, "DATE", b_strdup("2015-01-02 03:04:05"));
+ char *date = blogc_format_date(g, l);
+ assert_string_equal(date, "2015-01-02 03:04:05");
+ free(date);
+ b_trie_free(g);
+ b_trie_free(l);
+}
+
+
+static void
+test_format_date_without_date(void **state)
+{
+ b_trie_t *g = b_trie_new(free);
+ b_trie_t *l = b_trie_new(free);
+ char *date = blogc_format_date(g, l);
+ assert_null(date);
+ free(date);
+ b_trie_free(g);
+ b_trie_free(l);
+}
+
+
int
main(void)
{
@@ -332,6 +446,13 @@ main(void)
unit_test(test_render_outside_block),
unit_test(test_render_null),
unit_test(test_render_prefer_local_variable),
+ unit_test(test_get_variable),
+ unit_test(test_get_variable_only_local),
+ unit_test(test_get_variable_only_global),
+ unit_test(test_format_date),
+ unit_test(test_format_date_with_global_format),
+ unit_test(test_format_date_without_format),
+ unit_test(test_format_date_without_date),
};
return run_tests(tests);
}