Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e761964

Browse files
authored
Add tests from [email protected] (#696)
1 parent a4ec4a9 commit e761964

File tree

3 files changed

+163
-25
lines changed

3 files changed

+163
-25
lines changed

test/syntax-errors.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"{{}",
88
"{{}}}",
99
"{|foo| #markup}",
10-
"{/tag foo=bar}",
1110
"{{missing end brace}",
1211
"{{missing end braces",
1312
"{{missing end {$braces",
@@ -17,6 +16,10 @@
1716
"missing space {|foo|:func}",
1817
"missing space {|foo|@bar}",
1918
"missing space {:func@bar}",
19+
"missing space {:func @bar@baz}",
20+
"missing space {:func @bar=42@baz}",
21+
"missing space {+reserved@bar}",
22+
"missing space {&private@bar}",
2023
"bad {:} placeholder",
2124
"bad {\\u0000placeholder}",
2225
"no-equal {|42| :number minimumFractionDigits 2}",

test/test-core.json

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,19 @@
114114
}
115115
]
116116
},
117+
{
118+
"src": "{#tag foo=bar/}",
119+
"cleanSrc": "{#tag foo=bar /}",
120+
"exp": "",
121+
"parts": [
122+
{
123+
"type": "markup",
124+
"kind": "standalone",
125+
"name": "tag",
126+
"options": { "foo": "bar" }
127+
}
128+
]
129+
},
117130
{
118131
"src": "{#tag a:foo=|foo| b:bar=$bar}",
119132
"params": { "bar": "b a r" },
@@ -127,6 +140,18 @@
127140
}
128141
]
129142
},
143+
{
144+
"src": "{/tag foo=bar}",
145+
"exp": "",
146+
"parts": [
147+
{
148+
"type": "markup",
149+
"kind": "close",
150+
"name": "tag",
151+
"options": { "foo": "bar" }
152+
}
153+
]
154+
},
130155
{
131156
"src": "{42 @foo @bar=13}",
132157
"exp": "42",
@@ -136,5 +161,52 @@
136161
"src": "{42 @foo=$bar}",
137162
"exp": "42",
138163
"parts": [{ "type": "string", "value": "42" }]
164+
},
165+
{
166+
"src": "foo {+reserved}",
167+
"exp": "foo {+}",
168+
"parts": [
169+
{ "type": "literal", "value": "foo " },
170+
{ "type": "fallback", "source": "+" }
171+
],
172+
"errors": [{ "type": "unsupported-annotation" }]
173+
},
174+
{
175+
"src": "foo {&private}",
176+
"exp": "foo {&}",
177+
"parts": [
178+
{ "type": "literal", "value": "foo " },
179+
{ "type": "fallback", "source": "&" }
180+
],
181+
"errors": [{ "type": "unsupported-annotation" }]
182+
},
183+
{
184+
"src": "foo {?reserved @a @b=$c}",
185+
"exp": "foo {?}",
186+
"parts": [
187+
{ "type": "literal", "value": "foo " },
188+
{ "type": "fallback", "source": "?" }
189+
],
190+
"errors": [{ "type": "unsupported-annotation" }]
191+
},
192+
{
193+
"src": ".foo {42} {{bar}}",
194+
"exp": "bar",
195+
"parts": [{ "type": "literal", "value": "bar" }],
196+
"errors": [{ "type": "unsupported-statement" }]
197+
},
198+
{
199+
"src": ".foo{42}{{bar}}",
200+
"cleanSrc": ".foo {42} {{bar}}",
201+
"exp": "bar",
202+
"parts": [{ "type": "literal", "value": "bar" }],
203+
"errors": [{ "type": "unsupported-statement" }]
204+
},
205+
{
206+
"src": ".foo |}lit{| {42}{{bar}}",
207+
"cleanSrc": ".foo |}lit{| {42} {{bar}}",
208+
"exp": "bar",
209+
"parts": [{ "type": "literal", "value": "bar" }],
210+
"errors": [{ "type": "unsupported-statement" }]
139211
}
140212
]

test/test-functions.json

