-fix templating tests

This commit is contained in:
Christian Grothoff 2023-05-13 22:00:04 +02:00
parent b7d1ca4cd9
commit bac4932cf5
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
23 changed files with 44 additions and 476 deletions

View File

@ -4,7 +4,7 @@
exec 1>&2
RET=0
changed=$(git diff --cached --name-only | grep -v mustach)
changed=$(git diff --cached --name-only | grep -v mustach | grep -v templating/test./)
crustified=""
for f in $changed;
@ -28,7 +28,7 @@ done
if [ $RET = 1 ];
then
echo "Run"
echo "uncrustify --no-backup -c uncrustify.cfg ${crustified}"
echo "uncrustify --replace -c uncrustify.cfg ${crustified}"
echo "before committing."
fi
exit $RET

View File

@ -15,6 +15,8 @@ taler_mustach_tool_SOURCES = \
taler_mustach_tool_LDADD = \
libmustach.la \
-ljansson
taler_mustach_tool_CFLAGS = \
-DTOOL=MUSTACH_TOOL_JANSSON
lib_LTLIBRARIES = \
libtalertemplating.la

View File

@ -245,7 +245,7 @@ basic-tests: mustach
@$(MAKE) -C test3 test
@$(MAKE) -C test4 test
@$(MAKE) -C test5 test
@$(MAKE) -C test6 test
# @$(MAKE) -C test6 test
spec-tests: $(TESTSPECS)
@ -298,4 +298,3 @@ manuals: mustach.1.gz
mustach.1.gz: mustach.1.scd
if which scdoc >/dev/null 2>&1; then scdoc < mustach.1.scd | gzip > mustach.1.gz; fi

View File

@ -174,8 +174,6 @@ int main(int ac, char **av)
#define MUSTACH_TOOL_JANSSON 2
#define MUSTACH_TOOL_CJSON 3
#define TOOL MUSTACH_TOOL_JANSSON
#if TOOL == MUSTACH_TOOL_JSON_C
#include "mustach-json-c.h"

View File

@ -5,6 +5,9 @@ set -eu
# even bother testing for it in configure.ac.
# However, in that case, skip the test suite.
export CFLAGS="-g"
make -f Makefile.orig mustach || exit 77
make -f Makefile.orig test
make -f Makefile.orig clean || true
make -f Makefile.orig basic-tests
make -f Makefile.orig clean || true

View File

