summaryrefslogtreecommitdiff
path: root/src/mustach/test_mustach_jansson.c
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2020-08-20 23:08:13 +0530
committerFlorian Dold <florian.dold@gmail.com>2020-08-20 23:08:13 +0530
commit0a5308e71e7f65a9921d74e8d55b389654defca6 (patch)
tree5c5fef0b2fff39580fec0accb452ec688aa49c05 /src/mustach/test_mustach_jansson.c
parent9ed4a331019dab10c8bd37094e3dcde2efdac2e6 (diff)
downloadmerchant-0a5308e71e7f65a9921d74e8d55b389654defca6.tar.gz
merchant-0a5308e71e7f65a9921d74e8d55b389654defca6.tar.bz2
merchant-0a5308e71e7f65a9921d74e8d55b389654defca6.zip
jansson adapter for mustache templates
Diffstat (limited to 'src/mustach/test_mustach_jansson.c')
-rw-r--r--src/mustach/test_mustach_jansson.c80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/mustach/test_mustach_jansson.c b/src/mustach/test_mustach_jansson.c
new file mode 100644
index 00000000..8f1e37b6
--- /dev/null
+++ b/src/mustach/test_mustach_jansson.c
@@ -0,0 +1,80 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2014-2020 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 3, or
+ (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not, see
+ <http://www.gnu.org/licenses/>
+*/
+
+/**
+ * @file mustac/test_mustach_jansson.c
+ * @brief testcase to test the mustach/jansson integration
+ * @author Florian Dold
+ */
+#include "platform.h"
+#include "mustach-jansson.h"
+
+void
+assert_template (const char *template, json_t *root, const char *expected)
+{
+ char *r;
+ size_t sz;
+
+ GNUNET_assert (0 == mustach_jansson (template, root, &r, &sz));
+ GNUNET_assert (0 == strcmp (r, expected));
+ GNUNET_free (r);
+}
+
+int
+main (int argc,
+ char *const *argv)
+{
+ json_t *root = json_object ();
+ json_t *arr = json_array ();
+ json_t *obj = json_object();
+ /* test 1 */
+ char *t1 = "hello world";
+ char *x1 = "hello world";
+ /* test 2 */
+ char *t2 = "hello {{ v1 }}";
+ char *x2 = "hello world";
+ /* test 3 */
+ char *t3 = "hello {{ v3.x }}";
+ char *x3 = "hello baz";
+ /* test 4 */
+ char *t4 = "hello {{# v2 }}{{ . }}{{/ v2 }}";
+ char *x4 = "hello foobar";
+ /* test 5 */
+ char *t5 = "hello {{# v3 }}{{ y }}/{{ x }}{{ z }}{{/ v3 }}";
+ char *x5 = "hello quux/baz";
+
+ json_object_set_new (root, "v1", json_string ("world"));
+ json_array_append_new (arr, json_string ("foo"));
+ json_array_append_new (arr, json_string ("bar"));
+ json_object_set_new (root, "v2", arr);
+ json_object_set_new (root, "v3", obj);
+ json_object_set_new (obj, "x", json_string ("baz"));
+ json_object_set_new (obj, "y", json_string ("quux"));
+
+ assert_template (t1, root, x1);
+ assert_template (t2, root, x2);
+ assert_template (t3, root, x3);
+ assert_template (t4, root, x4);
+ assert_template (t5, root, x5);
+
+ json_decref (root);
+
+ return 0;
+}
+