@@ -165,111 +165,111 @@ main() {
165
165
166
166
// PARSER ERRORS
167
167
it ('should throw a reasonable error for unconsumed tokens' , () {
168
- expectEval (")" ).toThrow ( 'Parser Error: Unconsumed token ) at column 1 in [)]' );
168
+ expectEval (")" ).toThrowWith (message : 'Parser Error: Unconsumed token ) at column 1 in [)]' );
169
169
});
170
170
171
171
172
172
it ('should throw on missing expected token' , () {
173
- expectEval ("a(b" ).toThrow ( 'Parser Error: Missing expected ) the end of the expression [a(b]' );
173
+ expectEval ("a(b" ).toThrowWith (message : 'Parser Error: Missing expected ) the end of the expression [a(b]' );
174
174
});
175
175
176
176
177
177
it ('should throw on bad assignment' , () {
178
- expectEval ("5=4" ).toThrow ( 'Parser Error: Expression 5 is not assignable at column 2 in [5=4]' );
179
- expectEval ("array[5=4]" ).toThrow ( 'Parser Error: Expression 5 is not assignable at column 8 in [array[5=4]]' );
178
+ expectEval ("5=4" ).toThrowWith (message : 'Parser Error: Expression 5 is not assignable at column 2 in [5=4]' );
179
+ expectEval ("array[5=4]" ).toThrowWith (message : 'Parser Error: Expression 5 is not assignable at column 8 in [array[5=4]]' );
180
180
});
181
181
182
182
183
183
it ('should throw on incorrect ternary operator syntax' , () {
184
- expectEval ("true?1" ).toThrow ( 'Parser Error: Conditional expression true?1 requires all 3 expressions' );
184
+ expectEval ("true?1" ).toThrowWith (message : 'Parser Error: Conditional expression true?1 requires all 3 expressions' );
185
185
});
186
186
187
187
188
188
it ('should throw on non-function function calls' , () {
189
- expectEval ("4()" ).toThrow ( '4 is not a function' );
189
+ expectEval ("4()" ).toThrowWith (message : '4 is not a function' );
190
190
});
191
191
192
192
it ("should throw on an unexpected token" , (){
193
193
expectEval ("[1,2] trac" )
194
- .toThrow ( 'Parser Error: \' trac\' is an unexpected token at column 7 in [[1,2] trac]' );
194
+ .toThrowWith (message : 'Parser Error: \' trac\' is an unexpected token at column 7 in [[1,2] trac]' );
195
195
});
196
196
197
197
it ('should fail gracefully when invoking non-function' , () {
198
198
expect (() {
199
199
parser ('a[0]()' ).eval ({'a' : [4 ]});
200
- }).toThrow ( 'a[0] is not a function' );
200
+ }).toThrowWith (message : 'a[0] is not a function' );
201
201
202
202
expect (() {
203
203
parser ('a[x()]()' ).eval ({'a' : [4 ], 'x' : () => 0 });
204
- }).toThrow ( 'a[x()] is not a function' );
204
+ }).toThrowWith (message : 'a[x()] is not a function' );
205
205
206
206
expect (() {
207
207
parser ('{}()' ).eval ({});
208
- }).toThrow ( '{} is not a function' );
208
+ }).toThrowWith (message : '{} is not a function' );
209
209
});
210
210
211
211
212
212
it ('should throw on undefined functions (relaxed message)' , () {
213
- expectEval ("notAFn()" ).toThrow ( 'notAFn' );
213
+ expectEval ("notAFn()" ).toThrowWith (message : 'notAFn' );
214
214
});
215
215
216
216
217
217
it ('should fail gracefully when missing a function (relaxed message)' , () {
218
218
expect (() {
219
219
parser ('doesNotExist()' ).eval ({});
220
- }).toThrow ( 'doesNotExist' );
220
+ }).toThrowWith (message : 'doesNotExist' );
221
221
222
222
expect (() {
223
223
parser ('exists(doesNotExist())' ).eval ({'exists' : () => true });
224
- }).toThrow ( 'doesNotExist' );
224
+ }).toThrowWith (message : 'doesNotExist' );
225
225
226
226
expect (() {
227
227
parser ('doesNotExists(exists())' ).eval ({'exists' : () => true });
228
- }).toThrow ( 'doesNotExist' );
228
+ }).toThrowWith (message : 'doesNotExist' );
229
229
230
230
expect (() {
231
231
parser ('doesNotExist(1)' ).eval ({});
232
- }).toThrow ( 'doesNotExist' );
232
+ }).toThrowWith (message : 'doesNotExist' );
233
233
234
234
expect (() {
235
235
parser ('doesNotExist(1, 2)' ).eval ({});
236
- }).toThrow ( 'doesNotExist' );
236
+ }).toThrowWith (message : 'doesNotExist' );
237
237
238
238
expect (() {
239
239
parser ('doesNotExist()' ).eval (new TestData ());
240
- }).toThrow ( 'doesNotExist' );
240
+ }).toThrowWith (message : 'doesNotExist' );
241
241
242
242
expect (() {
243
243
parser ('doesNotExist(1)' ).eval (new TestData ());
244
- }).toThrow ( 'doesNotExist' );
244
+ }).toThrowWith (message : 'doesNotExist' );
245
245
246
246
expect (() {
247
247
parser ('doesNotExist(1, 2)' ).eval (new TestData ());
248
- }).toThrow ( 'doesNotExist' );
248
+ }).toThrowWith (message : 'doesNotExist' );
249
249
250
250
expect (() {
251
251
parser ('a.doesNotExist()' ).eval ({'a' : {}});
252
- }).toThrow ( 'doesNotExist' );
252
+ }).toThrowWith (message : 'doesNotExist' );
253
253
254
254
expect (() {
255
255
parser ('a.doesNotExist(1)' ).eval ({'a' : {}});
256
- }).toThrow ( 'doesNotExist' );
256
+ }).toThrowWith (message : 'doesNotExist' );
257
257
258
258
expect (() {
259
259
parser ('a.doesNotExist(1, 2)' ).eval ({'a' : {}});
260
- }).toThrow ( 'doesNotExist' );
260
+ }).toThrowWith (message : 'doesNotExist' );
261
261
262
262
expect (() {
263
263
parser ('a.doesNotExist()' ).eval ({'a' : new TestData ()});
264
- }).toThrow ( 'doesNotExist' );
264
+ }).toThrowWith (message : 'doesNotExist' );
265
265
266
266
expect (() {
267
267
parser ('a.doesNotExist(1)' ).eval ({'a' : new TestData ()});
268
- }).toThrow ( 'doesNotExist' );
268
+ }).toThrowWith (message : 'doesNotExist' );
269
269
270
270
expect (() {
271
271
parser ('a.doesNotExist(1, 2)' ).eval ({'a' : new TestData ()});
272
- }).toThrow ( 'doesNotExist' );
272
+ }).toThrowWith (message : 'doesNotExist' );
273
273
});
274
274
275
275
@@ -278,7 +278,7 @@ main() {
278
278
279
279
expect (eval ('null' )).toBe (null );
280
280
expect (() => eval ('map.null' ))
281
- .toThrow ( "Identifier 'null' is a reserved word." );
281
+ .toThrowWith (message : "Identifier 'null' is a reserved word." );
282
282
});
283
283
284
284
@@ -304,14 +304,14 @@ main() {
304
304
it ('should pass exceptions through getters' , () {
305
305
expect (() {
306
306
parser ('boo' ).eval (new ScopeWithErrors ());
307
- }).toThrow ( 'boo to you' );
307
+ }).toThrowWith (message : 'boo to you' );
308
308
});
309
309
310
310
311
311
it ('should pass noSuchMethodExceptions through getters' , () {
312
312
expect (() {
313
313
parser ('getNoSuchMethod' ).eval (new ScopeWithErrors ());
314
- }).toThrow ( "null" );
314
+ }).toThrowWith (message : "null" );
315
315
// Dartium throws: The null object does not have a method 'iDontExist'
316
316
// Chrome throws: NullError: Cannot call "iDontExist$0" on null
317
317
// Firefox throws: NullError: null has no properties
@@ -321,14 +321,14 @@ main() {
321
321
it ('should pass exceptions through methods' , () {
322
322
expect (() {
323
323
parser ('foo()' ).eval (new ScopeWithErrors ());
324
- }).toThrow ( 'foo to you' );
324
+ }).toThrowWith (message : 'foo to you' );
325
325
});
326
326
327
327
328
328
it ('should fail if reflected object has no property' , () {
329
329
expect (() {
330
330
parser ('notAProperty' ).eval (new TestData ());
331
- }).toThrow ( "notAProperty" );
331
+ }).toThrowWith (message : "notAProperty" );
332
332
});
333
333
334
334
@@ -344,22 +344,22 @@ main() {
344
344
345
345
346
346
it ('should only allow identifier or keyword as formatter names' , () {
347
- expect (() => parser ('"Foo"|(' )).toThrow ( 'identifier or keyword' );
348
- expect (() => parser ('"Foo"|1234' )).toThrow ( 'identifier or keyword' );
349
- expect (() => parser ('"Foo"|"uppercase"' )).toThrow ( 'identifier or keyword' );
347
+ expect (() => parser ('"Foo"|(' )).toThrowWith (message : 'identifier or keyword' );
348
+ expect (() => parser ('"Foo"|1234' )).toThrowWith (message : 'identifier or keyword' );
349
+ expect (() => parser ('"Foo"|"uppercase"' )).toThrowWith (message : 'identifier or keyword' );
350
350
});
351
351
352
352
353
353
it ('should only allow identifier or keyword as member names' , () {
354
- expect (() => parser ('x.(' )).toThrow ( 'identifier or keyword' );
355
- expect (() => parser ('x. 1234' )).toThrow ( 'identifier or keyword' );
356
- expect (() => parser ('x."foo"' )).toThrow ( 'identifier or keyword' );
354
+ expect (() => parser ('x.(' )).toThrowWith (message : 'identifier or keyword' );
355
+ expect (() => parser ('x. 1234' )).toThrowWith (message : 'identifier or keyword' );
356
+ expect (() => parser ('x."foo"' )).toThrowWith (message : 'identifier or keyword' );
357
357
});
358
358
359
359
360
360
it ('should only allow identifier, string, or keyword as object literal key' , () {
361
- expect (() => parser ('{(:0}' )).toThrow ( 'expected identifier, keyword, or string' );
362
- expect (() => parser ('{1234:0}' )).toThrow ( 'expected identifier, keyword, or string' );
361
+ expect (() => parser ('{(:0}' )).toThrowWith (message : 'expected identifier, keyword, or string' );
362
+ expect (() => parser ('{1234:0}' )).toThrowWith (message : 'expected identifier, keyword, or string' );
363
363
});
364
364
});
365
365
@@ -433,15 +433,15 @@ main() {
433
433
it ('should rethrow an error from a function' , () {
434
434
expect (() {
435
435
parser ("causeException()" ).eval (new TestData ());
436
- }).toThrow ( 'NoSuchMethodError' );
436
+ }).toThrowWith (message : 'NoSuchMethodError' );
437
437
});
438
438
439
439
440
440
xit ('should throw a nice error for type mismatch' , () {
441
441
context['obj' ] = new SetterObject ();
442
442
expect (() {
443
443
eval ('obj.integer = "hello"' );
444
- }).toThrow ( "Eval Error: Caught type 'String' is not a subtype of type 'int' of 'value'. while evaling [obj.integer = \" hello\" ]" );
444
+ }).toThrowWith (message : "Eval Error: Caught type 'String' is not a subtype of type 'int' of 'value'. while evaling [obj.integer = \" hello\" ]" );
445
445
});
446
446
});
447
447
@@ -468,7 +468,7 @@ main() {
468
468
for (String reserved in RESERVED_WORDS ) {
469
469
expect (() {
470
470
parser ("o.$reserved ()" ).eval ({ 'o' : new Object () });
471
- }).toThrow ( 'Undefined function $reserved ' );
471
+ }).toThrowWith (message : 'Undefined function $reserved ' );
472
472
expect (parser ("o.$reserved ()" ).eval ({ 'o' : { reserved: () => reserved }})).toEqual (reserved);
473
473
}
474
474
});
@@ -499,7 +499,7 @@ main() {
499
499
if ([ "true" , "false" , "null" ].contains (reserved)) continue ;
500
500
expect (() {
501
501
parser ("$reserved ()" ).eval (new Object ());
502
- }).toThrow ( 'Undefined function $reserved ' );
502
+ }).toThrowWith (message : 'Undefined function $reserved ' );
503
503
expect (parser ("$reserved ()" ).eval ({ reserved: () => reserved })).toEqual (reserved);
504
504
}
505
505
});
@@ -644,7 +644,7 @@ main() {
644
644
645
645
it ('should catch NoSuchMethod' , () {
646
646
context = {'a' : {'b' : 23 }};
647
- expect (() => eval ('a.b.c.d' )).toThrow ( 'NoSuchMethod' );
647
+ expect (() => eval ('a.b.c.d' )).toThrowWith (message : 'NoSuchMethod' );
648
648
});
649
649
650
650
@@ -816,7 +816,7 @@ main() {
816
816
it ('should throw exception on non-closed bracket' , () {
817
817
expect (() {
818
818
eval ('[].count(' );
819
- }).toThrow ( 'Unexpected end of expression: [].count(' );
819
+ }).toThrowWith (message : 'Unexpected end of expression: [].count(' );
820
820
});
821
821
822
822
@@ -1058,16 +1058,16 @@ main() {
1058
1058
1059
1059
1060
1060
it ('should be an error to use the same name twice' , () {
1061
- expect (() => parser ('foo(a: 0, a: 1)' )).toThrow ( "Duplicate argument named 'a' at column 11" );
1062
- expect (() => parser ('foo(a: 0, b: 1, a: 2)' )).toThrow ( "Duplicate argument named 'a' at column 17" );
1063
- expect (() => parser ('foo(0, a: 1, a: 2)' )).toThrow ( "Duplicate argument named 'a' at column 14" );
1064
- expect (() => parser ('foo(0, a: 1, b: 2, a: 3)' )).toThrow ( "Duplicate argument named 'a' at column 20" );
1061
+ expect (() => parser ('foo(a: 0, a: 1)' )).toThrowWith (message : "Duplicate argument named 'a' at column 11" );
1062
+ expect (() => parser ('foo(a: 0, b: 1, a: 2)' )).toThrowWith (message : "Duplicate argument named 'a' at column 17" );
1063
+ expect (() => parser ('foo(0, a: 1, a: 2)' )).toThrowWith (message : "Duplicate argument named 'a' at column 14" );
1064
+ expect (() => parser ('foo(0, a: 1, b: 2, a: 3)' )).toThrowWith (message : "Duplicate argument named 'a' at column 20" );
1065
1065
});
1066
1066
1067
1067
1068
1068
it ('should be an error to use Dart reserved words as names' , () {
1069
- expect (() => parser ('foo(if: 0)' )).toThrow ( "Cannot use Dart reserved word 'if' as named argument at column 5" );
1070
- expect (() => parser ('foo(a: 0, class: 0)' )).toThrow ( "Cannot use Dart reserved word 'class' as named argument at column 11" );
1069
+ expect (() => parser ('foo(if: 0)' )).toThrowWith (message : "Cannot use Dart reserved word 'if' as named argument at column 5" );
1070
+ expect (() => parser ('foo(a: 0, class: 0)' )).toThrowWith (message : "Cannot use Dart reserved word 'class' as named argument at column 11" );
1071
1071
});
1072
1072
1073
1073
@@ -1129,10 +1129,10 @@ main() {
1129
1129
it ('should parse formatters' , () {
1130
1130
expect (() {
1131
1131
eval ("1|nonexistent" );
1132
- }).toThrow ( 'No formatter \' nonexistent\' found!' );
1132
+ }).toThrowWith (message : 'No formatter \' nonexistent\' found!' );
1133
1133
expect (() {
1134
1134
eval ("1|nonexistent" , formatters);
1135
- }).toThrow ( 'No formatter \' nonexistent\' found!' );
1135
+ }).toThrowWith (message : 'No formatter \' nonexistent\' found!' );
1136
1136
1137
1137
context['offset' ] = 3 ;
1138
1138
expect (eval ("'abcd'|substring:1:offset" )).toEqual ("bc" );
@@ -1143,7 +1143,7 @@ main() {
1143
1143
var expression = parser ("'World'|hello" );
1144
1144
expect (() {
1145
1145
expression.eval ({}, formatters);
1146
- }).toThrow ( 'No formatter \' hello\' found!' );
1146
+ }).toThrowWith (message : 'No formatter \' hello\' found!' );
1147
1147
1148
1148
var module = new Module ()
1149
1149
..bind (FormatterMap )
@@ -1157,10 +1157,10 @@ main() {
1157
1157
it ('should not allow formatters in a chain' , () {
1158
1158
expect (() {
1159
1159
parser ("1;'World'|hello" );
1160
- }).toThrow ( 'Cannot have a formatter in a chain the end of the expression [1;\' World\' |hello]' );
1160
+ }).toThrowWith (message : 'Cannot have a formatter in a chain the end of the expression [1;\' World\' |hello]' );
1161
1161
expect (() {
1162
1162
parser ("'World'|hello;1" );
1163
- }).toThrow ( 'Cannot have a formatter in a chain at column 15 in [\' World\' |hello;1]' );
1163
+ }).toThrowWith (message : 'Cannot have a formatter in a chain at column 15 in [\' World\' |hello;1]' );
1164
1164
});
1165
1165
});
1166
1166
});
0 commit comments