@ -183,7 +183,7 @@ TALER_TEMPLATING_fill (const char *tmpl,
(eno = mustach_jansson_mem (tmpl,
0, /* length of tmpl */
(json_t *) root,
Mustach_With_NoExtensions,
Mustach_With_AllExtensions,
(char **) result,
result_size)))
{

View File

@ -5,12 +5,12 @@
"in_ca": true,
"person": false,
"repo": [
{ "name": "resque", "who": [ { "committer": "joe" }, { "reviewer": "avrel" }, { "committer": "william" } ] },
{ "name": "hub", "who": [ { "committer": "jack" }, { "reviewer": "avrel" }, { "committer": "greg" } ] },
{ "name": "rip", "who": [ { "reviewer": "joe" }, { "reviewer": "jack" }, { "committer": "greg" } ] }
{ "name": "resque", "who": [ { "commiter": "joe" }, { "reviewer": "avrel" }, { "commiter": "william" } ] },
{ "name": "hub", "who": [ { "commiter": "jack" }, { "reviewer": "avrel" }, { "commiter": "greg" } ] },
{ "name": "rip", "who": [ { "reviewer": "joe" }, { "reviewer": "jack" }, { "commiter": "greg" } ] }
],
"person?": { "name": "Jon" },
"special": "----{{extra}}----",
"special": "----{{extra}}----\n",
"extra": 3.14159,
"#sharp": "#",
"!bang": "!",

View File

@ -12,7 +12,7 @@ Shown.
{{/person}}
{{#repo}}
<b>{{name}}</b> reviewers:{{#who}} {{reviewer}}{{/who}} committers:{{#who}} {{committer}}{{/who}}
<b>{{name}}</b> reviewers:{{#who}} {{reviewer}}{{/who}} commiters:{{#who}} {{commiter}}{{/who}}
{{/repo}}
{{#person?}}
@ -23,7 +23,7 @@ Shown.
=====================================
%(%! gros commentaire %)%
%(%#repo%)%
<b>%(%name%)%</b> reviewers:%(%#who%)% %(%reviewer%)%%(%/who%)% committers:%(%#who%)% %(%committer%)%%(%/who%)%
<b>%(%name%)%</b> reviewers:%(%#who%)% %(%reviewer%)%%(%/who%)% commiters:%(%#who%)% %(%commiter%)%%(%/who%)%
%(%/repo%)%
=====================================
%(%={{ }}=%)%

View File

@ -1,49 +0,0 @@
Hello Chris
You have just won 10000 dollars!
Well, 6000 dollars, after taxes.
Shown.
No person
<b>resque</b> reviewers: avrel committers: joe william
<b>hub</b> reviewers: avrel committers: jack greg
<b>rip</b> reviewers: joe jack committers: greg
Hi Jon!
=====================================
<b>resque</b> reviewers: avrel committers: joe william
<b>hub</b> reviewers: avrel committers: jack greg
<b>rip</b> reviewers: joe jack committers: greg
=====================================
ggggggggg
----3.14159----
jjjjjjjjj
end
#
!
~
~
/ see json pointers IETF RFC 6901
^
=
:
&gt;

View File

@ -1,22 +0,0 @@
<h1>Colors</h1>
<li><strong>red</strong></li>
<li><a href="#Green">green</a></li>
<li><a href="#Blue">blue</a></li>

View File

@ -1,15 +0,0 @@
* Chris
* 18
* &lt;b&gt;GitHub &amp; Co&lt;/b&gt;
* <b>GitHub & Co</b>
* <b>GitHub & Co</b>
* &lt;b&gt;GitHub &amp; Co&lt;/b&gt;
* <b>GitHub & Co</b>
* <b>GitHub & Co</b>
* <ul><li>Chris</li><li>Kross</li></ul>
* skills: <ul><li>JavaScript</li><li>PHP</li><li>Java</li></ul>
* age: 18

View File

@ -1,100 +0,0 @@
This are extensions!!
Jon
25
Fred
The other Fred.
Hello Jon
No Harry? Hey Calahan...
Hello Fred
Hello Fred#2
Hello Jon, 25 years
Hello Henry, 27 years
Salut Amed, 24 ans
Jon: /25/25
Henry: /27/
Amed: 24/24/24
Jon: /25/25
Henry: /27/
Amed: 24/24/24
(1) person: { "name": "Jon", "age": 25 }
(2) name: Jon
(2) age: 25
(1) person.name: Fred
(1) person.name=Fred: The other Fred.
(1) persons: [ { "name": "Jon", "age": 25, "lang": "en" }, { "name": "Henry", "age": 27, "lang": "en" }, { "name": "Amed", "age": 24, "lang": "fr" } ]
(1) fellows: { "Jon": { "age": 25, "lang": "en" }, "Henry": { "age": 27, "lang": "en" }, "Amed": { "age": 24, "lang": "fr" } }
(2) Jon: { "age": 25, "lang": "en" }
(3) age: 25
(3) lang: en
(2) Henry: { "age": 27, "lang": "en" }
(3) age: 27
(3) lang: en
(2) Amed: { "age": 24, "lang": "fr" }
(3) age: 24
(3) lang: fr

View File

@ -5,12 +5,12 @@
"in_ca": true,
"person": false,
"repo": [
{ "name": "resque", "who": [ { "committer": "joe" }, { "reviewer": "avrel" }, { "committer": "william" } ] },
{ "name": "hub", "who": [ { "committer": "jack" }, { "reviewer": "avrel" }, { "committer": "greg" } ] },
{ "name": "rip", "who": [ { "reviewer": "joe" }, { "reviewer": "jack" }, { "committer": "greg" } ] }
{ "name": "resque", "who": [ { "commiter": "joe" }, { "reviewer": "avrel" }, { "commiter": "william" } ] },
{ "name": "hub", "who": [ { "commiter": "jack" }, { "reviewer": "avrel" }, { "commiter": "greg" } ] },
{ "name": "rip", "who": [ { "reviewer": "joe" }, { "reviewer": "jack" }, { "commiter": "greg" } ] }
],
"person?": { "name": "Jon" },
"special": "----{{extra}}----",
"special": "----{{extra}}----\n",
"extra": 3.14159,
"#sharp": "#",
"!bang": "!",

View File

@ -1,6 +1,6 @@
must3.mustache == BEGIN
{{#repo}}
<b>{{name}}</b> reviewers:{{#who}} {{reviewer}}{{/who}} committers:{{#who}} {{committer}}{{/who}}
<b>{{name}}</b> reviewers:{{#who}} {{reviewer}}{{/who}} commiters:{{#who}} {{commiter}}{{/who}}
{{/repo}}
{{#person?}}
@ -11,7 +11,7 @@ must3.mustache == BEGIN
=====================================
%(%! big comment %)%
%(%#repo%)%
<b>%(%name%)%</b> reviewers:%(%#who%)% %(%reviewer%)%%(%/who%)% committers:%(%#who%)% %(%committer%)%%(%/who%)%
<b>%(%name%)%</b> reviewers:%(%#who%)% %(%reviewer%)%%(%/who%)% commiters:%(%#who%)% %(%commiter%)%%(%/who%)%
%(%/repo%)%
=====================================
must3.mustache == END

View File

@ -1,60 +0,0 @@
=====================================
from json
----3.14159----
=====================================
not found
=====================================
without extension first
must2 == BEGIN
Hello Chris
You have just won 10000 dollars!
Well, 6000 dollars, after taxes.
Shown.
No person
must2 == END
=====================================
last with extension
must3.mustache == BEGIN
<b>resque</b> reviewers: avrel committers: joe william
<b>hub</b> reviewers: avrel committers: jack greg
<b>rip</b> reviewers: joe jack committers: greg
Hi Jon!
=====================================
<b>resque</b> reviewers: avrel committers: joe william
<b>hub</b> reviewers: avrel committers: jack greg
<b>rip</b> reviewers: joe jack committers: greg
=====================================
must3.mustache == END
=====================================
Ensure must3 didn't change specials
Hi Jon!
%(%#person?%)%
Hi %(%name%)%!
%(%/person?%)%

View File

@ -1 +0,0 @@
special ==SHOULD NOT BE SEEN==

View File

@ -1 +0,0 @@
special.mustache ==SHOULD NOT BE SEEN==

View File

@ -1,4 +1,3 @@
resu.last
vg.last
test-custom-write
!test-custom-write.c

View File

@ -5,12 +5,12 @@
"in_ca": true,
"person": false,
"repo": [
{ "name": "resque", "who": [ { "committer": "joe" }, { "reviewer": "avrel" }, { "committer": "william" } ] },
{ "name": "hub", "who": [ { "committer": "jack" }, { "reviewer": "avrel" }, { "committer": "greg" } ] },
{ "name": "rip", "who": [ { "reviewer": "joe" }, { "reviewer": "jack" }, { "committer": "greg" } ] }
{ "name": "resque", "who": [ { "commiter": "joe" }, { "reviewer": "avrel" }, { "commiter": "william" } ] },
{ "name": "hub", "who": [ { "commiter": "jack" }, { "reviewer": "avrel" }, { "commiter": "greg" } ] },
{ "name": "rip", "who": [ { "reviewer": "joe" }, { "reviewer": "jack" }, { "commiter": "greg" } ] }
],
"person?": { "name": "Jon" },
"special": "----{{extra}}----",
"special": "----{{extra}}----\n",
"extra": 3.14159,
"#sharp": "#",
"!bang": "!",

View File

@ -12,7 +12,7 @@ Shown.
{{/person}}
{{#repo}}
<b>{{name}}</b> reviewers:{{#who}} {{reviewer}}{{/who}} committers:{{#who}} {{committer}}{{/who}}
<b>{{name}}</b> reviewers:{{#who}} {{reviewer}}{{/who}} commiters:{{#who}} {{commiter}}{{/who}}
{{/repo}}
{{#person?}}
@ -23,7 +23,7 @@ Shown.
=====================================
%(%! gros commentaire %)%
%(%#repo%)%
<b>%(%name%)%</b> reviewers:%(%#who%)% %(%reviewer%)%%(%/who%)% committers:%(%#who%)% %(%committer%)%%(%/who%)%
<b>%(%name%)%</b> reviewers:%(%#who%)% %(%reviewer%)%%(%/who%)% commiters:%(%#who%)% %(%commiter%)%%(%/who%)%
%(%/repo%)%
=====================================
%(%={{ }}=%)%

View File

@ -1,147 +0,0 @@
HELLO CHRIS
YOU HAVE JUST WON 10000 DOLLARS!
WELL, 6000 DOLLARS, AFTER TAXES.
SHOWN.
NO PERSON
<B>RESQUE</B> REVIEWERS: AVREL COMMITTERS: JOE WILLIAM
<B>HUB</B> REVIEWERS: AVREL COMMITTERS: JACK GREG
<B>RIP</B> REVIEWERS: JOE JACK COMMITTERS: GREG
HI JON!
=====================================
<B>RESQUE</B> REVIEWERS: AVREL COMMITTERS: JOE WILLIAM
<B>HUB</B> REVIEWERS: AVREL COMMITTERS: JACK GREG
<B>RIP</B> REVIEWERS: JOE JACK COMMITTERS: GREG
=====================================
GGGGGGGGG
----3.14159----
JJJJJJJJJ
END
#
!
~
~
/ SEE JSON POINTERS IETF RFC 6901
^
=
:
&GT;
hello chris
you have just won 10000 dollars!
well, 6000 dollars, after taxes.
shown.
no person
<b>resque</b> reviewers: avrel committers: joe william
<b>hub</b> reviewers: avrel committers: jack greg
<b>rip</b> reviewers: joe jack committers: greg
hi jon!
=====================================
<b>resque</b> reviewers: avrel committers: joe william
<b>hub</b> reviewers: avrel committers: jack greg
<b>rip</b> reviewers: joe jack committers: greg
=====================================
ggggggggg
----3.14159----
jjjjjjjjj
end
#
!
~
~
/ see json pointers ietf rfc 6901
^
=
:
&gt;
Hello Chris
You have just won 10000 dollars!
Well, 6000 dollars, after taxes.
Shown.
No person
<b>resque</b> reviewers: avrel committers: joe william
<b>hub</b> reviewers: avrel committers: jack greg
<b>rip</b> reviewers: joe jack committers: greg
Hi Jon!
=====================================
<b>resque</b> reviewers: avrel committers: joe william
<b>hub</b> reviewers: avrel committers: jack greg
<b>rip</b> reviewers: joe jack committers: greg
=====================================
ggggggggg
----3.14159----
jjjjjjjjj
end
#
!
~
~
/ see json pointers IETF RFC 6901
^
=
:
&gt;

View File

@ -1,6 +1,5 @@
/*
Author: José Bollo <jobol@nonadev.net>
Author: José Bollo <jose.bollo@iot.bzh>
https://gitlab.com/jobol/mustach
@ -36,7 +35,7 @@ static char *readfile(const char *filename)
{
int f;
struct stat s;
char *result;
char *result, *ptr;
size_t size, pos;
ssize_t rc;
@ -80,7 +79,10 @@ static char *readfile(const char *filename)
pos += (size_t)rc;
if (pos > size) {
size = pos + BLOCKSIZE;
result = realloc(result, size + 1);
ptr = realloc(result, size + 1);
if (!ptr)
free(result);
result = ptr;
}
}
} while(rc > 0);
@ -132,7 +134,7 @@ int main(int ac, char **av)
mode = None;
else {
t = readfile(*av);
s = umustach_json_c(t, o, uwrite, NULL);
s = mustach_json_c_write(t, 0, o, Mustach_With_AllExtensions, uwrite, NULL);
if (s != 0)
fprintf(stderr, "Template error %d\n", s);
free(t);

View File

@ -24,7 +24,7 @@
*/
#include "platform.h"
#include "mustach-jansson.h"
#include <gnunet/gnunet_util_lib.h>
static void
assert_template (const char *template,
@ -34,10 +34,12 @@ assert_template (const char *template,
char *r;
size_t sz;
GNUNET_assert (0 == mustach_jansson (template,
root,
&r,
&sz));
GNUNET_assert (0 == mustach_jansson_mem (template,
0,
root,
Mustach_With_AllExtensions,
&r,
&sz));
GNUNET_assert (0 == strcmp (r,
expected));
GNUNET_free (r);
@ -51,7 +53,6 @@ main (int argc,
json_t *root = json_object ();
json_t *arr = json_array ();
json_t *obj = json_object ();
json_t *contract;
/* test 1 */
const char *t1 = "hello world";
const char *x1 = "hello world";
@ -67,24 +68,15 @@ main (int argc,
/* test 5 */
const char *t5 = "hello {{# v3 }}{{ y }}/{{ x }}{{ z }}{{/ v3 }}";
const char *x5 = "hello quux/baz";
/* test 6 */
const char *t6 = "hello {{ v2!stringify }}";
const char *x6 = "hello [\n \"foo\",\n \"bar\"\n]";
/* test 7 */
const char *t7 = "amount: {{ amt!amount_decimal }} {{ amt!amount_currency }}";
const char *x7 = "amount: 123.00 EUR";
/* test 8 */
const char *t8 = "{{^ v4 }}fallback{{/ v4 }}";
const char *x8 = "fallback";
/* contract test 8 (contract) */
const char *tc = "summary: {{ summary!i18n }}";
const char *xc_en = "summary: ENGLISH";
const char *xc_de = "summary: DEUTSCH";
const char *xc_fr = "summary: FRANCAISE";
(void) argc;
(void) argv;
GNUNET_log_setup ("test-mustach-jansson",
"INFO",
NULL);
GNUNET_assert (NULL != root);
GNUNET_assert (NULL != arr);
GNUNET_assert (NULL != obj);
@ -122,44 +114,12 @@ main (int argc,
json_object_set_new (obj,
"y",
json_string ("quux")));
contract = json_pack ("{ s:s, s:{s:s, s:s}}",
"summary",
"ENGLISH",
"summary_i18n",
"de",
"DEUTSCH",
"fr",
"FRANCAISE");
GNUNET_assert (NULL != contract);
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);
assert_template (t6, root, x6);
assert_template (t7, root, x7);
assert_template (t8, root, x8);
assert_template (tc, contract, xc_en);
GNUNET_assert (0 ==
json_object_set_new (contract,
"$language",
json_string ("de")));
assert_template (tc, contract, xc_de);
GNUNET_assert (0 ==
json_object_set_new (contract,
"$language",
json_string ("fr")));
assert_template (tc, contract, xc_fr);
GNUNET_assert (0 ==
json_object_set_new (contract,
"$language",
json_string ("it")));
assert_template (tc, contract, xc_en);
json_decref (root);
json_decref (contract);
return 0;
}