Lines changed: 87 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,85 @@
11
{
2+
"date": [
3+
{ "src": "{:date}", "exp": "{:date}", "errors": [{ "type": "bad-input" }] },
4+
{
5+
"src": "{horse :date}",
6+
"exp": "{|horse|}",
7+
"errors": [{ "name": "RangeError" }]
8+
},
9+
{ "src": "{|2006-01-02| :date}", "exp": "1/2/06" },
10+
{ "src": "{|2006-01-02T15:04:06| :date}", "exp": "1/2/06" },
11+
{ "src": "{|2006-01-02| :date style=long}", "exp": "January 2, 2006" },
12+
{
13+
"src": ".local $d = {|2006-01-02| :date style=long} {{{$d :date}}}",
14+
"exp": "January 2, 2006"
15+
},
16+
{
17+
"src": ".local $t = {|2006-01-02T15:04:06| :time} {{{$t :date}}}",
18+
"exp": "1/2/06"
19+
}
20+
],
21+
"time": [
22+
{ "src": "{:time}", "exp": "{:time}", "errors": [{ "type": "bad-input" }] },
23+
{
24+
"src": "{horse :time}",
25+
"exp": "{|horse|}",
26+
"errors": [{ "name": "RangeError" }]
27+
},
28+
{ "src": "{|2006-01-02T15:04:06| :time}", "exp": "3:04 PM" },
29+
{
30+
"src": "{|2006-01-02T15:04:06| :time style=medium}",
31+
"exp": "3:04:06 PM"
32+
},
33+
{
34+
"src": ".local $t = {|2006-01-02T15:04:06| :time style=medium} {{{$t :time}}}",
35+
"exp": "3:04:06 PM"
36+
},
37+
{
38+
"src": ".local $d = {|2006-01-02T15:04:06| :date} {{{$d :time}}}",
39+
"exp": "3:04 PM"
40+
}
41+
],
42+
"datetime": [
43+
{
44+
"src": "{:datetime}",
45+
"exp": "{:datetime}",
46+
"errors": [{ "type": "bad-input" }]
47+
},
48+
{
49+
"src": "{$x :datetime}",
50+
"exp": "{$x}",
51+
"params": { "x": true },
52+
"errors": [{ "type": "bad-input" }]
53+
},
54+
{
55+
"src": "{horse :datetime}",
56+
"exp": "{|horse|}",
57+
"errors": [{ "name": "RangeError" }]
58+
},
59+
{ "src": "{|2006-01-02T15:04:06| :datetime}", "exp": "1/2/06, 3:04 PM" },
60+
{
61+
"src": "{|2006-01-02T15:04:06| :datetime year=numeric month=|2-digit|}",
62+
"exp": "01/2006"
63+
},
64+
{
65+
"src": "{|2006-01-02T15:04:06| :datetime dateStyle=long}",
66+
"exp": "January 2, 2006"
67+
},
68+
{
69+
"src": "{|2006-01-02T15:04:06| :datetime timeStyle=medium}",
70+
"exp": "3:04:06 PM"
71+
},
72+
{
73+
"src": "{$dt :datetime}",
74+
"params": { "dt": "2006-01-02T15:04:06" },
75+
"exp": "1/2/06, 3:04 PM"
76+
},
77+
{
78+
"src": ".input {$dt :time style=medium} {{{$dt :datetime dateStyle=long}}}",
79+
"params": { "dt": "2006-01-02T15:04:06" },
80+
"exp": "January 2, 2006 at 3:04:06 PM"
81+
}
82+
],
283
"integer": [
384
{ "src": "hello {4.2 :integer}", "exp": "hello 4" },
485
{ "src": "hello {-4.20 :integer}", "exp": "hello -4" },
@@ -194,44 +275,26 @@
194275
{
195276
"src": ".match {$foo :ordinal} one {{st}} two {{nd}} few {{rd}} * {{th}}",
196277
"params": { "foo": 1 },
197-
"exp": "st"
198-
},
199-
{
200-
"src": ".match {$foo :ordinal} one {{st}} two {{nd}} few {{rd}} * {{th}}",
201-
"params": { "foo": 2 },
202-
"exp": "nd"
203-
},
204-
{
205-
"src": ".match {$foo :ordinal} one {{st}} two {{nd}} few {{rd}} * {{th}}",
206-
"params": { "foo": 3 },
207-
"exp": "rd"
208-
},
209-
{
210-
"src": ".match {$foo :ordinal} one {{st}} two {{nd}} few {{rd}} * {{th}}",
211-
"params": { "foo": 4 },
212-
"exp": "th"
278+
"exp": "th",
279+
"errors": [{ "type": "missing-func" }, { "type": "not-selectable" }]
213280
},
214281
{
215282
"src": "hello {42 :ordinal}",
216283
"exp": "hello {|42|}",
217-
"errors": [{ "type": "not-formattable" }]
284+
"errors": [{ "type": "missing-func" }]
218285
}
219286
],
220287
"plural": [
221288
{
222289
"src": ".match {$foo :plural} one {{one}} * {{other}}",
223290
"params": { "foo": 1 },
224-
"exp": "one"
225-
},
226-
{
227-
"src": ".match {$foo :plural} one {{one}} * {{other}}",
228-
"params": { "foo": 1.1 },
229-
"exp": "other"
291+
"exp": "other",
292+
"errors": [{ "type": "missing-func" }, { "type": "not-selectable" }]
230293
},
231294
{
232295
"src": "hello {42 :plural}",
233296
"exp": "hello {|42|}",
234-
"errors": [{ "type": "not-formattable" }]
297+
"errors": [{ "type": "missing-func" }]
235298
}
236299
],
237300
"string": [

0 commit comments

Comments
 (0)