@@ -25,20 +25,26 @@ suite('Built-in functions', function() {
25
25
test ( 'missing argument' , function ( ) {
26
26
let msg ;
27
27
28
+ errors = [ ] ;
28
29
msg = bundle . getMessage ( 'num-decimal' ) ;
29
- assert . strictEqual ( bundle . formatPattern ( msg . value , { } , errors ) , '{$arg}' ) ;
30
+ assert . strictEqual ( bundle . formatPattern ( msg . value , { } , errors ) , '{NUMBER( $arg) }' ) ;
30
31
assert . strictEqual ( errors . length , 1 ) ;
31
- assert . ok ( errors . pop ( ) instanceof ReferenceError ) ;
32
+ assert . ok ( errors [ 0 ] instanceof ReferenceError ) ;
33
+ assert . strictEqual ( errors [ 0 ] . message , "Unknown variable: $arg" ) ;
32
34
35
+ errors = [ ] ;
33
36
msg = bundle . getMessage ( 'num-percent' ) ;
34
- assert . strictEqual ( bundle . formatPattern ( msg . value , { } , errors ) , '{$arg}' ) ;
37
+ assert . strictEqual ( bundle . formatPattern ( msg . value , { } , errors ) , '{NUMBER( $arg) }' ) ;
35
38
assert . strictEqual ( errors . length , 1 ) ;
36
- assert . ok ( errors . pop ( ) instanceof ReferenceError ) ;
39
+ assert . ok ( errors [ 0 ] instanceof ReferenceError ) ;
40
+ assert . strictEqual ( errors [ 0 ] . message , "Unknown variable: $arg" ) ;
37
41
42
+ errors = [ ] ;
38
43
msg = bundle . getMessage ( 'num-bad-opt' ) ;
39
- assert . strictEqual ( bundle . formatPattern ( msg . value , { } , errors ) , '{$arg}' ) ;
44
+ assert . strictEqual ( bundle . formatPattern ( msg . value , { } , errors ) , '{NUMBER( $arg) }' ) ;
40
45
assert . strictEqual ( errors . length , 1 ) ;
41
- assert . ok ( errors . pop ( ) instanceof ReferenceError ) ;
46
+ assert . ok ( errors [ 0 ] instanceof ReferenceError ) ;
47
+ assert . strictEqual ( errors [ 0 ] . message , "Unknown variable: $arg" ) ;
42
48
} ) ;
43
49
44
50
test ( 'number argument' , function ( ) {
@@ -55,66 +61,87 @@ suite('Built-in functions', function() {
55
61
56
62
msg = bundle . getMessage ( 'num-bad-opt' ) ;
57
63
assert . strictEqual ( bundle . formatPattern ( msg . value , args , errors ) , '1' ) ;
58
- assert . strictEqual ( errors . length , 0 ) ;
64
+ assert . strictEqual ( errors . length , 1 ) ;
65
+ assert . ok ( errors [ 0 ] instanceof RangeError ) ; // Invalid option value
59
66
} ) ;
60
67
61
- // XXX Functions should report errors.
62
- // https://github.com/projectfluent/fluent.js/issues/106
63
68
test ( 'string argument' , function ( ) {
64
69
const args = { arg : "Foo" } ;
65
70
let msg ;
66
71
72
+ errors = [ ] ;
67
73
msg = bundle . getMessage ( 'num-decimal' ) ;
68
74
assert . strictEqual ( bundle . formatPattern ( msg . value , args , errors ) , '{NUMBER()}' ) ;
69
- assert . strictEqual ( errors . length , 0 ) ;
75
+ assert . strictEqual ( errors . length , 1 ) ;
76
+ assert . ok ( errors [ 0 ] instanceof TypeError ) ;
77
+ assert . strictEqual ( errors [ 0 ] . message , "Invalid argument type to NUMBER" ) ;
70
78
79
+ errors = [ ] ;
71
80
msg = bundle . getMessage ( 'num-percent' ) ;
72
81
assert . strictEqual ( bundle . formatPattern ( msg . value , args , errors ) , '{NUMBER()}' ) ;
73
- assert . strictEqual ( errors . length , 0 ) ;
82
+ assert . strictEqual ( errors . length , 1 ) ;
83
+ assert . ok ( errors [ 0 ] instanceof TypeError ) ;
84
+ assert . strictEqual ( errors [ 0 ] . message , "Invalid argument type to NUMBER" ) ;
74
85
86
+ errors = [ ] ;
75
87
msg = bundle . getMessage ( 'num-bad-opt' ) ;
76
88
assert . strictEqual ( bundle . formatPattern ( msg . value , args , errors ) , '{NUMBER()}' ) ;
77
- assert . strictEqual ( errors . length , 0 ) ;
89
+ assert . strictEqual ( errors . length , 1 ) ;
90
+ assert . ok ( errors [ 0 ] instanceof TypeError ) ;
91
+ assert . strictEqual ( errors [ 0 ] . message , "Invalid argument type to NUMBER" ) ;
78
92
} ) ;
79
93
80
- // XXX Functions should report errors.
81
- // https://github.com/projectfluent/fluent.js/issues/106
82
94
test ( 'date argument' , function ( ) {
83
95
const date = new Date ( '2016-09-29' ) ;
84
96
const args = { arg : date } ;
85
97
let msg ;
86
98
99
+ errors = [ ] ;
87
100
msg = bundle . getMessage ( 'num-decimal' ) ;
88
101
assert . strictEqual ( bundle . formatPattern ( msg . value , args , errors ) , '{NUMBER()}' ) ;
89
- assert . strictEqual ( errors . length , 0 ) ;
102
+ assert . strictEqual ( errors . length , 1 ) ;
103
+ assert . ok ( errors [ 0 ] instanceof TypeError ) ;
104
+ assert . strictEqual ( errors [ 0 ] . message , "Invalid argument type to NUMBER" ) ;
90
105
106
+ errors = [ ] ;
91
107
msg = bundle . getMessage ( 'num-percent' ) ;
92
108
assert . strictEqual ( bundle . formatPattern ( msg . value , args , errors ) , '{NUMBER()}' ) ;
93
- assert . strictEqual ( errors . length , 0 ) ;
109
+ assert . strictEqual ( errors . length , 1 ) ;
110
+ assert . ok ( errors [ 0 ] instanceof TypeError ) ;
111
+ assert . strictEqual ( errors [ 0 ] . message , "Invalid argument type to NUMBER" ) ;
94
112
113
+ errors = [ ] ;
95
114
msg = bundle . getMessage ( 'num-bad-opt' ) ;
96
115
assert . strictEqual ( bundle . formatPattern ( msg . value , args , errors ) , '{NUMBER()}' ) ;
97
- assert . strictEqual ( errors . length , 0 ) ;
116
+ assert . strictEqual ( errors . length , 1 ) ;
117
+ assert . ok ( errors [ 0 ] instanceof TypeError ) ;
118
+ assert . strictEqual ( errors [ 0 ] . message , "Invalid argument type to NUMBER" ) ;
98
119
} ) ;
99
120
100
121
test ( 'invalid argument' , function ( ) {
101
122
const args = { arg : [ ] } ;
102
123
let msg ;
103
124
125
+ errors = [ ] ;
104
126
msg = bundle . getMessage ( 'num-decimal' ) ;
105
- assert . strictEqual ( bundle . formatPattern ( msg . value , args , errors ) , '{$arg}' ) ;
127
+ assert . strictEqual ( bundle . formatPattern ( msg . value , args , errors ) , '{NUMBER( $arg) }' ) ;
106
128
assert . strictEqual ( errors . length , 1 ) ;
107
- assert . ok ( errors . pop ( ) instanceof TypeError ) ;
129
+ assert . ok ( errors [ 0 ] instanceof TypeError ) ;
130
+ assert . strictEqual ( errors [ 0 ] . message , "Variable type not supported: $arg, object" ) ;
108
131
132
+ errors = [ ] ;
109
133
msg = bundle . getMessage ( 'num-percent' ) ;
110
- assert . strictEqual ( bundle . formatPattern ( msg . value , args , errors ) , '{$arg}' ) ;
134
+ assert . strictEqual ( bundle . formatPattern ( msg . value , args , errors ) , '{NUMBER( $arg) }' ) ;
111
135
assert . strictEqual ( errors . length , 1 ) ;
112
- assert . ok ( errors . pop ( ) instanceof TypeError ) ;
136
+ assert . ok ( errors [ 0 ] instanceof TypeError ) ;
137
+ assert . strictEqual ( errors [ 0 ] . message , "Variable type not supported: $arg, object" ) ;
113
138
139
+ errors = [ ] ;
114
140
msg = bundle . getMessage ( 'num-bad-opt' ) ;
115
- assert . strictEqual ( bundle . formatPattern ( msg . value , args , errors ) , '{$arg}' ) ;
141
+ assert . strictEqual ( bundle . formatPattern ( msg . value , args , errors ) , '{NUMBER( $arg) }' ) ;
116
142
assert . strictEqual ( errors . length , 1 ) ;
117
- assert . ok ( errors . pop ( ) instanceof TypeError ) ;
143
+ assert . ok ( errors [ 0 ] instanceof TypeError ) ;
144
+ assert . strictEqual ( errors [ 0 ] . message , "Variable type not supported: $arg, object" ) ;
118
145
} ) ;
119
146
} ) ;
120
147
@@ -131,20 +158,26 @@ suite('Built-in functions', function() {
131
158
test ( 'missing argument' , function ( ) {
132
159
let msg ;
133
160
161
+ errors = [ ] ;
134
162
msg = bundle . getMessage ( 'dt-default' ) ;
135
- assert . strictEqual ( bundle . formatPattern ( msg . value , { } , errors ) , '{$arg}' ) ;
163
+ assert . strictEqual ( bundle . formatPattern ( msg . value , { } , errors ) , '{DATETIME( $arg) }' ) ;
136
164
assert . strictEqual ( errors . length , 1 ) ;
137
- assert . ok ( errors . pop ( ) instanceof ReferenceError ) ;
165
+ assert . ok ( errors [ 0 ] instanceof ReferenceError ) ;
166
+ assert . strictEqual ( errors [ 0 ] . message , "Unknown variable: $arg" ) ;
138
167
168
+ errors = [ ] ;
139
169
msg = bundle . getMessage ( 'dt-month' ) ;
140
- assert . strictEqual ( bundle . formatPattern ( msg . value , { } , errors ) , '{$arg}' ) ;
170
+ assert . strictEqual ( bundle . formatPattern ( msg . value , { } , errors ) , '{DATETIME( $arg) }' ) ;
141
171
assert . strictEqual ( errors . length , 1 ) ;
142
- assert . ok ( errors . pop ( ) instanceof ReferenceError ) ;
172
+ assert . ok ( errors [ 0 ] instanceof ReferenceError ) ;
173
+ assert . strictEqual ( errors [ 0 ] . message , "Unknown variable: $arg" ) ;
143
174
175
+ errors = [ ] ;
144
176
msg = bundle . getMessage ( 'dt-bad-opt' ) ;
145
- assert . strictEqual ( bundle . formatPattern ( msg . value , { } , errors ) , '{$arg}' ) ;
177
+ assert . strictEqual ( bundle . formatPattern ( msg . value , { } , errors ) , '{DATETIME( $arg) }' ) ;
146
178
assert . strictEqual ( errors . length , 1 ) ;
147
- assert . ok ( errors . pop ( ) instanceof ReferenceError ) ;
179
+ assert . ok ( errors [ 0 ] instanceof ReferenceError ) ;
180
+ assert . strictEqual ( errors [ 0 ] . message , "Unknown variable: $arg" ) ;
148
181
} ) ;
149
182
150
183
test ( 'Date argument' , function ( ) {
@@ -172,65 +205,86 @@ suite('Built-in functions', function() {
172
205
// may vary depending on the TZ:
173
206
// Thu Sep 29 2016 02:00:00 GMT+0200 (CEST)
174
207
assert . strictEqual ( bundle . formatPattern ( msg . value , args , errors ) , date . toString ( ) ) ;
175
- assert . strictEqual ( errors . length , 0 ) ;
208
+ assert . strictEqual ( errors . length , 1 ) ;
209
+ assert . ok ( errors [ 0 ] instanceof RangeError ) ; // Invalid option value
176
210
} ) ;
177
211
178
- // XXX Functions should report errors.
179
- // https://github.com/projectfluent/fluent.js/issues/106
180
212
test ( 'number argument' , function ( ) {
181
213
let args = { arg : 1 } ;
182
214
let msg ;
183
215
216
+ errors = [ ] ;
184
217
msg = bundle . getMessage ( 'dt-default' ) ;
185
218
assert . strictEqual ( bundle . formatPattern ( msg . value , args , errors ) , '{DATETIME()}' ) ;
186
- assert . strictEqual ( errors . length , 0 ) ;
219
+ assert . strictEqual ( errors . length , 1 ) ;
220
+ assert . ok ( errors [ 0 ] instanceof TypeError ) ;
221
+ assert . strictEqual ( errors [ 0 ] . message , "Invalid argument type to DATETIME" ) ;
187
222
223
+ errors = [ ] ;
188
224
msg = bundle . getMessage ( 'dt-month' ) ;
189
225
assert . strictEqual ( bundle . formatPattern ( msg . value , args , errors ) , '{DATETIME()}' ) ;
190
- assert . strictEqual ( errors . length , 0 ) ;
226
+ assert . strictEqual ( errors . length , 1 ) ;
227
+ assert . ok ( errors [ 0 ] instanceof TypeError ) ;
228
+ assert . strictEqual ( errors [ 0 ] . message , "Invalid argument type to DATETIME" ) ;
191
229
230
+ errors = [ ] ;
192
231
msg = bundle . getMessage ( 'dt-bad-opt' ) ;
193
232
assert . strictEqual ( bundle . formatPattern ( msg . value , args , errors ) , '{DATETIME()}' ) ;
194
- assert . strictEqual ( errors . length , 0 ) ;
233
+ assert . strictEqual ( errors . length , 1 ) ;
234
+ assert . ok ( errors [ 0 ] instanceof TypeError ) ;
235
+ assert . strictEqual ( errors [ 0 ] . message , "Invalid argument type to DATETIME" ) ;
195
236
} ) ;
196
237
197
- // XXX Functions should report errors.
198
- // https://github.com/projectfluent/fluent.js/issues/106
199
238
test ( 'string argument' , function ( ) {
200
239
let args = { arg : 'Foo' } ;
201
240
let msg ;
202
241
242
+ errors = [ ] ;
203
243
msg = bundle . getMessage ( 'dt-default' ) ;
204
244
assert . strictEqual ( bundle . formatPattern ( msg . value , args , errors ) , '{DATETIME()}' ) ;
205
- assert . strictEqual ( errors . length , 0 ) ;
245
+ assert . strictEqual ( errors . length , 1 ) ;
246
+ assert . ok ( errors [ 0 ] instanceof TypeError ) ;
247
+ assert . strictEqual ( errors [ 0 ] . message , "Invalid argument type to DATETIME" ) ;
206
248
249
+ errors = [ ] ;
207
250
msg = bundle . getMessage ( 'dt-month' ) ;
208
251
assert . strictEqual ( bundle . formatPattern ( msg . value , args , errors ) , '{DATETIME()}' ) ;
209
- assert . strictEqual ( errors . length , 0 ) ;
252
+ assert . strictEqual ( errors . length , 1 ) ;
253
+ assert . ok ( errors [ 0 ] instanceof TypeError ) ;
254
+ assert . strictEqual ( errors [ 0 ] . message , "Invalid argument type to DATETIME" ) ;
210
255
256
+ errors = [ ] ;
211
257
msg = bundle . getMessage ( 'dt-bad-opt' ) ;
212
258
assert . strictEqual ( bundle . formatPattern ( msg . value , args , errors ) , '{DATETIME()}' ) ;
213
- assert . strictEqual ( errors . length , 0 ) ;
259
+ assert . strictEqual ( errors . length , 1 ) ;
260
+ assert . ok ( errors [ 0 ] instanceof TypeError ) ;
261
+ assert . strictEqual ( errors [ 0 ] . message , "Invalid argument type to DATETIME" ) ;
214
262
} ) ;
215
263
216
264
test ( 'invalid argument' , function ( ) {
217
265
let args = { arg : [ ] } ;
218
266
let msg ;
219
267
268
+ errors = [ ] ;
220
269
msg = bundle . getMessage ( 'dt-default' ) ;
221
- assert . strictEqual ( bundle . formatPattern ( msg . value , args , errors ) , '{$arg}' ) ;
270
+ assert . strictEqual ( bundle . formatPattern ( msg . value , args , errors ) , '{DATETIME( $arg) }' ) ;
222
271
assert . strictEqual ( errors . length , 1 ) ;
223
- assert . ok ( errors . pop ( ) instanceof TypeError ) ;
272
+ assert . ok ( errors [ 0 ] instanceof TypeError ) ;
273
+ assert . strictEqual ( errors [ 0 ] . message , "Variable type not supported: $arg, object" ) ;
224
274
275
+ errors = [ ] ;
225
276
msg = bundle . getMessage ( 'dt-month' ) ;
226
- assert . strictEqual ( bundle . formatPattern ( msg . value , args , errors ) , '{$arg}' ) ;
277
+ assert . strictEqual ( bundle . formatPattern ( msg . value , args , errors ) , '{DATETIME( $arg) }' ) ;
227
278
assert . strictEqual ( errors . length , 1 ) ;
228
- assert . ok ( errors . pop ( ) instanceof TypeError ) ;
279
+ assert . ok ( errors [ 0 ] instanceof TypeError ) ;
280
+ assert . strictEqual ( errors [ 0 ] . message , "Variable type not supported: $arg, object" ) ;
229
281
282
+ errors = [ ] ;
230
283
msg = bundle . getMessage ( 'dt-bad-opt' ) ;
231
- assert . strictEqual ( bundle . formatPattern ( msg . value , args , errors ) , '{$arg}' ) ;
284
+ assert . strictEqual ( bundle . formatPattern ( msg . value , args , errors ) , '{DATETIME( $arg) }' ) ;
232
285
assert . strictEqual ( errors . length , 1 ) ;
233
- assert . ok ( errors . pop ( ) instanceof TypeError ) ;
286
+ assert . ok ( errors [ 0 ] instanceof TypeError ) ;
287
+ assert . strictEqual ( errors [ 0 ] . message , "Variable type not supported: $arg, object" ) ;
234
288
} ) ;
235
289
} ) ;
236
290
} ) ;
0 commit comments