Skip to content

Commit 83602bc

Browse files
committed
cram tests for many error cases
1 parent 3f0cd8a commit 83602bc

19 files changed

+404
-0
lines changed

bin/test/errors/dune

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
(cram
2+
(deps %{bin:mustache}))

bin/test/errors/json-errors.t

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
$ touch empty.json
2+
$ echo '{ "foo": "Foo"; "bar": "Bar" }' > invalid.json
3+
$ echo '{{foo}}' > foo.mustache
4+
5+
Empty json file:
6+
$ mustache empty.json foo.mustache
7+
Fatal error: exception Ezjsonm.Parse_error(870828711, "JSON.of_buffer expected JSON text (JSON value)")
8+
[2]
9+
10+
Invalid json file:
11+
$ mustache invalid.json foo.mustache
12+
Fatal error: exception Ezjsonm.Parse_error(870828711, "JSON.of_buffer expected value separator or object end (',' or '}')")
13+
[2]

bin/test/errors/parsing-errors.t

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
$ echo '{ "foo": "Foo"}' > foo.json
2+
3+
Delimiter problems:
4+
$ PROBLEM=no-closing-mustache.mustache
5+
$ echo "{{foo" > $PROBLEM
6+
$ mustache foo.json $PROBLEM
7+
Line 2, character 0: syntax error.
8+
[3]
9+
10+
$ PROBLEM=one-closing-mustache.mustache
11+
$ echo "{{foo}" > $PROBLEM
12+
$ mustache foo.json $PROBLEM
13+
Lines 1-2, characters 6-0: syntax error.
14+
[3]
15+
16+
$ PROBLEM=eof-before-variable.mustache
17+
$ echo "{{" > $PROBLEM
18+
$ mustache foo.json $PROBLEM
19+
Line 2, character 0: ident expected.
20+
[3]
21+
22+
$ PROBLEM=eof-before-section.mustache
23+
$ echo "{{#" > $PROBLEM
24+
$ mustache foo.json $PROBLEM
25+
Line 2, character 0: ident expected.
26+
[3]
27+
28+
$ PROBLEM=eof-before-section-end.mustache
29+
$ echo "{{#foo}} {{.}} {{/" > $PROBLEM
30+
$ mustache foo.json $PROBLEM
31+
Line 2, character 0: ident expected.
32+
[3]
33+
34+
$ PROBLEM=eof-before-inverted-section.mustache
35+
$ echo "{{^" > $PROBLEM
36+
$ mustache foo.json $PROBLEM
37+
Line 2, character 0: ident expected.
38+
[3]
39+
40+
$ PROBLEM=eof-before-unescape.mustache
41+
$ echo "{{{" > $PROBLEM
42+
$ mustache foo.json $PROBLEM
43+
Line 2, character 0: ident expected.
44+
[3]
45+
46+
$ PROBLEM=eof-before-unescape.mustache
47+
$ echo "{{&" > $PROBLEM
48+
$ mustache foo.json $PROBLEM
49+
Line 2, character 0: ident expected.
50+
[3]
51+
52+
$ PROBLEM=eof-before-partial.mustache
53+
$ echo "{{>" > $PROBLEM
54+
$ mustache foo.json $PROBLEM
55+
Line 2, character 0: ident expected.
56+
[3]
57+
58+
$ PROBLEM=eof-in-comment.mustache
59+
$ echo "{{! non-terminated comment" > $PROBLEM
60+
$ mustache foo.json $PROBLEM
61+
Line 2, character 0: non-terminated comment.
62+
[3]
63+
64+
65+
Mismatches between opening and closing mustaches:
66+
67+
$ PROBLEM=two-three.mustache
68+
$ echo "{{ foo }}}" > $PROBLEM
69+
$ mustache foo.json $PROBLEM
70+
Lines 1-2, characters 10-0: syntax error.
71+
[3]
72+
73+
$ PROBLEM=three-two.mustache
74+
$ echo "{{{ foo }}" > $PROBLEM
75+
$ mustache foo.json $PROBLEM
76+
Lines 1-2, characters 10-0: syntax error.
77+
[3]
78+
79+
80+
Mismatch between section-start and section-end:
81+
82+
$ PROBLEM=foo-bar.mustache
83+
$ echo "{{#foo}} {{.}} {{/bar}}" > $PROBLEM
84+
$ mustache foo.json $PROBLEM
85+
Fatal error: exception Mustache_types.Invalid_template("Mismatched section foo with bar")
86+
[2]
87+
88+
$ PROBLEM=foo-not-closed.mustache
89+
$ echo "{{#foo}} {{.}} {{foo}}" > $PROBLEM
90+
$ mustache foo.json $PROBLEM
91+
Line 2, character 0: syntax error.
92+
[3]
93+
94+
$ PROBLEM=wrong-nesting.mustache
95+
$ echo "{{#bar}} {{#foo}} {{.}} {{/bar}} {{/foo}}" > $PROBLEM
96+
$ mustache foo.json $PROBLEM
97+
Fatal error: exception Mustache_types.Invalid_template("Mismatched section foo with bar")
98+
[2]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"title": "Some Title",
3+
"list": [
4+
{"data": "foo"},
5+
{"data": "bar"},
6+
{"data": "baz"}
7+
],
8+
"gro": {
9+
"first": "First",
10+
"second": "Second"
11+
},
12+
"name": "Some Name"
13+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Title: {{title}}
2+
3+
List:
4+
{{#list}}
5+
- {{data}}
6+
{{/list}}
7+
8+
Group:
9+
{{#group}}
10+
{{gro.first}}
11+
{{second}}
12+
{{/group}}
13+
14+
{{#name}}The variable "name" has value "{{name}}".{{/name}}
15+
{{^name}}The variable "name" is not set. {{/name}}
16+
17+
Last line.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"title": "Some Title",
3+
"list": [
4+
{"data": "foo"},
5+
{"data": "bar"},
6+
{"data": "baz"}
7+
],
8+
"group": {
9+
"fir": "First",
10+
"second": "Second"
11+
},
12+
"name": "Some Name"
13+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Title: {{title}}
2+
3+
List:
4+
{{#list}}
5+
- {{data}}
6+
{{/list}}
7+
8+
Group:
9+
{{#group}}
10+
{{group.fir}}
11+
{{second}}
12+
{{/group}}
13+
14+
{{#name}}The variable "name" has value "{{name}}".{{/name}}
15+
{{^name}}The variable "name" is not set. {{/name}}
16+
17+
Last line.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"title": "Some Title",
3+
"list": [
4+
{"data": "foo"},
5+
{"data": "bar"},
6+
{"data": "baz"}
7+
],
8+
"grop": {
9+
"first": "First",
10+
"second": "Second"
11+
},
12+
"name": "Some Name"
13+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Title: {{title}}
2+
3+
List:
4+
{{#list}}
5+
- {{data}}
6+
{{/list}}
7+
8+
Group:
9+
{{#group}}
10+
{{group.first}}
11+
{{second}}
12+
{{/group}}
13+
14+
{{#na}}The variable "name" has value "{{name}}".{{/na}}
15+
{{^name}}The variable "name" is not set. {{/name}}
16+
17+
Last line.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"title": "Some Title",
3+
"list": [
4+
{"data": "foo"},
5+
{"datum": "bar"},
6+
{"data": "baz"}
7+
],
8+
"group": {
9+
"first": "First",
10+
"second": "Second"
11+
},
12+
"name": "Some Name"
13+
}

0 commit comments

Comments
 (0)