OLD | NEW |
| (Empty) |
1 // This code was auto-generated, is not intended to be edited, and is subject to | |
2 // significant change. Please see the README file for more information. | |
3 | |
4 library engine.scanner_test; | |
5 | |
6 import 'dart:collection'; | |
7 import 'package:analyzer-experimental/src/generated/java_core.dart'; | |
8 import 'package:analyzer-experimental/src/generated/java_engine.dart'; | |
9 import 'package:analyzer-experimental/src/generated/java_junit.dart'; | |
10 import 'package:analyzer-experimental/src/generated/source.dart'; | |
11 import 'package:analyzer-experimental/src/generated/error.dart'; | |
12 import 'package:analyzer-experimental/src/generated/scanner.dart'; | |
13 import 'package:unittest/unittest.dart' as _ut; | |
14 import 'test_support.dart'; | |
15 | |
16 class KeywordStateTest extends JUnitTestCase { | |
17 void test_KeywordState() { | |
18 List<Keyword> keywords = Keyword.values; | |
19 int keywordCount = keywords.length; | |
20 List<String> textToTest = new List<String>(keywordCount * 3); | |
21 for (int i = 0; i < keywordCount; i++) { | |
22 String syntax3 = keywords[i].syntax; | |
23 textToTest[i] = syntax3; | |
24 textToTest[i + keywordCount] = "${syntax3}x"; | |
25 textToTest[i + keywordCount * 2] = syntax3.substring(0, syntax3.length - 1
); | |
26 } | |
27 KeywordState firstState = KeywordState.KEYWORD_STATE; | |
28 for (int i = 0; i < textToTest.length; i++) { | |
29 String text = textToTest[i]; | |
30 int index = 0; | |
31 int length10 = text.length; | |
32 KeywordState state = firstState; | |
33 while (index < length10 && state != null) { | |
34 state = state.next(text.codeUnitAt(index)); | |
35 index++; | |
36 } | |
37 if (i < keywordCount) { | |
38 JUnitTestCase.assertNotNull(state); | |
39 JUnitTestCase.assertNotNull(state.keyword()); | |
40 JUnitTestCase.assertEquals(keywords[i], state.keyword()); | |
41 } else if (i < keywordCount * 2) { | |
42 JUnitTestCase.assertNull(state); | |
43 } else { | |
44 JUnitTestCase.assertNotNull(state); | |
45 } | |
46 } | |
47 } | |
48 static dartSuite() { | |
49 _ut.group('KeywordStateTest', () { | |
50 _ut.test('test_KeywordState', () { | |
51 final __test = new KeywordStateTest(); | |
52 runJUnitTest(__test, __test.test_KeywordState); | |
53 }); | |
54 }); | |
55 } | |
56 } | |
57 class TokenTypeTest extends EngineTestCase { | |
58 void test_isOperator() { | |
59 JUnitTestCase.assertTrue(TokenType.AMPERSAND.isOperator()); | |
60 JUnitTestCase.assertTrue(TokenType.AMPERSAND_AMPERSAND.isOperator()); | |
61 JUnitTestCase.assertTrue(TokenType.AMPERSAND_EQ.isOperator()); | |
62 JUnitTestCase.assertTrue(TokenType.BANG.isOperator()); | |
63 JUnitTestCase.assertTrue(TokenType.BANG_EQ.isOperator()); | |
64 JUnitTestCase.assertTrue(TokenType.BAR.isOperator()); | |
65 JUnitTestCase.assertTrue(TokenType.BAR_BAR.isOperator()); | |
66 JUnitTestCase.assertTrue(TokenType.BAR_EQ.isOperator()); | |
67 JUnitTestCase.assertTrue(TokenType.CARET.isOperator()); | |
68 JUnitTestCase.assertTrue(TokenType.CARET_EQ.isOperator()); | |
69 JUnitTestCase.assertTrue(TokenType.EQ.isOperator()); | |
70 JUnitTestCase.assertTrue(TokenType.EQ_EQ.isOperator()); | |
71 JUnitTestCase.assertTrue(TokenType.GT.isOperator()); | |
72 JUnitTestCase.assertTrue(TokenType.GT_EQ.isOperator()); | |
73 JUnitTestCase.assertTrue(TokenType.GT_GT.isOperator()); | |
74 JUnitTestCase.assertTrue(TokenType.GT_GT_EQ.isOperator()); | |
75 JUnitTestCase.assertTrue(TokenType.INDEX.isOperator()); | |
76 JUnitTestCase.assertTrue(TokenType.INDEX_EQ.isOperator()); | |
77 JUnitTestCase.assertTrue(TokenType.IS.isOperator()); | |
78 JUnitTestCase.assertTrue(TokenType.LT.isOperator()); | |
79 JUnitTestCase.assertTrue(TokenType.LT_EQ.isOperator()); | |
80 JUnitTestCase.assertTrue(TokenType.LT_LT.isOperator()); | |
81 JUnitTestCase.assertTrue(TokenType.LT_LT_EQ.isOperator()); | |
82 JUnitTestCase.assertTrue(TokenType.MINUS.isOperator()); | |
83 JUnitTestCase.assertTrue(TokenType.MINUS_EQ.isOperator()); | |
84 JUnitTestCase.assertTrue(TokenType.MINUS_MINUS.isOperator()); | |
85 JUnitTestCase.assertTrue(TokenType.PERCENT.isOperator()); | |
86 JUnitTestCase.assertTrue(TokenType.PERCENT_EQ.isOperator()); | |
87 JUnitTestCase.assertTrue(TokenType.PERIOD_PERIOD.isOperator()); | |
88 JUnitTestCase.assertTrue(TokenType.PLUS.isOperator()); | |
89 JUnitTestCase.assertTrue(TokenType.PLUS_EQ.isOperator()); | |
90 JUnitTestCase.assertTrue(TokenType.PLUS_PLUS.isOperator()); | |
91 JUnitTestCase.assertTrue(TokenType.QUESTION.isOperator()); | |
92 JUnitTestCase.assertTrue(TokenType.SLASH.isOperator()); | |
93 JUnitTestCase.assertTrue(TokenType.SLASH_EQ.isOperator()); | |
94 JUnitTestCase.assertTrue(TokenType.STAR.isOperator()); | |
95 JUnitTestCase.assertTrue(TokenType.STAR_EQ.isOperator()); | |
96 JUnitTestCase.assertTrue(TokenType.TILDE.isOperator()); | |
97 JUnitTestCase.assertTrue(TokenType.TILDE_SLASH.isOperator()); | |
98 JUnitTestCase.assertTrue(TokenType.TILDE_SLASH_EQ.isOperator()); | |
99 } | |
100 void test_isUserDefinableOperator() { | |
101 JUnitTestCase.assertTrue(TokenType.AMPERSAND.isUserDefinableOperator()); | |
102 JUnitTestCase.assertTrue(TokenType.BAR.isUserDefinableOperator()); | |
103 JUnitTestCase.assertTrue(TokenType.CARET.isUserDefinableOperator()); | |
104 JUnitTestCase.assertTrue(TokenType.EQ_EQ.isUserDefinableOperator()); | |
105 JUnitTestCase.assertTrue(TokenType.GT.isUserDefinableOperator()); | |
106 JUnitTestCase.assertTrue(TokenType.GT_EQ.isUserDefinableOperator()); | |
107 JUnitTestCase.assertTrue(TokenType.GT_GT.isUserDefinableOperator()); | |
108 JUnitTestCase.assertTrue(TokenType.INDEX.isUserDefinableOperator()); | |
109 JUnitTestCase.assertTrue(TokenType.INDEX_EQ.isUserDefinableOperator()); | |
110 JUnitTestCase.assertTrue(TokenType.LT.isUserDefinableOperator()); | |
111 JUnitTestCase.assertTrue(TokenType.LT_EQ.isUserDefinableOperator()); | |
112 JUnitTestCase.assertTrue(TokenType.LT_LT.isUserDefinableOperator()); | |
113 JUnitTestCase.assertTrue(TokenType.MINUS.isUserDefinableOperator()); | |
114 JUnitTestCase.assertTrue(TokenType.PERCENT.isUserDefinableOperator()); | |
115 JUnitTestCase.assertTrue(TokenType.PLUS.isUserDefinableOperator()); | |
116 JUnitTestCase.assertTrue(TokenType.SLASH.isUserDefinableOperator()); | |
117 JUnitTestCase.assertTrue(TokenType.STAR.isUserDefinableOperator()); | |
118 JUnitTestCase.assertTrue(TokenType.TILDE.isUserDefinableOperator()); | |
119 JUnitTestCase.assertTrue(TokenType.TILDE_SLASH.isUserDefinableOperator()); | |
120 } | |
121 static dartSuite() { | |
122 _ut.group('TokenTypeTest', () { | |
123 _ut.test('test_isOperator', () { | |
124 final __test = new TokenTypeTest(); | |
125 runJUnitTest(__test, __test.test_isOperator); | |
126 }); | |
127 _ut.test('test_isUserDefinableOperator', () { | |
128 final __test = new TokenTypeTest(); | |
129 runJUnitTest(__test, __test.test_isUserDefinableOperator); | |
130 }); | |
131 }); | |
132 } | |
133 } | |
134 /** | |
135 * The class {@code TokenFactory} defines utility methods that can be used to cr
eate tokens. | |
136 */ | |
137 class TokenFactory { | |
138 static Token token(Keyword keyword) => new KeywordToken(keyword, 0); | |
139 static Token token2(String lexeme) => new StringToken(TokenType.STRING, lexeme
, 0); | |
140 static Token token3(TokenType type) => new Token(type, 0); | |
141 static Token token4(TokenType type, String lexeme) => new StringToken(type, le
xeme, 0); | |
142 /** | |
143 * Prevent the creation of instances of this class. | |
144 */ | |
145 TokenFactory() { | |
146 } | |
147 } | |
148 class CharBufferScannerTest extends AbstractScannerTest { | |
149 Token scan(String source, GatheringErrorListener listener) { | |
150 CharBuffer buffer = CharBuffer.wrap(source); | |
151 CharBufferScanner scanner = new CharBufferScanner(null, buffer, listener); | |
152 Token result = scanner.tokenize(); | |
153 listener.setLineInfo(new TestSource(), scanner.lineStarts); | |
154 return result; | |
155 } | |
156 static dartSuite() { | |
157 _ut.group('CharBufferScannerTest', () { | |
158 _ut.test('test_ampersand', () { | |
159 final __test = new CharBufferScannerTest(); | |
160 runJUnitTest(__test, __test.test_ampersand); | |
161 }); | |
162 _ut.test('test_ampersand_ampersand', () { | |
163 final __test = new CharBufferScannerTest(); | |
164 runJUnitTest(__test, __test.test_ampersand_ampersand); | |
165 }); | |
166 _ut.test('test_ampersand_eq', () { | |
167 final __test = new CharBufferScannerTest(); | |
168 runJUnitTest(__test, __test.test_ampersand_eq); | |
169 }); | |
170 _ut.test('test_at', () { | |
171 final __test = new CharBufferScannerTest(); | |
172 runJUnitTest(__test, __test.test_at); | |
173 }); | |
174 _ut.test('test_backping', () { | |
175 final __test = new CharBufferScannerTest(); | |
176 runJUnitTest(__test, __test.test_backping); | |
177 }); | |
178 _ut.test('test_backslash', () { | |
179 final __test = new CharBufferScannerTest(); | |
180 runJUnitTest(__test, __test.test_backslash); | |
181 }); | |
182 _ut.test('test_bang', () { | |
183 final __test = new CharBufferScannerTest(); | |
184 runJUnitTest(__test, __test.test_bang); | |
185 }); | |
186 _ut.test('test_bang_eq', () { | |
187 final __test = new CharBufferScannerTest(); | |
188 runJUnitTest(__test, __test.test_bang_eq); | |
189 }); | |
190 _ut.test('test_bar', () { | |
191 final __test = new CharBufferScannerTest(); | |
192 runJUnitTest(__test, __test.test_bar); | |
193 }); | |
194 _ut.test('test_bar_bar', () { | |
195 final __test = new CharBufferScannerTest(); | |
196 runJUnitTest(__test, __test.test_bar_bar); | |
197 }); | |
198 _ut.test('test_bar_eq', () { | |
199 final __test = new CharBufferScannerTest(); | |
200 runJUnitTest(__test, __test.test_bar_eq); | |
201 }); | |
202 _ut.test('test_caret', () { | |
203 final __test = new CharBufferScannerTest(); | |
204 runJUnitTest(__test, __test.test_caret); | |
205 }); | |
206 _ut.test('test_caret_eq', () { | |
207 final __test = new CharBufferScannerTest(); | |
208 runJUnitTest(__test, __test.test_caret_eq); | |
209 }); | |
210 _ut.test('test_close_curly_bracket', () { | |
211 final __test = new CharBufferScannerTest(); | |
212 runJUnitTest(__test, __test.test_close_curly_bracket); | |
213 }); | |
214 _ut.test('test_close_paren', () { | |
215 final __test = new CharBufferScannerTest(); | |
216 runJUnitTest(__test, __test.test_close_paren); | |
217 }); | |
218 _ut.test('test_close_quare_bracket', () { | |
219 final __test = new CharBufferScannerTest(); | |
220 runJUnitTest(__test, __test.test_close_quare_bracket); | |
221 }); | |
222 _ut.test('test_colon', () { | |
223 final __test = new CharBufferScannerTest(); | |
224 runJUnitTest(__test, __test.test_colon); | |
225 }); | |
226 _ut.test('test_comma', () { | |
227 final __test = new CharBufferScannerTest(); | |
228 runJUnitTest(__test, __test.test_comma); | |
229 }); | |
230 _ut.test('test_comment_multi', () { | |
231 final __test = new CharBufferScannerTest(); | |
232 runJUnitTest(__test, __test.test_comment_multi); | |
233 }); | |
234 _ut.test('test_comment_multi_unterminated', () { | |
235 final __test = new CharBufferScannerTest(); | |
236 runJUnitTest(__test, __test.test_comment_multi_unterminated); | |
237 }); | |
238 _ut.test('test_comment_nested', () { | |
239 final __test = new CharBufferScannerTest(); | |
240 runJUnitTest(__test, __test.test_comment_nested); | |
241 }); | |
242 _ut.test('test_comment_single', () { | |
243 final __test = new CharBufferScannerTest(); | |
244 runJUnitTest(__test, __test.test_comment_single); | |
245 }); | |
246 _ut.test('test_double_both_E', () { | |
247 final __test = new CharBufferScannerTest(); | |
248 runJUnitTest(__test, __test.test_double_both_E); | |
249 }); | |
250 _ut.test('test_double_both_e', () { | |
251 final __test = new CharBufferScannerTest(); | |
252 runJUnitTest(__test, __test.test_double_both_e); | |
253 }); | |
254 _ut.test('test_double_fraction', () { | |
255 final __test = new CharBufferScannerTest(); | |
256 runJUnitTest(__test, __test.test_double_fraction); | |
257 }); | |
258 _ut.test('test_double_fraction_D', () { | |
259 final __test = new CharBufferScannerTest(); | |
260 runJUnitTest(__test, __test.test_double_fraction_D); | |
261 }); | |
262 _ut.test('test_double_fraction_E', () { | |
263 final __test = new CharBufferScannerTest(); | |
264 runJUnitTest(__test, __test.test_double_fraction_E); | |
265 }); | |
266 _ut.test('test_double_fraction_Ed', () { | |
267 final __test = new CharBufferScannerTest(); | |
268 runJUnitTest(__test, __test.test_double_fraction_Ed); | |
269 }); | |
270 _ut.test('test_double_fraction_d', () { | |
271 final __test = new CharBufferScannerTest(); | |
272 runJUnitTest(__test, __test.test_double_fraction_d); | |
273 }); | |
274 _ut.test('test_double_fraction_e', () { | |
275 final __test = new CharBufferScannerTest(); | |
276 runJUnitTest(__test, __test.test_double_fraction_e); | |
277 }); | |
278 _ut.test('test_double_fraction_ed', () { | |
279 final __test = new CharBufferScannerTest(); | |
280 runJUnitTest(__test, __test.test_double_fraction_ed); | |
281 }); | |
282 _ut.test('test_double_missingDigitInExponent', () { | |
283 final __test = new CharBufferScannerTest(); | |
284 runJUnitTest(__test, __test.test_double_missingDigitInExponent); | |
285 }); | |
286 _ut.test('test_double_whole_D', () { | |
287 final __test = new CharBufferScannerTest(); | |
288 runJUnitTest(__test, __test.test_double_whole_D); | |
289 }); | |
290 _ut.test('test_double_whole_E', () { | |
291 final __test = new CharBufferScannerTest(); | |
292 runJUnitTest(__test, __test.test_double_whole_E); | |
293 }); | |
294 _ut.test('test_double_whole_Ed', () { | |
295 final __test = new CharBufferScannerTest(); | |
296 runJUnitTest(__test, __test.test_double_whole_Ed); | |
297 }); | |
298 _ut.test('test_double_whole_d', () { | |
299 final __test = new CharBufferScannerTest(); | |
300 runJUnitTest(__test, __test.test_double_whole_d); | |
301 }); | |
302 _ut.test('test_double_whole_e', () { | |
303 final __test = new CharBufferScannerTest(); | |
304 runJUnitTest(__test, __test.test_double_whole_e); | |
305 }); | |
306 _ut.test('test_double_whole_ed', () { | |
307 final __test = new CharBufferScannerTest(); | |
308 runJUnitTest(__test, __test.test_double_whole_ed); | |
309 }); | |
310 _ut.test('test_eq', () { | |
311 final __test = new CharBufferScannerTest(); | |
312 runJUnitTest(__test, __test.test_eq); | |
313 }); | |
314 _ut.test('test_eq_eq', () { | |
315 final __test = new CharBufferScannerTest(); | |
316 runJUnitTest(__test, __test.test_eq_eq); | |
317 }); | |
318 _ut.test('test_gt', () { | |
319 final __test = new CharBufferScannerTest(); | |
320 runJUnitTest(__test, __test.test_gt); | |
321 }); | |
322 _ut.test('test_gt_eq', () { | |
323 final __test = new CharBufferScannerTest(); | |
324 runJUnitTest(__test, __test.test_gt_eq); | |
325 }); | |
326 _ut.test('test_gt_gt', () { | |
327 final __test = new CharBufferScannerTest(); | |
328 runJUnitTest(__test, __test.test_gt_gt); | |
329 }); | |
330 _ut.test('test_gt_gt_eq', () { | |
331 final __test = new CharBufferScannerTest(); | |
332 runJUnitTest(__test, __test.test_gt_gt_eq); | |
333 }); | |
334 _ut.test('test_hash', () { | |
335 final __test = new CharBufferScannerTest(); | |
336 runJUnitTest(__test, __test.test_hash); | |
337 }); | |
338 _ut.test('test_hexidecimal', () { | |
339 final __test = new CharBufferScannerTest(); | |
340 runJUnitTest(__test, __test.test_hexidecimal); | |
341 }); | |
342 _ut.test('test_hexidecimal_missingDigit', () { | |
343 final __test = new CharBufferScannerTest(); | |
344 runJUnitTest(__test, __test.test_hexidecimal_missingDigit); | |
345 }); | |
346 _ut.test('test_identifier', () { | |
347 final __test = new CharBufferScannerTest(); | |
348 runJUnitTest(__test, __test.test_identifier); | |
349 }); | |
350 _ut.test('test_illegalChar', () { | |
351 final __test = new CharBufferScannerTest(); | |
352 runJUnitTest(__test, __test.test_illegalChar); | |
353 }); | |
354 _ut.test('test_index', () { | |
355 final __test = new CharBufferScannerTest(); | |
356 runJUnitTest(__test, __test.test_index); | |
357 }); | |
358 _ut.test('test_index_eq', () { | |
359 final __test = new CharBufferScannerTest(); | |
360 runJUnitTest(__test, __test.test_index_eq); | |
361 }); | |
362 _ut.test('test_int', () { | |
363 final __test = new CharBufferScannerTest(); | |
364 runJUnitTest(__test, __test.test_int); | |
365 }); | |
366 _ut.test('test_int_initialZero', () { | |
367 final __test = new CharBufferScannerTest(); | |
368 runJUnitTest(__test, __test.test_int_initialZero); | |
369 }); | |
370 _ut.test('test_keyword_abstract', () { | |
371 final __test = new CharBufferScannerTest(); | |
372 runJUnitTest(__test, __test.test_keyword_abstract); | |
373 }); | |
374 _ut.test('test_keyword_as', () { | |
375 final __test = new CharBufferScannerTest(); | |
376 runJUnitTest(__test, __test.test_keyword_as); | |
377 }); | |
378 _ut.test('test_keyword_assert', () { | |
379 final __test = new CharBufferScannerTest(); | |
380 runJUnitTest(__test, __test.test_keyword_assert); | |
381 }); | |
382 _ut.test('test_keyword_break', () { | |
383 final __test = new CharBufferScannerTest(); | |
384 runJUnitTest(__test, __test.test_keyword_break); | |
385 }); | |
386 _ut.test('test_keyword_case', () { | |
387 final __test = new CharBufferScannerTest(); | |
388 runJUnitTest(__test, __test.test_keyword_case); | |
389 }); | |
390 _ut.test('test_keyword_catch', () { | |
391 final __test = new CharBufferScannerTest(); | |
392 runJUnitTest(__test, __test.test_keyword_catch); | |
393 }); | |
394 _ut.test('test_keyword_class', () { | |
395 final __test = new CharBufferScannerTest(); | |
396 runJUnitTest(__test, __test.test_keyword_class); | |
397 }); | |
398 _ut.test('test_keyword_const', () { | |
399 final __test = new CharBufferScannerTest(); | |
400 runJUnitTest(__test, __test.test_keyword_const); | |
401 }); | |
402 _ut.test('test_keyword_continue', () { | |
403 final __test = new CharBufferScannerTest(); | |
404 runJUnitTest(__test, __test.test_keyword_continue); | |
405 }); | |
406 _ut.test('test_keyword_default', () { | |
407 final __test = new CharBufferScannerTest(); | |
408 runJUnitTest(__test, __test.test_keyword_default); | |
409 }); | |
410 _ut.test('test_keyword_do', () { | |
411 final __test = new CharBufferScannerTest(); | |
412 runJUnitTest(__test, __test.test_keyword_do); | |
413 }); | |
414 _ut.test('test_keyword_dynamic', () { | |
415 final __test = new CharBufferScannerTest(); | |
416 runJUnitTest(__test, __test.test_keyword_dynamic); | |
417 }); | |
418 _ut.test('test_keyword_else', () { | |
419 final __test = new CharBufferScannerTest(); | |
420 runJUnitTest(__test, __test.test_keyword_else); | |
421 }); | |
422 _ut.test('test_keyword_export', () { | |
423 final __test = new CharBufferScannerTest(); | |
424 runJUnitTest(__test, __test.test_keyword_export); | |
425 }); | |
426 _ut.test('test_keyword_extends', () { | |
427 final __test = new CharBufferScannerTest(); | |
428 runJUnitTest(__test, __test.test_keyword_extends); | |
429 }); | |
430 _ut.test('test_keyword_factory', () { | |
431 final __test = new CharBufferScannerTest(); | |
432 runJUnitTest(__test, __test.test_keyword_factory); | |
433 }); | |
434 _ut.test('test_keyword_false', () { | |
435 final __test = new CharBufferScannerTest(); | |
436 runJUnitTest(__test, __test.test_keyword_false); | |
437 }); | |
438 _ut.test('test_keyword_final', () { | |
439 final __test = new CharBufferScannerTest(); | |
440 runJUnitTest(__test, __test.test_keyword_final); | |
441 }); | |
442 _ut.test('test_keyword_finally', () { | |
443 final __test = new CharBufferScannerTest(); | |
444 runJUnitTest(__test, __test.test_keyword_finally); | |
445 }); | |
446 _ut.test('test_keyword_for', () { | |
447 final __test = new CharBufferScannerTest(); | |
448 runJUnitTest(__test, __test.test_keyword_for); | |
449 }); | |
450 _ut.test('test_keyword_get', () { | |
451 final __test = new CharBufferScannerTest(); | |
452 runJUnitTest(__test, __test.test_keyword_get); | |
453 }); | |
454 _ut.test('test_keyword_if', () { | |
455 final __test = new CharBufferScannerTest(); | |
456 runJUnitTest(__test, __test.test_keyword_if); | |
457 }); | |
458 _ut.test('test_keyword_implements', () { | |
459 final __test = new CharBufferScannerTest(); | |
460 runJUnitTest(__test, __test.test_keyword_implements); | |
461 }); | |
462 _ut.test('test_keyword_import', () { | |
463 final __test = new CharBufferScannerTest(); | |
464 runJUnitTest(__test, __test.test_keyword_import); | |
465 }); | |
466 _ut.test('test_keyword_in', () { | |
467 final __test = new CharBufferScannerTest(); | |
468 runJUnitTest(__test, __test.test_keyword_in); | |
469 }); | |
470 _ut.test('test_keyword_is', () { | |
471 final __test = new CharBufferScannerTest(); | |
472 runJUnitTest(__test, __test.test_keyword_is); | |
473 }); | |
474 _ut.test('test_keyword_library', () { | |
475 final __test = new CharBufferScannerTest(); | |
476 runJUnitTest(__test, __test.test_keyword_library); | |
477 }); | |
478 _ut.test('test_keyword_new', () { | |
479 final __test = new CharBufferScannerTest(); | |
480 runJUnitTest(__test, __test.test_keyword_new); | |
481 }); | |
482 _ut.test('test_keyword_null', () { | |
483 final __test = new CharBufferScannerTest(); | |
484 runJUnitTest(__test, __test.test_keyword_null); | |
485 }); | |
486 _ut.test('test_keyword_operator', () { | |
487 final __test = new CharBufferScannerTest(); | |
488 runJUnitTest(__test, __test.test_keyword_operator); | |
489 }); | |
490 _ut.test('test_keyword_part', () { | |
491 final __test = new CharBufferScannerTest(); | |
492 runJUnitTest(__test, __test.test_keyword_part); | |
493 }); | |
494 _ut.test('test_keyword_return', () { | |
495 final __test = new CharBufferScannerTest(); | |
496 runJUnitTest(__test, __test.test_keyword_return); | |
497 }); | |
498 _ut.test('test_keyword_set', () { | |
499 final __test = new CharBufferScannerTest(); | |
500 runJUnitTest(__test, __test.test_keyword_set); | |
501 }); | |
502 _ut.test('test_keyword_static', () { | |
503 final __test = new CharBufferScannerTest(); | |
504 runJUnitTest(__test, __test.test_keyword_static); | |
505 }); | |
506 _ut.test('test_keyword_super', () { | |
507 final __test = new CharBufferScannerTest(); | |
508 runJUnitTest(__test, __test.test_keyword_super); | |
509 }); | |
510 _ut.test('test_keyword_switch', () { | |
511 final __test = new CharBufferScannerTest(); | |
512 runJUnitTest(__test, __test.test_keyword_switch); | |
513 }); | |
514 _ut.test('test_keyword_this', () { | |
515 final __test = new CharBufferScannerTest(); | |
516 runJUnitTest(__test, __test.test_keyword_this); | |
517 }); | |
518 _ut.test('test_keyword_throw', () { | |
519 final __test = new CharBufferScannerTest(); | |
520 runJUnitTest(__test, __test.test_keyword_throw); | |
521 }); | |
522 _ut.test('test_keyword_true', () { | |
523 final __test = new CharBufferScannerTest(); | |
524 runJUnitTest(__test, __test.test_keyword_true); | |
525 }); | |
526 _ut.test('test_keyword_try', () { | |
527 final __test = new CharBufferScannerTest(); | |
528 runJUnitTest(__test, __test.test_keyword_try); | |
529 }); | |
530 _ut.test('test_keyword_typedef', () { | |
531 final __test = new CharBufferScannerTest(); | |
532 runJUnitTest(__test, __test.test_keyword_typedef); | |
533 }); | |
534 _ut.test('test_keyword_var', () { | |
535 final __test = new CharBufferScannerTest(); | |
536 runJUnitTest(__test, __test.test_keyword_var); | |
537 }); | |
538 _ut.test('test_keyword_void', () { | |
539 final __test = new CharBufferScannerTest(); | |
540 runJUnitTest(__test, __test.test_keyword_void); | |
541 }); | |
542 _ut.test('test_keyword_while', () { | |
543 final __test = new CharBufferScannerTest(); | |
544 runJUnitTest(__test, __test.test_keyword_while); | |
545 }); | |
546 _ut.test('test_keyword_with', () { | |
547 final __test = new CharBufferScannerTest(); | |
548 runJUnitTest(__test, __test.test_keyword_with); | |
549 }); | |
550 _ut.test('test_lt', () { | |
551 final __test = new CharBufferScannerTest(); | |
552 runJUnitTest(__test, __test.test_lt); | |
553 }); | |
554 _ut.test('test_lt_eq', () { | |
555 final __test = new CharBufferScannerTest(); | |
556 runJUnitTest(__test, __test.test_lt_eq); | |
557 }); | |
558 _ut.test('test_lt_lt', () { | |
559 final __test = new CharBufferScannerTest(); | |
560 runJUnitTest(__test, __test.test_lt_lt); | |
561 }); | |
562 _ut.test('test_lt_lt_eq', () { | |
563 final __test = new CharBufferScannerTest(); | |
564 runJUnitTest(__test, __test.test_lt_lt_eq); | |
565 }); | |
566 _ut.test('test_minus', () { | |
567 final __test = new CharBufferScannerTest(); | |
568 runJUnitTest(__test, __test.test_minus); | |
569 }); | |
570 _ut.test('test_minus_eq', () { | |
571 final __test = new CharBufferScannerTest(); | |
572 runJUnitTest(__test, __test.test_minus_eq); | |
573 }); | |
574 _ut.test('test_minus_minus', () { | |
575 final __test = new CharBufferScannerTest(); | |
576 runJUnitTest(__test, __test.test_minus_minus); | |
577 }); | |
578 _ut.test('test_openSquareBracket', () { | |
579 final __test = new CharBufferScannerTest(); | |
580 runJUnitTest(__test, __test.test_openSquareBracket); | |
581 }); | |
582 _ut.test('test_open_curly_bracket', () { | |
583 final __test = new CharBufferScannerTest(); | |
584 runJUnitTest(__test, __test.test_open_curly_bracket); | |
585 }); | |
586 _ut.test('test_open_paren', () { | |
587 final __test = new CharBufferScannerTest(); | |
588 runJUnitTest(__test, __test.test_open_paren); | |
589 }); | |
590 _ut.test('test_open_square_bracket', () { | |
591 final __test = new CharBufferScannerTest(); | |
592 runJUnitTest(__test, __test.test_open_square_bracket); | |
593 }); | |
594 _ut.test('test_percent', () { | |
595 final __test = new CharBufferScannerTest(); | |
596 runJUnitTest(__test, __test.test_percent); | |
597 }); | |
598 _ut.test('test_percent_eq', () { | |
599 final __test = new CharBufferScannerTest(); | |
600 runJUnitTest(__test, __test.test_percent_eq); | |
601 }); | |
602 _ut.test('test_period', () { | |
603 final __test = new CharBufferScannerTest(); | |
604 runJUnitTest(__test, __test.test_period); | |
605 }); | |
606 _ut.test('test_periodAfterNumberNotIncluded_identifier', () { | |
607 final __test = new CharBufferScannerTest(); | |
608 runJUnitTest(__test, __test.test_periodAfterNumberNotIncluded_identifier
); | |
609 }); | |
610 _ut.test('test_periodAfterNumberNotIncluded_period', () { | |
611 final __test = new CharBufferScannerTest(); | |
612 runJUnitTest(__test, __test.test_periodAfterNumberNotIncluded_period); | |
613 }); | |
614 _ut.test('test_period_period', () { | |
615 final __test = new CharBufferScannerTest(); | |
616 runJUnitTest(__test, __test.test_period_period); | |
617 }); | |
618 _ut.test('test_period_period_period', () { | |
619 final __test = new CharBufferScannerTest(); | |
620 runJUnitTest(__test, __test.test_period_period_period); | |
621 }); | |
622 _ut.test('test_plus', () { | |
623 final __test = new CharBufferScannerTest(); | |
624 runJUnitTest(__test, __test.test_plus); | |
625 }); | |
626 _ut.test('test_plus_eq', () { | |
627 final __test = new CharBufferScannerTest(); | |
628 runJUnitTest(__test, __test.test_plus_eq); | |
629 }); | |
630 _ut.test('test_plus_plus', () { | |
631 final __test = new CharBufferScannerTest(); | |
632 runJUnitTest(__test, __test.test_plus_plus); | |
633 }); | |
634 _ut.test('test_question', () { | |
635 final __test = new CharBufferScannerTest(); | |
636 runJUnitTest(__test, __test.test_question); | |
637 }); | |
638 _ut.test('test_scriptTag_withArgs', () { | |
639 final __test = new CharBufferScannerTest(); | |
640 runJUnitTest(__test, __test.test_scriptTag_withArgs); | |
641 }); | |
642 _ut.test('test_scriptTag_withSpace', () { | |
643 final __test = new CharBufferScannerTest(); | |
644 runJUnitTest(__test, __test.test_scriptTag_withSpace); | |
645 }); | |
646 _ut.test('test_scriptTag_withoutSpace', () { | |
647 final __test = new CharBufferScannerTest(); | |
648 runJUnitTest(__test, __test.test_scriptTag_withoutSpace); | |
649 }); | |
650 _ut.test('test_semicolon', () { | |
651 final __test = new CharBufferScannerTest(); | |
652 runJUnitTest(__test, __test.test_semicolon); | |
653 }); | |
654 _ut.test('test_slash', () { | |
655 final __test = new CharBufferScannerTest(); | |
656 runJUnitTest(__test, __test.test_slash); | |
657 }); | |
658 _ut.test('test_slash_eq', () { | |
659 final __test = new CharBufferScannerTest(); | |
660 runJUnitTest(__test, __test.test_slash_eq); | |
661 }); | |
662 _ut.test('test_star', () { | |
663 final __test = new CharBufferScannerTest(); | |
664 runJUnitTest(__test, __test.test_star); | |
665 }); | |
666 _ut.test('test_star_eq', () { | |
667 final __test = new CharBufferScannerTest(); | |
668 runJUnitTest(__test, __test.test_star_eq); | |
669 }); | |
670 _ut.test('test_startAndEnd', () { | |
671 final __test = new CharBufferScannerTest(); | |
672 runJUnitTest(__test, __test.test_startAndEnd); | |
673 }); | |
674 _ut.test('test_string_multi_double', () { | |
675 final __test = new CharBufferScannerTest(); | |
676 runJUnitTest(__test, __test.test_string_multi_double); | |
677 }); | |
678 _ut.test('test_string_multi_interpolation_block', () { | |
679 final __test = new CharBufferScannerTest(); | |
680 runJUnitTest(__test, __test.test_string_multi_interpolation_block); | |
681 }); | |
682 _ut.test('test_string_multi_interpolation_identifier', () { | |
683 final __test = new CharBufferScannerTest(); | |
684 runJUnitTest(__test, __test.test_string_multi_interpolation_identifier); | |
685 }); | |
686 _ut.test('test_string_multi_single', () { | |
687 final __test = new CharBufferScannerTest(); | |
688 runJUnitTest(__test, __test.test_string_multi_single); | |
689 }); | |
690 _ut.test('test_string_multi_unterminated', () { | |
691 final __test = new CharBufferScannerTest(); | |
692 runJUnitTest(__test, __test.test_string_multi_unterminated); | |
693 }); | |
694 _ut.test('test_string_raw_multi_double', () { | |
695 final __test = new CharBufferScannerTest(); | |
696 runJUnitTest(__test, __test.test_string_raw_multi_double); | |
697 }); | |
698 _ut.test('test_string_raw_multi_single', () { | |
699 final __test = new CharBufferScannerTest(); | |
700 runJUnitTest(__test, __test.test_string_raw_multi_single); | |
701 }); | |
702 _ut.test('test_string_raw_multi_unterminated', () { | |
703 final __test = new CharBufferScannerTest(); | |
704 runJUnitTest(__test, __test.test_string_raw_multi_unterminated); | |
705 }); | |
706 _ut.test('test_string_raw_simple_double', () { | |
707 final __test = new CharBufferScannerTest(); | |
708 runJUnitTest(__test, __test.test_string_raw_simple_double); | |
709 }); | |
710 _ut.test('test_string_raw_simple_single', () { | |
711 final __test = new CharBufferScannerTest(); | |
712 runJUnitTest(__test, __test.test_string_raw_simple_single); | |
713 }); | |
714 _ut.test('test_string_raw_simple_unterminated_eof', () { | |
715 final __test = new CharBufferScannerTest(); | |
716 runJUnitTest(__test, __test.test_string_raw_simple_unterminated_eof); | |
717 }); | |
718 _ut.test('test_string_raw_simple_unterminated_eol', () { | |
719 final __test = new CharBufferScannerTest(); | |
720 runJUnitTest(__test, __test.test_string_raw_simple_unterminated_eol); | |
721 }); | |
722 _ut.test('test_string_simple_double', () { | |
723 final __test = new CharBufferScannerTest(); | |
724 runJUnitTest(__test, __test.test_string_simple_double); | |
725 }); | |
726 _ut.test('test_string_simple_escapedDollar', () { | |
727 final __test = new CharBufferScannerTest(); | |
728 runJUnitTest(__test, __test.test_string_simple_escapedDollar); | |
729 }); | |
730 _ut.test('test_string_simple_interpolation_block', () { | |
731 final __test = new CharBufferScannerTest(); | |
732 runJUnitTest(__test, __test.test_string_simple_interpolation_block); | |
733 }); | |
734 _ut.test('test_string_simple_interpolation_blockWithNestedMap', () { | |
735 final __test = new CharBufferScannerTest(); | |
736 runJUnitTest(__test, __test.test_string_simple_interpolation_blockWithNe
stedMap); | |
737 }); | |
738 _ut.test('test_string_simple_interpolation_firstAndLast', () { | |
739 final __test = new CharBufferScannerTest(); | |
740 runJUnitTest(__test, __test.test_string_simple_interpolation_firstAndLas
t); | |
741 }); | |
742 _ut.test('test_string_simple_interpolation_identifier', () { | |
743 final __test = new CharBufferScannerTest(); | |
744 runJUnitTest(__test, __test.test_string_simple_interpolation_identifier)
; | |
745 }); | |
746 _ut.test('test_string_simple_single', () { | |
747 final __test = new CharBufferScannerTest(); | |
748 runJUnitTest(__test, __test.test_string_simple_single); | |
749 }); | |
750 _ut.test('test_string_simple_unterminated_eof', () { | |
751 final __test = new CharBufferScannerTest(); | |
752 runJUnitTest(__test, __test.test_string_simple_unterminated_eof); | |
753 }); | |
754 _ut.test('test_string_simple_unterminated_eol', () { | |
755 final __test = new CharBufferScannerTest(); | |
756 runJUnitTest(__test, __test.test_string_simple_unterminated_eol); | |
757 }); | |
758 _ut.test('test_tilde', () { | |
759 final __test = new CharBufferScannerTest(); | |
760 runJUnitTest(__test, __test.test_tilde); | |
761 }); | |
762 _ut.test('test_tilde_slash', () { | |
763 final __test = new CharBufferScannerTest(); | |
764 runJUnitTest(__test, __test.test_tilde_slash); | |
765 }); | |
766 _ut.test('test_tilde_slash_eq', () { | |
767 final __test = new CharBufferScannerTest(); | |
768 runJUnitTest(__test, __test.test_tilde_slash_eq); | |
769 }); | |
770 _ut.test('test_unclosedPairInInterpolation', () { | |
771 final __test = new CharBufferScannerTest(); | |
772 runJUnitTest(__test, __test.test_unclosedPairInInterpolation); | |
773 }); | |
774 }); | |
775 } | |
776 } | |
777 class StringScannerTest extends AbstractScannerTest { | |
778 void test_setSourceStart() { | |
779 int offsetDelta = 42; | |
780 GatheringErrorListener listener = new GatheringErrorListener(); | |
781 StringScanner scanner = new StringScanner(null, "a", listener); | |
782 scanner.setSourceStart(3, 9, offsetDelta); | |
783 scanner.tokenize(); | |
784 List<int> lineStarts3 = scanner.lineStarts; | |
785 JUnitTestCase.assertNotNull(lineStarts3); | |
786 JUnitTestCase.assertEquals(3, lineStarts3.length); | |
787 JUnitTestCase.assertEquals(33, lineStarts3[2]); | |
788 } | |
789 Token scan(String source, GatheringErrorListener listener) { | |
790 StringScanner scanner = new StringScanner(null, source, listener); | |
791 Token result = scanner.tokenize(); | |
792 listener.setLineInfo(new TestSource(), scanner.lineStarts); | |
793 return result; | |
794 } | |
795 static dartSuite() { | |
796 _ut.group('StringScannerTest', () { | |
797 _ut.test('test_ampersand', () { | |
798 final __test = new StringScannerTest(); | |
799 runJUnitTest(__test, __test.test_ampersand); | |
800 }); | |
801 _ut.test('test_ampersand_ampersand', () { | |
802 final __test = new StringScannerTest(); | |
803 runJUnitTest(__test, __test.test_ampersand_ampersand); | |
804 }); | |
805 _ut.test('test_ampersand_eq', () { | |
806 final __test = new StringScannerTest(); | |
807 runJUnitTest(__test, __test.test_ampersand_eq); | |
808 }); | |
809 _ut.test('test_at', () { | |
810 final __test = new StringScannerTest(); | |
811 runJUnitTest(__test, __test.test_at); | |
812 }); | |
813 _ut.test('test_backping', () { | |
814 final __test = new StringScannerTest(); | |
815 runJUnitTest(__test, __test.test_backping); | |
816 }); | |
817 _ut.test('test_backslash', () { | |
818 final __test = new StringScannerTest(); | |
819 runJUnitTest(__test, __test.test_backslash); | |
820 }); | |
821 _ut.test('test_bang', () { | |
822 final __test = new StringScannerTest(); | |
823 runJUnitTest(__test, __test.test_bang); | |
824 }); | |
825 _ut.test('test_bang_eq', () { | |
826 final __test = new StringScannerTest(); | |
827 runJUnitTest(__test, __test.test_bang_eq); | |
828 }); | |
829 _ut.test('test_bar', () { | |
830 final __test = new StringScannerTest(); | |
831 runJUnitTest(__test, __test.test_bar); | |
832 }); | |
833 _ut.test('test_bar_bar', () { | |
834 final __test = new StringScannerTest(); | |
835 runJUnitTest(__test, __test.test_bar_bar); | |
836 }); | |
837 _ut.test('test_bar_eq', () { | |
838 final __test = new StringScannerTest(); | |
839 runJUnitTest(__test, __test.test_bar_eq); | |
840 }); | |
841 _ut.test('test_caret', () { | |
842 final __test = new StringScannerTest(); | |
843 runJUnitTest(__test, __test.test_caret); | |
844 }); | |
845 _ut.test('test_caret_eq', () { | |
846 final __test = new StringScannerTest(); | |
847 runJUnitTest(__test, __test.test_caret_eq); | |
848 }); | |
849 _ut.test('test_close_curly_bracket', () { | |
850 final __test = new StringScannerTest(); | |
851 runJUnitTest(__test, __test.test_close_curly_bracket); | |
852 }); | |
853 _ut.test('test_close_paren', () { | |
854 final __test = new StringScannerTest(); | |
855 runJUnitTest(__test, __test.test_close_paren); | |
856 }); | |
857 _ut.test('test_close_quare_bracket', () { | |
858 final __test = new StringScannerTest(); | |
859 runJUnitTest(__test, __test.test_close_quare_bracket); | |
860 }); | |
861 _ut.test('test_colon', () { | |
862 final __test = new StringScannerTest(); | |
863 runJUnitTest(__test, __test.test_colon); | |
864 }); | |
865 _ut.test('test_comma', () { | |
866 final __test = new StringScannerTest(); | |
867 runJUnitTest(__test, __test.test_comma); | |
868 }); | |
869 _ut.test('test_comment_multi', () { | |
870 final __test = new StringScannerTest(); | |
871 runJUnitTest(__test, __test.test_comment_multi); | |
872 }); | |
873 _ut.test('test_comment_multi_unterminated', () { | |
874 final __test = new StringScannerTest(); | |
875 runJUnitTest(__test, __test.test_comment_multi_unterminated); | |
876 }); | |
877 _ut.test('test_comment_nested', () { | |
878 final __test = new StringScannerTest(); | |
879 runJUnitTest(__test, __test.test_comment_nested); | |
880 }); | |
881 _ut.test('test_comment_single', () { | |
882 final __test = new StringScannerTest(); | |
883 runJUnitTest(__test, __test.test_comment_single); | |
884 }); | |
885 _ut.test('test_double_both_E', () { | |
886 final __test = new StringScannerTest(); | |
887 runJUnitTest(__test, __test.test_double_both_E); | |
888 }); | |
889 _ut.test('test_double_both_e', () { | |
890 final __test = new StringScannerTest(); | |
891 runJUnitTest(__test, __test.test_double_both_e); | |
892 }); | |
893 _ut.test('test_double_fraction', () { | |
894 final __test = new StringScannerTest(); | |
895 runJUnitTest(__test, __test.test_double_fraction); | |
896 }); | |
897 _ut.test('test_double_fraction_D', () { | |
898 final __test = new StringScannerTest(); | |
899 runJUnitTest(__test, __test.test_double_fraction_D); | |
900 }); | |
901 _ut.test('test_double_fraction_E', () { | |
902 final __test = new StringScannerTest(); | |
903 runJUnitTest(__test, __test.test_double_fraction_E); | |
904 }); | |
905 _ut.test('test_double_fraction_Ed', () { | |
906 final __test = new StringScannerTest(); | |
907 runJUnitTest(__test, __test.test_double_fraction_Ed); | |
908 }); | |
909 _ut.test('test_double_fraction_d', () { | |
910 final __test = new StringScannerTest(); | |
911 runJUnitTest(__test, __test.test_double_fraction_d); | |
912 }); | |
913 _ut.test('test_double_fraction_e', () { | |
914 final __test = new StringScannerTest(); | |
915 runJUnitTest(__test, __test.test_double_fraction_e); | |
916 }); | |
917 _ut.test('test_double_fraction_ed', () { | |
918 final __test = new StringScannerTest(); | |
919 runJUnitTest(__test, __test.test_double_fraction_ed); | |
920 }); | |
921 _ut.test('test_double_missingDigitInExponent', () { | |
922 final __test = new StringScannerTest(); | |
923 runJUnitTest(__test, __test.test_double_missingDigitInExponent); | |
924 }); | |
925 _ut.test('test_double_whole_D', () { | |
926 final __test = new StringScannerTest(); | |
927 runJUnitTest(__test, __test.test_double_whole_D); | |
928 }); | |
929 _ut.test('test_double_whole_E', () { | |
930 final __test = new StringScannerTest(); | |
931 runJUnitTest(__test, __test.test_double_whole_E); | |
932 }); | |
933 _ut.test('test_double_whole_Ed', () { | |
934 final __test = new StringScannerTest(); | |
935 runJUnitTest(__test, __test.test_double_whole_Ed); | |
936 }); | |
937 _ut.test('test_double_whole_d', () { | |
938 final __test = new StringScannerTest(); | |
939 runJUnitTest(__test, __test.test_double_whole_d); | |
940 }); | |
941 _ut.test('test_double_whole_e', () { | |
942 final __test = new StringScannerTest(); | |
943 runJUnitTest(__test, __test.test_double_whole_e); | |
944 }); | |
945 _ut.test('test_double_whole_ed', () { | |
946 final __test = new StringScannerTest(); | |
947 runJUnitTest(__test, __test.test_double_whole_ed); | |
948 }); | |
949 _ut.test('test_eq', () { | |
950 final __test = new StringScannerTest(); | |
951 runJUnitTest(__test, __test.test_eq); | |
952 }); | |
953 _ut.test('test_eq_eq', () { | |
954 final __test = new StringScannerTest(); | |
955 runJUnitTest(__test, __test.test_eq_eq); | |
956 }); | |
957 _ut.test('test_gt', () { | |
958 final __test = new StringScannerTest(); | |
959 runJUnitTest(__test, __test.test_gt); | |
960 }); | |
961 _ut.test('test_gt_eq', () { | |
962 final __test = new StringScannerTest(); | |
963 runJUnitTest(__test, __test.test_gt_eq); | |
964 }); | |
965 _ut.test('test_gt_gt', () { | |
966 final __test = new StringScannerTest(); | |
967 runJUnitTest(__test, __test.test_gt_gt); | |
968 }); | |
969 _ut.test('test_gt_gt_eq', () { | |
970 final __test = new StringScannerTest(); | |
971 runJUnitTest(__test, __test.test_gt_gt_eq); | |
972 }); | |
973 _ut.test('test_hash', () { | |
974 final __test = new StringScannerTest(); | |
975 runJUnitTest(__test, __test.test_hash); | |
976 }); | |
977 _ut.test('test_hexidecimal', () { | |
978 final __test = new StringScannerTest(); | |
979 runJUnitTest(__test, __test.test_hexidecimal); | |
980 }); | |
981 _ut.test('test_hexidecimal_missingDigit', () { | |
982 final __test = new StringScannerTest(); | |
983 runJUnitTest(__test, __test.test_hexidecimal_missingDigit); | |
984 }); | |
985 _ut.test('test_identifier', () { | |
986 final __test = new StringScannerTest(); | |
987 runJUnitTest(__test, __test.test_identifier); | |
988 }); | |
989 _ut.test('test_illegalChar', () { | |
990 final __test = new StringScannerTest(); | |
991 runJUnitTest(__test, __test.test_illegalChar); | |
992 }); | |
993 _ut.test('test_index', () { | |
994 final __test = new StringScannerTest(); | |
995 runJUnitTest(__test, __test.test_index); | |
996 }); | |
997 _ut.test('test_index_eq', () { | |
998 final __test = new StringScannerTest(); | |
999 runJUnitTest(__test, __test.test_index_eq); | |
1000 }); | |
1001 _ut.test('test_int', () { | |
1002 final __test = new StringScannerTest(); | |
1003 runJUnitTest(__test, __test.test_int); | |
1004 }); | |
1005 _ut.test('test_int_initialZero', () { | |
1006 final __test = new StringScannerTest(); | |
1007 runJUnitTest(__test, __test.test_int_initialZero); | |
1008 }); | |
1009 _ut.test('test_keyword_abstract', () { | |
1010 final __test = new StringScannerTest(); | |
1011 runJUnitTest(__test, __test.test_keyword_abstract); | |
1012 }); | |
1013 _ut.test('test_keyword_as', () { | |
1014 final __test = new StringScannerTest(); | |
1015 runJUnitTest(__test, __test.test_keyword_as); | |
1016 }); | |
1017 _ut.test('test_keyword_assert', () { | |
1018 final __test = new StringScannerTest(); | |
1019 runJUnitTest(__test, __test.test_keyword_assert); | |
1020 }); | |
1021 _ut.test('test_keyword_break', () { | |
1022 final __test = new StringScannerTest(); | |
1023 runJUnitTest(__test, __test.test_keyword_break); | |
1024 }); | |
1025 _ut.test('test_keyword_case', () { | |
1026 final __test = new StringScannerTest(); | |
1027 runJUnitTest(__test, __test.test_keyword_case); | |
1028 }); | |
1029 _ut.test('test_keyword_catch', () { | |
1030 final __test = new StringScannerTest(); | |
1031 runJUnitTest(__test, __test.test_keyword_catch); | |
1032 }); | |
1033 _ut.test('test_keyword_class', () { | |
1034 final __test = new StringScannerTest(); | |
1035 runJUnitTest(__test, __test.test_keyword_class); | |
1036 }); | |
1037 _ut.test('test_keyword_const', () { | |
1038 final __test = new StringScannerTest(); | |
1039 runJUnitTest(__test, __test.test_keyword_const); | |
1040 }); | |
1041 _ut.test('test_keyword_continue', () { | |
1042 final __test = new StringScannerTest(); | |
1043 runJUnitTest(__test, __test.test_keyword_continue); | |
1044 }); | |
1045 _ut.test('test_keyword_default', () { | |
1046 final __test = new StringScannerTest(); | |
1047 runJUnitTest(__test, __test.test_keyword_default); | |
1048 }); | |
1049 _ut.test('test_keyword_do', () { | |
1050 final __test = new StringScannerTest(); | |
1051 runJUnitTest(__test, __test.test_keyword_do); | |
1052 }); | |
1053 _ut.test('test_keyword_dynamic', () { | |
1054 final __test = new StringScannerTest(); | |
1055 runJUnitTest(__test, __test.test_keyword_dynamic); | |
1056 }); | |
1057 _ut.test('test_keyword_else', () { | |
1058 final __test = new StringScannerTest(); | |
1059 runJUnitTest(__test, __test.test_keyword_else); | |
1060 }); | |
1061 _ut.test('test_keyword_export', () { | |
1062 final __test = new StringScannerTest(); | |
1063 runJUnitTest(__test, __test.test_keyword_export); | |
1064 }); | |
1065 _ut.test('test_keyword_extends', () { | |
1066 final __test = new StringScannerTest(); | |
1067 runJUnitTest(__test, __test.test_keyword_extends); | |
1068 }); | |
1069 _ut.test('test_keyword_factory', () { | |
1070 final __test = new StringScannerTest(); | |
1071 runJUnitTest(__test, __test.test_keyword_factory); | |
1072 }); | |
1073 _ut.test('test_keyword_false', () { | |
1074 final __test = new StringScannerTest(); | |
1075 runJUnitTest(__test, __test.test_keyword_false); | |
1076 }); | |
1077 _ut.test('test_keyword_final', () { | |
1078 final __test = new StringScannerTest(); | |
1079 runJUnitTest(__test, __test.test_keyword_final); | |
1080 }); | |
1081 _ut.test('test_keyword_finally', () { | |
1082 final __test = new StringScannerTest(); | |
1083 runJUnitTest(__test, __test.test_keyword_finally); | |
1084 }); | |
1085 _ut.test('test_keyword_for', () { | |
1086 final __test = new StringScannerTest(); | |
1087 runJUnitTest(__test, __test.test_keyword_for); | |
1088 }); | |
1089 _ut.test('test_keyword_get', () { | |
1090 final __test = new StringScannerTest(); | |
1091 runJUnitTest(__test, __test.test_keyword_get); | |
1092 }); | |
1093 _ut.test('test_keyword_if', () { | |
1094 final __test = new StringScannerTest(); | |
1095 runJUnitTest(__test, __test.test_keyword_if); | |
1096 }); | |
1097 _ut.test('test_keyword_implements', () { | |
1098 final __test = new StringScannerTest(); | |
1099 runJUnitTest(__test, __test.test_keyword_implements); | |
1100 }); | |
1101 _ut.test('test_keyword_import', () { | |
1102 final __test = new StringScannerTest(); | |
1103 runJUnitTest(__test, __test.test_keyword_import); | |
1104 }); | |
1105 _ut.test('test_keyword_in', () { | |
1106 final __test = new StringScannerTest(); | |
1107 runJUnitTest(__test, __test.test_keyword_in); | |
1108 }); | |
1109 _ut.test('test_keyword_is', () { | |
1110 final __test = new StringScannerTest(); | |
1111 runJUnitTest(__test, __test.test_keyword_is); | |
1112 }); | |
1113 _ut.test('test_keyword_library', () { | |
1114 final __test = new StringScannerTest(); | |
1115 runJUnitTest(__test, __test.test_keyword_library); | |
1116 }); | |
1117 _ut.test('test_keyword_new', () { | |
1118 final __test = new StringScannerTest(); | |
1119 runJUnitTest(__test, __test.test_keyword_new); | |
1120 }); | |
1121 _ut.test('test_keyword_null', () { | |
1122 final __test = new StringScannerTest(); | |
1123 runJUnitTest(__test, __test.test_keyword_null); | |
1124 }); | |
1125 _ut.test('test_keyword_operator', () { | |
1126 final __test = new StringScannerTest(); | |
1127 runJUnitTest(__test, __test.test_keyword_operator); | |
1128 }); | |
1129 _ut.test('test_keyword_part', () { | |
1130 final __test = new StringScannerTest(); | |
1131 runJUnitTest(__test, __test.test_keyword_part); | |
1132 }); | |
1133 _ut.test('test_keyword_return', () { | |
1134 final __test = new StringScannerTest(); | |
1135 runJUnitTest(__test, __test.test_keyword_return); | |
1136 }); | |
1137 _ut.test('test_keyword_set', () { | |
1138 final __test = new StringScannerTest(); | |
1139 runJUnitTest(__test, __test.test_keyword_set); | |
1140 }); | |
1141 _ut.test('test_keyword_static', () { | |
1142 final __test = new StringScannerTest(); | |
1143 runJUnitTest(__test, __test.test_keyword_static); | |
1144 }); | |
1145 _ut.test('test_keyword_super', () { | |
1146 final __test = new StringScannerTest(); | |
1147 runJUnitTest(__test, __test.test_keyword_super); | |
1148 }); | |
1149 _ut.test('test_keyword_switch', () { | |
1150 final __test = new StringScannerTest(); | |
1151 runJUnitTest(__test, __test.test_keyword_switch); | |
1152 }); | |
1153 _ut.test('test_keyword_this', () { | |
1154 final __test = new StringScannerTest(); | |
1155 runJUnitTest(__test, __test.test_keyword_this); | |
1156 }); | |
1157 _ut.test('test_keyword_throw', () { | |
1158 final __test = new StringScannerTest(); | |
1159 runJUnitTest(__test, __test.test_keyword_throw); | |
1160 }); | |
1161 _ut.test('test_keyword_true', () { | |
1162 final __test = new StringScannerTest(); | |
1163 runJUnitTest(__test, __test.test_keyword_true); | |
1164 }); | |
1165 _ut.test('test_keyword_try', () { | |
1166 final __test = new StringScannerTest(); | |
1167 runJUnitTest(__test, __test.test_keyword_try); | |
1168 }); | |
1169 _ut.test('test_keyword_typedef', () { | |
1170 final __test = new StringScannerTest(); | |
1171 runJUnitTest(__test, __test.test_keyword_typedef); | |
1172 }); | |
1173 _ut.test('test_keyword_var', () { | |
1174 final __test = new StringScannerTest(); | |
1175 runJUnitTest(__test, __test.test_keyword_var); | |
1176 }); | |
1177 _ut.test('test_keyword_void', () { | |
1178 final __test = new StringScannerTest(); | |
1179 runJUnitTest(__test, __test.test_keyword_void); | |
1180 }); | |
1181 _ut.test('test_keyword_while', () { | |
1182 final __test = new StringScannerTest(); | |
1183 runJUnitTest(__test, __test.test_keyword_while); | |
1184 }); | |
1185 _ut.test('test_keyword_with', () { | |
1186 final __test = new StringScannerTest(); | |
1187 runJUnitTest(__test, __test.test_keyword_with); | |
1188 }); | |
1189 _ut.test('test_lt', () { | |
1190 final __test = new StringScannerTest(); | |
1191 runJUnitTest(__test, __test.test_lt); | |
1192 }); | |
1193 _ut.test('test_lt_eq', () { | |
1194 final __test = new StringScannerTest(); | |
1195 runJUnitTest(__test, __test.test_lt_eq); | |
1196 }); | |
1197 _ut.test('test_lt_lt', () { | |
1198 final __test = new StringScannerTest(); | |
1199 runJUnitTest(__test, __test.test_lt_lt); | |
1200 }); | |
1201 _ut.test('test_lt_lt_eq', () { | |
1202 final __test = new StringScannerTest(); | |
1203 runJUnitTest(__test, __test.test_lt_lt_eq); | |
1204 }); | |
1205 _ut.test('test_minus', () { | |
1206 final __test = new StringScannerTest(); | |
1207 runJUnitTest(__test, __test.test_minus); | |
1208 }); | |
1209 _ut.test('test_minus_eq', () { | |
1210 final __test = new StringScannerTest(); | |
1211 runJUnitTest(__test, __test.test_minus_eq); | |
1212 }); | |
1213 _ut.test('test_minus_minus', () { | |
1214 final __test = new StringScannerTest(); | |
1215 runJUnitTest(__test, __test.test_minus_minus); | |
1216 }); | |
1217 _ut.test('test_openSquareBracket', () { | |
1218 final __test = new StringScannerTest(); | |
1219 runJUnitTest(__test, __test.test_openSquareBracket); | |
1220 }); | |
1221 _ut.test('test_open_curly_bracket', () { | |
1222 final __test = new StringScannerTest(); | |
1223 runJUnitTest(__test, __test.test_open_curly_bracket); | |
1224 }); | |
1225 _ut.test('test_open_paren', () { | |
1226 final __test = new StringScannerTest(); | |
1227 runJUnitTest(__test, __test.test_open_paren); | |
1228 }); | |
1229 _ut.test('test_open_square_bracket', () { | |
1230 final __test = new StringScannerTest(); | |
1231 runJUnitTest(__test, __test.test_open_square_bracket); | |
1232 }); | |
1233 _ut.test('test_percent', () { | |
1234 final __test = new StringScannerTest(); | |
1235 runJUnitTest(__test, __test.test_percent); | |
1236 }); | |
1237 _ut.test('test_percent_eq', () { | |
1238 final __test = new StringScannerTest(); | |
1239 runJUnitTest(__test, __test.test_percent_eq); | |
1240 }); | |
1241 _ut.test('test_period', () { | |
1242 final __test = new StringScannerTest(); | |
1243 runJUnitTest(__test, __test.test_period); | |
1244 }); | |
1245 _ut.test('test_periodAfterNumberNotIncluded_identifier', () { | |
1246 final __test = new StringScannerTest(); | |
1247 runJUnitTest(__test, __test.test_periodAfterNumberNotIncluded_identifier
); | |
1248 }); | |
1249 _ut.test('test_periodAfterNumberNotIncluded_period', () { | |
1250 final __test = new StringScannerTest(); | |
1251 runJUnitTest(__test, __test.test_periodAfterNumberNotIncluded_period); | |
1252 }); | |
1253 _ut.test('test_period_period', () { | |
1254 final __test = new StringScannerTest(); | |
1255 runJUnitTest(__test, __test.test_period_period); | |
1256 }); | |
1257 _ut.test('test_period_period_period', () { | |
1258 final __test = new StringScannerTest(); | |
1259 runJUnitTest(__test, __test.test_period_period_period); | |
1260 }); | |
1261 _ut.test('test_plus', () { | |
1262 final __test = new StringScannerTest(); | |
1263 runJUnitTest(__test, __test.test_plus); | |
1264 }); | |
1265 _ut.test('test_plus_eq', () { | |
1266 final __test = new StringScannerTest(); | |
1267 runJUnitTest(__test, __test.test_plus_eq); | |
1268 }); | |
1269 _ut.test('test_plus_plus', () { | |
1270 final __test = new StringScannerTest(); | |
1271 runJUnitTest(__test, __test.test_plus_plus); | |
1272 }); | |
1273 _ut.test('test_question', () { | |
1274 final __test = new StringScannerTest(); | |
1275 runJUnitTest(__test, __test.test_question); | |
1276 }); | |
1277 _ut.test('test_scriptTag_withArgs', () { | |
1278 final __test = new StringScannerTest(); | |
1279 runJUnitTest(__test, __test.test_scriptTag_withArgs); | |
1280 }); | |
1281 _ut.test('test_scriptTag_withSpace', () { | |
1282 final __test = new StringScannerTest(); | |
1283 runJUnitTest(__test, __test.test_scriptTag_withSpace); | |
1284 }); | |
1285 _ut.test('test_scriptTag_withoutSpace', () { | |
1286 final __test = new StringScannerTest(); | |
1287 runJUnitTest(__test, __test.test_scriptTag_withoutSpace); | |
1288 }); | |
1289 _ut.test('test_semicolon', () { | |
1290 final __test = new StringScannerTest(); | |
1291 runJUnitTest(__test, __test.test_semicolon); | |
1292 }); | |
1293 _ut.test('test_setSourceStart', () { | |
1294 final __test = new StringScannerTest(); | |
1295 runJUnitTest(__test, __test.test_setSourceStart); | |
1296 }); | |
1297 _ut.test('test_slash', () { | |
1298 final __test = new StringScannerTest(); | |
1299 runJUnitTest(__test, __test.test_slash); | |
1300 }); | |
1301 _ut.test('test_slash_eq', () { | |
1302 final __test = new StringScannerTest(); | |
1303 runJUnitTest(__test, __test.test_slash_eq); | |
1304 }); | |
1305 _ut.test('test_star', () { | |
1306 final __test = new StringScannerTest(); | |
1307 runJUnitTest(__test, __test.test_star); | |
1308 }); | |
1309 _ut.test('test_star_eq', () { | |
1310 final __test = new StringScannerTest(); | |
1311 runJUnitTest(__test, __test.test_star_eq); | |
1312 }); | |
1313 _ut.test('test_startAndEnd', () { | |
1314 final __test = new StringScannerTest(); | |
1315 runJUnitTest(__test, __test.test_startAndEnd); | |
1316 }); | |
1317 _ut.test('test_string_multi_double', () { | |
1318 final __test = new StringScannerTest(); | |
1319 runJUnitTest(__test, __test.test_string_multi_double); | |
1320 }); | |
1321 _ut.test('test_string_multi_interpolation_block', () { | |
1322 final __test = new StringScannerTest(); | |
1323 runJUnitTest(__test, __test.test_string_multi_interpolation_block); | |
1324 }); | |
1325 _ut.test('test_string_multi_interpolation_identifier', () { | |
1326 final __test = new StringScannerTest(); | |
1327 runJUnitTest(__test, __test.test_string_multi_interpolation_identifier); | |
1328 }); | |
1329 _ut.test('test_string_multi_single', () { | |
1330 final __test = new StringScannerTest(); | |
1331 runJUnitTest(__test, __test.test_string_multi_single); | |
1332 }); | |
1333 _ut.test('test_string_multi_unterminated', () { | |
1334 final __test = new StringScannerTest(); | |
1335 runJUnitTest(__test, __test.test_string_multi_unterminated); | |
1336 }); | |
1337 _ut.test('test_string_raw_multi_double', () { | |
1338 final __test = new StringScannerTest(); | |
1339 runJUnitTest(__test, __test.test_string_raw_multi_double); | |
1340 }); | |
1341 _ut.test('test_string_raw_multi_single', () { | |
1342 final __test = new StringScannerTest(); | |
1343 runJUnitTest(__test, __test.test_string_raw_multi_single); | |
1344 }); | |
1345 _ut.test('test_string_raw_multi_unterminated', () { | |
1346 final __test = new StringScannerTest(); | |
1347 runJUnitTest(__test, __test.test_string_raw_multi_unterminated); | |
1348 }); | |
1349 _ut.test('test_string_raw_simple_double', () { | |
1350 final __test = new StringScannerTest(); | |
1351 runJUnitTest(__test, __test.test_string_raw_simple_double); | |
1352 }); | |
1353 _ut.test('test_string_raw_simple_single', () { | |
1354 final __test = new StringScannerTest(); | |
1355 runJUnitTest(__test, __test.test_string_raw_simple_single); | |
1356 }); | |
1357 _ut.test('test_string_raw_simple_unterminated_eof', () { | |
1358 final __test = new StringScannerTest(); | |
1359 runJUnitTest(__test, __test.test_string_raw_simple_unterminated_eof); | |
1360 }); | |
1361 _ut.test('test_string_raw_simple_unterminated_eol', () { | |
1362 final __test = new StringScannerTest(); | |
1363 runJUnitTest(__test, __test.test_string_raw_simple_unterminated_eol); | |
1364 }); | |
1365 _ut.test('test_string_simple_double', () { | |
1366 final __test = new StringScannerTest(); | |
1367 runJUnitTest(__test, __test.test_string_simple_double); | |
1368 }); | |
1369 _ut.test('test_string_simple_escapedDollar', () { | |
1370 final __test = new StringScannerTest(); | |
1371 runJUnitTest(__test, __test.test_string_simple_escapedDollar); | |
1372 }); | |
1373 _ut.test('test_string_simple_interpolation_block', () { | |
1374 final __test = new StringScannerTest(); | |
1375 runJUnitTest(__test, __test.test_string_simple_interpolation_block); | |
1376 }); | |
1377 _ut.test('test_string_simple_interpolation_blockWithNestedMap', () { | |
1378 final __test = new StringScannerTest(); | |
1379 runJUnitTest(__test, __test.test_string_simple_interpolation_blockWithNe
stedMap); | |
1380 }); | |
1381 _ut.test('test_string_simple_interpolation_firstAndLast', () { | |
1382 final __test = new StringScannerTest(); | |
1383 runJUnitTest(__test, __test.test_string_simple_interpolation_firstAndLas
t); | |
1384 }); | |
1385 _ut.test('test_string_simple_interpolation_identifier', () { | |
1386 final __test = new StringScannerTest(); | |
1387 runJUnitTest(__test, __test.test_string_simple_interpolation_identifier)
; | |
1388 }); | |
1389 _ut.test('test_string_simple_single', () { | |
1390 final __test = new StringScannerTest(); | |
1391 runJUnitTest(__test, __test.test_string_simple_single); | |
1392 }); | |
1393 _ut.test('test_string_simple_unterminated_eof', () { | |
1394 final __test = new StringScannerTest(); | |
1395 runJUnitTest(__test, __test.test_string_simple_unterminated_eof); | |
1396 }); | |
1397 _ut.test('test_string_simple_unterminated_eol', () { | |
1398 final __test = new StringScannerTest(); | |
1399 runJUnitTest(__test, __test.test_string_simple_unterminated_eol); | |
1400 }); | |
1401 _ut.test('test_tilde', () { | |
1402 final __test = new StringScannerTest(); | |
1403 runJUnitTest(__test, __test.test_tilde); | |
1404 }); | |
1405 _ut.test('test_tilde_slash', () { | |
1406 final __test = new StringScannerTest(); | |
1407 runJUnitTest(__test, __test.test_tilde_slash); | |
1408 }); | |
1409 _ut.test('test_tilde_slash_eq', () { | |
1410 final __test = new StringScannerTest(); | |
1411 runJUnitTest(__test, __test.test_tilde_slash_eq); | |
1412 }); | |
1413 _ut.test('test_unclosedPairInInterpolation', () { | |
1414 final __test = new StringScannerTest(); | |
1415 runJUnitTest(__test, __test.test_unclosedPairInInterpolation); | |
1416 }); | |
1417 }); | |
1418 } | |
1419 } | |
1420 /** | |
1421 * Instances of the class {@code TokenStreamValidator} are used to validate the
correct construction | |
1422 * of a stream of tokens. | |
1423 */ | |
1424 class TokenStreamValidator { | |
1425 /** | |
1426 * Validate that the stream of tokens that starts with the given token is corr
ect. | |
1427 * @param token the first token in the stream of tokens to be validated | |
1428 */ | |
1429 void validate(Token token) { | |
1430 JavaStringBuilder builder = new JavaStringBuilder(); | |
1431 validateStream(builder, token); | |
1432 if (builder.length > 0) { | |
1433 JUnitTestCase.fail(builder.toString()); | |
1434 } | |
1435 } | |
1436 void validateStream(JavaStringBuilder builder, Token token) { | |
1437 if (token == null) { | |
1438 return; | |
1439 } | |
1440 Token previousToken = null; | |
1441 int previousEnd = -1; | |
1442 Token currentToken = token; | |
1443 while (currentToken != null && currentToken.type != TokenType.EOF) { | |
1444 validateStream(builder, currentToken.precedingComments); | |
1445 TokenType type29 = currentToken.type; | |
1446 if (identical(type29, TokenType.OPEN_CURLY_BRACKET) || identical(type29, T
okenType.OPEN_PAREN) || identical(type29, TokenType.OPEN_SQUARE_BRACKET) || iden
tical(type29, TokenType.STRING_INTERPOLATION_EXPRESSION)) { | |
1447 if (currentToken is! BeginToken) { | |
1448 builder.append("\r\nExpected BeginToken, found "); | |
1449 builder.append(currentToken.runtimeType.toString()); | |
1450 builder.append(" "); | |
1451 writeToken(builder, currentToken); | |
1452 } | |
1453 } | |
1454 int currentStart = currentToken.offset; | |
1455 int currentLength = currentToken.length; | |
1456 int currentEnd = currentStart + currentLength - 1; | |
1457 if (currentStart <= previousEnd) { | |
1458 builder.append("\r\nInvalid token sequence: "); | |
1459 writeToken(builder, previousToken); | |
1460 builder.append(" followed by "); | |
1461 writeToken(builder, currentToken); | |
1462 } | |
1463 previousEnd = currentEnd; | |
1464 previousToken = currentToken; | |
1465 currentToken = currentToken.next; | |
1466 } | |
1467 } | |
1468 void writeToken(JavaStringBuilder builder, Token token) { | |
1469 builder.append("["); | |
1470 builder.append(token.type); | |
1471 builder.append(", '"); | |
1472 builder.append(token.lexeme); | |
1473 builder.append("', "); | |
1474 builder.append(token.offset); | |
1475 builder.append(", "); | |
1476 builder.append(token.length); | |
1477 builder.append("]"); | |
1478 } | |
1479 } | |
1480 abstract class AbstractScannerTest extends JUnitTestCase { | |
1481 void test_ampersand() { | |
1482 assertToken(TokenType.AMPERSAND, "&"); | |
1483 } | |
1484 void test_ampersand_ampersand() { | |
1485 assertToken(TokenType.AMPERSAND_AMPERSAND, "&&"); | |
1486 } | |
1487 void test_ampersand_eq() { | |
1488 assertToken(TokenType.AMPERSAND_EQ, "&="); | |
1489 } | |
1490 void test_at() { | |
1491 assertToken(TokenType.AT, "@"); | |
1492 } | |
1493 void test_backping() { | |
1494 assertToken(TokenType.BACKPING, "`"); | |
1495 } | |
1496 void test_backslash() { | |
1497 assertToken(TokenType.BACKSLASH, "\\"); | |
1498 } | |
1499 void test_bang() { | |
1500 assertToken(TokenType.BANG, "!"); | |
1501 } | |
1502 void test_bang_eq() { | |
1503 assertToken(TokenType.BANG_EQ, "!="); | |
1504 } | |
1505 void test_bar() { | |
1506 assertToken(TokenType.BAR, "|"); | |
1507 } | |
1508 void test_bar_bar() { | |
1509 assertToken(TokenType.BAR_BAR, "||"); | |
1510 } | |
1511 void test_bar_eq() { | |
1512 assertToken(TokenType.BAR_EQ, "|="); | |
1513 } | |
1514 void test_caret() { | |
1515 assertToken(TokenType.CARET, "^"); | |
1516 } | |
1517 void test_caret_eq() { | |
1518 assertToken(TokenType.CARET_EQ, "^="); | |
1519 } | |
1520 void test_close_curly_bracket() { | |
1521 assertToken(TokenType.CLOSE_CURLY_BRACKET, "}"); | |
1522 } | |
1523 void test_close_paren() { | |
1524 assertToken(TokenType.CLOSE_PAREN, ")"); | |
1525 } | |
1526 void test_close_quare_bracket() { | |
1527 assertToken(TokenType.CLOSE_SQUARE_BRACKET, "]"); | |
1528 } | |
1529 void test_colon() { | |
1530 assertToken(TokenType.COLON, ":"); | |
1531 } | |
1532 void test_comma() { | |
1533 assertToken(TokenType.COMMA, ","); | |
1534 } | |
1535 void test_comment_multi() { | |
1536 assertComment(TokenType.MULTI_LINE_COMMENT, "/* comment */"); | |
1537 } | |
1538 void test_comment_multi_unterminated() { | |
1539 assertError(ScannerErrorCode.UNTERMINATED_MULTI_LINE_COMMENT, 3, "/* x"); | |
1540 } | |
1541 void test_comment_nested() { | |
1542 assertComment(TokenType.MULTI_LINE_COMMENT, "/* comment /* within a */ comme
nt */"); | |
1543 } | |
1544 void test_comment_single() { | |
1545 assertComment(TokenType.SINGLE_LINE_COMMENT, "// comment"); | |
1546 } | |
1547 void test_double_both_e() { | |
1548 assertToken(TokenType.DOUBLE, "0.123e4"); | |
1549 } | |
1550 void test_double_both_E() { | |
1551 assertToken(TokenType.DOUBLE, "0.123E4"); | |
1552 } | |
1553 void test_double_fraction() { | |
1554 assertToken(TokenType.DOUBLE, ".123"); | |
1555 } | |
1556 void test_double_fraction_d() { | |
1557 assertToken(TokenType.DOUBLE, ".123d"); | |
1558 } | |
1559 void test_double_fraction_D() { | |
1560 assertToken(TokenType.DOUBLE, ".123D"); | |
1561 } | |
1562 void test_double_fraction_e() { | |
1563 assertToken(TokenType.DOUBLE, ".123e4"); | |
1564 } | |
1565 void test_double_fraction_E() { | |
1566 assertToken(TokenType.DOUBLE, ".123E4"); | |
1567 } | |
1568 void test_double_fraction_ed() { | |
1569 assertToken(TokenType.DOUBLE, ".123e4d"); | |
1570 } | |
1571 void test_double_fraction_Ed() { | |
1572 assertToken(TokenType.DOUBLE, ".123E4d"); | |
1573 } | |
1574 void test_double_missingDigitInExponent() { | |
1575 assertError(ScannerErrorCode.MISSING_DIGIT, 1, "1e"); | |
1576 } | |
1577 void test_double_whole_d() { | |
1578 assertToken(TokenType.DOUBLE, "12d"); | |
1579 } | |
1580 void test_double_whole_D() { | |
1581 assertToken(TokenType.DOUBLE, "12D"); | |
1582 } | |
1583 void test_double_whole_e() { | |
1584 assertToken(TokenType.DOUBLE, "12e4"); | |
1585 } | |
1586 void test_double_whole_E() { | |
1587 assertToken(TokenType.DOUBLE, "12E4"); | |
1588 } | |
1589 void test_double_whole_ed() { | |
1590 assertToken(TokenType.DOUBLE, "12e4d"); | |
1591 } | |
1592 void test_double_whole_Ed() { | |
1593 assertToken(TokenType.DOUBLE, "12E4d"); | |
1594 } | |
1595 void test_eq() { | |
1596 assertToken(TokenType.EQ, "="); | |
1597 } | |
1598 void test_eq_eq() { | |
1599 assertToken(TokenType.EQ_EQ, "=="); | |
1600 } | |
1601 void test_gt() { | |
1602 assertToken(TokenType.GT, ">"); | |
1603 } | |
1604 void test_gt_eq() { | |
1605 assertToken(TokenType.GT_EQ, ">="); | |
1606 } | |
1607 void test_gt_gt() { | |
1608 assertToken(TokenType.GT_GT, ">>"); | |
1609 } | |
1610 void test_gt_gt_eq() { | |
1611 assertToken(TokenType.GT_GT_EQ, ">>="); | |
1612 } | |
1613 void test_hash() { | |
1614 assertToken(TokenType.HASH, "#"); | |
1615 } | |
1616 void test_hexidecimal() { | |
1617 assertToken(TokenType.HEXADECIMAL, "0x1A2B3C"); | |
1618 } | |
1619 void test_hexidecimal_missingDigit() { | |
1620 assertError(ScannerErrorCode.MISSING_HEX_DIGIT, 1, "0x"); | |
1621 } | |
1622 void test_identifier() { | |
1623 assertToken(TokenType.IDENTIFIER, "result"); | |
1624 } | |
1625 void test_illegalChar() { | |
1626 assertError(ScannerErrorCode.ILLEGAL_CHARACTER, 0, "\u0312"); | |
1627 } | |
1628 void test_index() { | |
1629 assertToken(TokenType.INDEX, "[]"); | |
1630 } | |
1631 void test_index_eq() { | |
1632 assertToken(TokenType.INDEX_EQ, "[]="); | |
1633 } | |
1634 void test_int() { | |
1635 assertToken(TokenType.INT, "123"); | |
1636 } | |
1637 void test_int_initialZero() { | |
1638 assertToken(TokenType.INT, "0123"); | |
1639 } | |
1640 void test_keyword_abstract() { | |
1641 assertKeywordToken("abstract"); | |
1642 } | |
1643 void test_keyword_as() { | |
1644 assertKeywordToken("as"); | |
1645 } | |
1646 void test_keyword_assert() { | |
1647 assertKeywordToken("assert"); | |
1648 } | |
1649 void test_keyword_break() { | |
1650 assertKeywordToken("break"); | |
1651 } | |
1652 void test_keyword_case() { | |
1653 assertKeywordToken("case"); | |
1654 } | |
1655 void test_keyword_catch() { | |
1656 assertKeywordToken("catch"); | |
1657 } | |
1658 void test_keyword_class() { | |
1659 assertKeywordToken("class"); | |
1660 } | |
1661 void test_keyword_const() { | |
1662 assertKeywordToken("const"); | |
1663 } | |
1664 void test_keyword_continue() { | |
1665 assertKeywordToken("continue"); | |
1666 } | |
1667 void test_keyword_default() { | |
1668 assertKeywordToken("default"); | |
1669 } | |
1670 void test_keyword_do() { | |
1671 assertKeywordToken("do"); | |
1672 } | |
1673 void test_keyword_dynamic() { | |
1674 assertKeywordToken("dynamic"); | |
1675 } | |
1676 void test_keyword_else() { | |
1677 assertKeywordToken("else"); | |
1678 } | |
1679 void test_keyword_export() { | |
1680 assertKeywordToken("export"); | |
1681 } | |
1682 void test_keyword_extends() { | |
1683 assertKeywordToken("extends"); | |
1684 } | |
1685 void test_keyword_factory() { | |
1686 assertKeywordToken("factory"); | |
1687 } | |
1688 void test_keyword_false() { | |
1689 assertKeywordToken("false"); | |
1690 } | |
1691 void test_keyword_final() { | |
1692 assertKeywordToken("final"); | |
1693 } | |
1694 void test_keyword_finally() { | |
1695 assertKeywordToken("finally"); | |
1696 } | |
1697 void test_keyword_for() { | |
1698 assertKeywordToken("for"); | |
1699 } | |
1700 void test_keyword_get() { | |
1701 assertKeywordToken("get"); | |
1702 } | |
1703 void test_keyword_if() { | |
1704 assertKeywordToken("if"); | |
1705 } | |
1706 void test_keyword_implements() { | |
1707 assertKeywordToken("implements"); | |
1708 } | |
1709 void test_keyword_import() { | |
1710 assertKeywordToken("import"); | |
1711 } | |
1712 void test_keyword_in() { | |
1713 assertKeywordToken("in"); | |
1714 } | |
1715 void test_keyword_is() { | |
1716 assertKeywordToken("is"); | |
1717 } | |
1718 void test_keyword_library() { | |
1719 assertKeywordToken("library"); | |
1720 } | |
1721 void test_keyword_new() { | |
1722 assertKeywordToken("new"); | |
1723 } | |
1724 void test_keyword_null() { | |
1725 assertKeywordToken("null"); | |
1726 } | |
1727 void test_keyword_operator() { | |
1728 assertKeywordToken("operator"); | |
1729 } | |
1730 void test_keyword_part() { | |
1731 assertKeywordToken("part"); | |
1732 } | |
1733 void test_keyword_return() { | |
1734 assertKeywordToken("return"); | |
1735 } | |
1736 void test_keyword_set() { | |
1737 assertKeywordToken("set"); | |
1738 } | |
1739 void test_keyword_static() { | |
1740 assertKeywordToken("static"); | |
1741 } | |
1742 void test_keyword_super() { | |
1743 assertKeywordToken("super"); | |
1744 } | |
1745 void test_keyword_switch() { | |
1746 assertKeywordToken("switch"); | |
1747 } | |
1748 void test_keyword_this() { | |
1749 assertKeywordToken("this"); | |
1750 } | |
1751 void test_keyword_throw() { | |
1752 assertKeywordToken("throw"); | |
1753 } | |
1754 void test_keyword_true() { | |
1755 assertKeywordToken("true"); | |
1756 } | |
1757 void test_keyword_try() { | |
1758 assertKeywordToken("try"); | |
1759 } | |
1760 void test_keyword_typedef() { | |
1761 assertKeywordToken("typedef"); | |
1762 } | |
1763 void test_keyword_var() { | |
1764 assertKeywordToken("var"); | |
1765 } | |
1766 void test_keyword_void() { | |
1767 assertKeywordToken("void"); | |
1768 } | |
1769 void test_keyword_while() { | |
1770 assertKeywordToken("while"); | |
1771 } | |
1772 void test_keyword_with() { | |
1773 assertKeywordToken("with"); | |
1774 } | |
1775 void test_lt() { | |
1776 assertToken(TokenType.LT, "<"); | |
1777 } | |
1778 void test_lt_eq() { | |
1779 assertToken(TokenType.LT_EQ, "<="); | |
1780 } | |
1781 void test_lt_lt() { | |
1782 assertToken(TokenType.LT_LT, "<<"); | |
1783 } | |
1784 void test_lt_lt_eq() { | |
1785 assertToken(TokenType.LT_LT_EQ, "<<="); | |
1786 } | |
1787 void test_minus() { | |
1788 assertToken(TokenType.MINUS, "-"); | |
1789 } | |
1790 void test_minus_eq() { | |
1791 assertToken(TokenType.MINUS_EQ, "-="); | |
1792 } | |
1793 void test_minus_minus() { | |
1794 assertToken(TokenType.MINUS_MINUS, "--"); | |
1795 } | |
1796 void test_open_curly_bracket() { | |
1797 assertToken(TokenType.OPEN_CURLY_BRACKET, "{"); | |
1798 } | |
1799 void test_open_paren() { | |
1800 assertToken(TokenType.OPEN_PAREN, "("); | |
1801 } | |
1802 void test_open_square_bracket() { | |
1803 assertToken(TokenType.OPEN_SQUARE_BRACKET, "["); | |
1804 } | |
1805 void test_openSquareBracket() { | |
1806 assertToken(TokenType.OPEN_SQUARE_BRACKET, "["); | |
1807 } | |
1808 void test_percent() { | |
1809 assertToken(TokenType.PERCENT, "%"); | |
1810 } | |
1811 void test_percent_eq() { | |
1812 assertToken(TokenType.PERCENT_EQ, "%="); | |
1813 } | |
1814 void test_period() { | |
1815 assertToken(TokenType.PERIOD, "."); | |
1816 } | |
1817 void test_period_period() { | |
1818 assertToken(TokenType.PERIOD_PERIOD, ".."); | |
1819 } | |
1820 void test_period_period_period() { | |
1821 assertToken(TokenType.PERIOD_PERIOD_PERIOD, "..."); | |
1822 } | |
1823 void test_periodAfterNumberNotIncluded_identifier() { | |
1824 assertTokens("42.isEven()", [new StringToken(TokenType.INT, "42", 0), new To
ken(TokenType.PERIOD, 2), new StringToken(TokenType.IDENTIFIER, "isEven", 3), ne
w Token(TokenType.OPEN_PAREN, 9), new Token(TokenType.CLOSE_PAREN, 10)]); | |
1825 } | |
1826 void test_periodAfterNumberNotIncluded_period() { | |
1827 assertTokens("42..isEven()", [new StringToken(TokenType.INT, "42", 0), new T
oken(TokenType.PERIOD_PERIOD, 2), new StringToken(TokenType.IDENTIFIER, "isEven"
, 4), new Token(TokenType.OPEN_PAREN, 10), new Token(TokenType.CLOSE_PAREN, 11)]
); | |
1828 } | |
1829 void test_plus() { | |
1830 assertToken(TokenType.PLUS, "+"); | |
1831 } | |
1832 void test_plus_eq() { | |
1833 assertToken(TokenType.PLUS_EQ, "+="); | |
1834 } | |
1835 void test_plus_plus() { | |
1836 assertToken(TokenType.PLUS_PLUS, "++"); | |
1837 } | |
1838 void test_question() { | |
1839 assertToken(TokenType.QUESTION, "?"); | |
1840 } | |
1841 void test_scriptTag_withArgs() { | |
1842 assertToken(TokenType.SCRIPT_TAG, "#!/bin/dart -debug"); | |
1843 } | |
1844 void test_scriptTag_withoutSpace() { | |
1845 assertToken(TokenType.SCRIPT_TAG, "#!/bin/dart"); | |
1846 } | |
1847 void test_scriptTag_withSpace() { | |
1848 assertToken(TokenType.SCRIPT_TAG, "#! /bin/dart"); | |
1849 } | |
1850 void test_semicolon() { | |
1851 assertToken(TokenType.SEMICOLON, ";"); | |
1852 } | |
1853 void test_slash() { | |
1854 assertToken(TokenType.SLASH, "/"); | |
1855 } | |
1856 void test_slash_eq() { | |
1857 assertToken(TokenType.SLASH_EQ, "/="); | |
1858 } | |
1859 void test_star() { | |
1860 assertToken(TokenType.STAR, "*"); | |
1861 } | |
1862 void test_star_eq() { | |
1863 assertToken(TokenType.STAR_EQ, "*="); | |
1864 } | |
1865 void test_startAndEnd() { | |
1866 Token token = scan2("a"); | |
1867 Token previous5 = token.previous; | |
1868 JUnitTestCase.assertEquals(token, previous5.next); | |
1869 JUnitTestCase.assertEquals(previous5, previous5.previous); | |
1870 Token next7 = token.next; | |
1871 JUnitTestCase.assertEquals(next7, next7.next); | |
1872 JUnitTestCase.assertEquals(token, next7.previous); | |
1873 } | |
1874 void test_string_multi_double() { | |
1875 assertToken(TokenType.STRING, "\"\"\"multi-line\nstring\"\"\""); | |
1876 } | |
1877 void test_string_multi_interpolation_block() { | |
1878 assertTokens("\"Hello \${name}!\"", [new StringToken(TokenType.STRING, "\"He
llo ", 0), new StringToken(TokenType.STRING_INTERPOLATION_EXPRESSION, "\${", 7),
new StringToken(TokenType.IDENTIFIER, "name", 9), new Token(TokenType.CLOSE_CUR
LY_BRACKET, 13), new StringToken(TokenType.STRING, "!\"", 14)]); | |
1879 } | |
1880 void test_string_multi_interpolation_identifier() { | |
1881 assertTokens("\"Hello \$name!\"", [new StringToken(TokenType.STRING, "\"Hell
o ", 0), new StringToken(TokenType.STRING_INTERPOLATION_IDENTIFIER, "\$", 7), ne
w StringToken(TokenType.IDENTIFIER, "name", 8), new StringToken(TokenType.STRING
, "!\"", 12)]); | |
1882 } | |
1883 void test_string_multi_single() { | |
1884 assertToken(TokenType.STRING, "'''string'''"); | |
1885 } | |
1886 void test_string_multi_unterminated() { | |
1887 assertError(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 8, "'''string"); | |
1888 } | |
1889 void test_string_raw_multi_double() { | |
1890 assertToken(TokenType.STRING, "r\"\"\"string\"\"\""); | |
1891 } | |
1892 void test_string_raw_multi_single() { | |
1893 assertToken(TokenType.STRING, "r'''string'''"); | |
1894 } | |
1895 void test_string_raw_multi_unterminated() { | |
1896 assertError(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 9, "r'''string"); | |
1897 } | |
1898 void test_string_raw_simple_double() { | |
1899 assertToken(TokenType.STRING, "r\"string\""); | |
1900 } | |
1901 void test_string_raw_simple_single() { | |
1902 assertToken(TokenType.STRING, "r'string'"); | |
1903 } | |
1904 void test_string_raw_simple_unterminated_eof() { | |
1905 assertError(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 7, "r'string"); | |
1906 } | |
1907 void test_string_raw_simple_unterminated_eol() { | |
1908 assertError(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 8, "r'string\n"); | |
1909 } | |
1910 void test_string_simple_double() { | |
1911 assertToken(TokenType.STRING, "\"string\""); | |
1912 } | |
1913 void test_string_simple_escapedDollar() { | |
1914 assertToken(TokenType.STRING, "'a\\\$b'"); | |
1915 } | |
1916 void test_string_simple_interpolation_block() { | |
1917 assertTokens("'Hello \${name}!'", [new StringToken(TokenType.STRING, "'Hello
", 0), new StringToken(TokenType.STRING_INTERPOLATION_EXPRESSION, "\${", 7), ne
w StringToken(TokenType.IDENTIFIER, "name", 9), new Token(TokenType.CLOSE_CURLY_
BRACKET, 13), new StringToken(TokenType.STRING, "!'", 14)]); | |
1918 } | |
1919 void test_string_simple_interpolation_blockWithNestedMap() { | |
1920 assertTokens("'a \${f({'b' : 'c'})} d'", [new StringToken(TokenType.STRING,
"'a ", 0), new StringToken(TokenType.STRING_INTERPOLATION_EXPRESSION, "\${", 3),
new StringToken(TokenType.IDENTIFIER, "f", 5), new Token(TokenType.OPEN_PAREN,
6), new Token(TokenType.OPEN_CURLY_BRACKET, 7), new StringToken(TokenType.STRING
, "'b'", 8), new Token(TokenType.COLON, 12), new StringToken(TokenType.STRING, "
'c'", 14), new Token(TokenType.CLOSE_CURLY_BRACKET, 17), new Token(TokenType.CLO
SE_PAREN, 18), new Token(TokenType.CLOSE_CURLY_BRACKET, 19), new StringToken(Tok
enType.STRING, " d'", 20)]); | |
1921 } | |
1922 void test_string_simple_interpolation_firstAndLast() { | |
1923 assertTokens("'\$greeting \$name'", [new StringToken(TokenType.STRING, "'",
0), new StringToken(TokenType.STRING_INTERPOLATION_IDENTIFIER, "\$", 1), new Str
ingToken(TokenType.IDENTIFIER, "greeting", 2), new StringToken(TokenType.STRING,
" ", 10), new StringToken(TokenType.STRING_INTERPOLATION_IDENTIFIER, "\$", 11),
new StringToken(TokenType.IDENTIFIER, "name", 12), new StringToken(TokenType.ST
RING, "'", 16)]); | |
1924 } | |
1925 void test_string_simple_interpolation_identifier() { | |
1926 assertTokens("'Hello \$name!'", [new StringToken(TokenType.STRING, "'Hello "
, 0), new StringToken(TokenType.STRING_INTERPOLATION_IDENTIFIER, "\$", 7), new S
tringToken(TokenType.IDENTIFIER, "name", 8), new StringToken(TokenType.STRING, "
!'", 12)]); | |
1927 } | |
1928 void test_string_simple_single() { | |
1929 assertToken(TokenType.STRING, "'string'"); | |
1930 } | |
1931 void test_string_simple_unterminated_eof() { | |
1932 assertError(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 6, "'string"); | |
1933 } | |
1934 void test_string_simple_unterminated_eol() { | |
1935 assertError(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 7, "'string\r"); | |
1936 } | |
1937 void test_tilde() { | |
1938 assertToken(TokenType.TILDE, "~"); | |
1939 } | |
1940 void test_tilde_slash() { | |
1941 assertToken(TokenType.TILDE_SLASH, "~/"); | |
1942 } | |
1943 void test_tilde_slash_eq() { | |
1944 assertToken(TokenType.TILDE_SLASH_EQ, "~/="); | |
1945 } | |
1946 void test_unclosedPairInInterpolation() { | |
1947 GatheringErrorListener listener = new GatheringErrorListener(); | |
1948 scan("'\${(}'", listener); | |
1949 } | |
1950 Token scan(String source, GatheringErrorListener listener); | |
1951 void assertComment(TokenType commentType, String source) { | |
1952 Token token = scan2(source); | |
1953 JUnitTestCase.assertNotNull(token); | |
1954 JUnitTestCase.assertEquals(TokenType.EOF, token.type); | |
1955 Token comment = token.precedingComments; | |
1956 JUnitTestCase.assertNotNull(comment); | |
1957 JUnitTestCase.assertEquals(commentType, comment.type); | |
1958 JUnitTestCase.assertEquals(0, comment.offset); | |
1959 JUnitTestCase.assertEquals(source.length, comment.length); | |
1960 JUnitTestCase.assertEquals(source, comment.lexeme); | |
1961 } | |
1962 /** | |
1963 * Assert that scanning the given source produces an error with the given code
. | |
1964 * @param illegalCharacter | |
1965 * @param i | |
1966 * @param source the source to be scanned to produce the error | |
1967 */ | |
1968 void assertError(ScannerErrorCode expectedError, int expectedOffset, String so
urce) { | |
1969 GatheringErrorListener listener = new GatheringErrorListener(); | |
1970 scan(source, listener); | |
1971 listener.assertErrors([new AnalysisError.con2(null, expectedOffset, 1, expec
tedError, [(source.codeUnitAt(expectedOffset) as int)])]); | |
1972 } | |
1973 /** | |
1974 * Assert that when scanned the given source contains a single keyword token w
ith the same lexeme | |
1975 * as the original source. | |
1976 * @param source the source to be scanned | |
1977 */ | |
1978 void assertKeywordToken(String source) { | |
1979 Token token = scan2(source); | |
1980 JUnitTestCase.assertNotNull(token); | |
1981 JUnitTestCase.assertEquals(TokenType.KEYWORD, token.type); | |
1982 JUnitTestCase.assertEquals(0, token.offset); | |
1983 JUnitTestCase.assertEquals(source.length, token.length); | |
1984 JUnitTestCase.assertEquals(source, token.lexeme); | |
1985 Object value3 = token.value(); | |
1986 JUnitTestCase.assertTrue(value3 is Keyword); | |
1987 JUnitTestCase.assertEquals(source, ((value3 as Keyword)).syntax); | |
1988 token = scan2(" ${source} "); | |
1989 JUnitTestCase.assertNotNull(token); | |
1990 JUnitTestCase.assertEquals(TokenType.KEYWORD, token.type); | |
1991 JUnitTestCase.assertEquals(1, token.offset); | |
1992 JUnitTestCase.assertEquals(source.length, token.length); | |
1993 JUnitTestCase.assertEquals(source, token.lexeme); | |
1994 value3 = token.value(); | |
1995 JUnitTestCase.assertTrue(value3 is Keyword); | |
1996 JUnitTestCase.assertEquals(source, ((value3 as Keyword)).syntax); | |
1997 JUnitTestCase.assertEquals(TokenType.EOF, token.next.type); | |
1998 } | |
1999 /** | |
2000 * Assert that the token scanned from the given source has the expected type. | |
2001 * @param expectedType the expected type of the token | |
2002 * @param source the source to be scanned to produce the actual token | |
2003 */ | |
2004 Token assertToken(TokenType expectedType, String source) { | |
2005 Token originalToken = scan2(source); | |
2006 JUnitTestCase.assertNotNull(originalToken); | |
2007 JUnitTestCase.assertEquals(expectedType, originalToken.type); | |
2008 JUnitTestCase.assertEquals(0, originalToken.offset); | |
2009 JUnitTestCase.assertEquals(source.length, originalToken.length); | |
2010 JUnitTestCase.assertEquals(source, originalToken.lexeme); | |
2011 if (identical(expectedType, TokenType.SCRIPT_TAG)) { | |
2012 return originalToken; | |
2013 } else if (identical(expectedType, TokenType.SINGLE_LINE_COMMENT)) { | |
2014 Token tokenWithSpaces = scan2(" ${source}"); | |
2015 JUnitTestCase.assertNotNull(tokenWithSpaces); | |
2016 JUnitTestCase.assertEquals(expectedType, tokenWithSpaces.type); | |
2017 JUnitTestCase.assertEquals(1, tokenWithSpaces.offset); | |
2018 JUnitTestCase.assertEquals(source.length, tokenWithSpaces.length); | |
2019 JUnitTestCase.assertEquals(source, tokenWithSpaces.lexeme); | |
2020 return originalToken; | |
2021 } | |
2022 Token tokenWithSpaces = scan2(" ${source} "); | |
2023 JUnitTestCase.assertNotNull(tokenWithSpaces); | |
2024 JUnitTestCase.assertEquals(expectedType, tokenWithSpaces.type); | |
2025 JUnitTestCase.assertEquals(1, tokenWithSpaces.offset); | |
2026 JUnitTestCase.assertEquals(source.length, tokenWithSpaces.length); | |
2027 JUnitTestCase.assertEquals(source, tokenWithSpaces.lexeme); | |
2028 JUnitTestCase.assertEquals(TokenType.EOF, originalToken.next.type); | |
2029 return originalToken; | |
2030 } | |
2031 /** | |
2032 * Assert that when scanned the given source contains a sequence of tokens ide
ntical to the given | |
2033 * tokens. | |
2034 * @param source the source to be scanned | |
2035 * @param expectedTokens the tokens that are expected to be in the source | |
2036 */ | |
2037 void assertTokens(String source, List<Token> expectedTokens) { | |
2038 Token token = scan2(source); | |
2039 JUnitTestCase.assertNotNull(token); | |
2040 for (int i = 0; i < expectedTokens.length; i++) { | |
2041 Token expectedToken = expectedTokens[i]; | |
2042 JUnitTestCase.assertEqualsMsg("Wrong type for token ${i}", expectedToken.t
ype, token.type); | |
2043 JUnitTestCase.assertEqualsMsg("Wrong offset for token ${i}", expectedToken
.offset, token.offset); | |
2044 JUnitTestCase.assertEqualsMsg("Wrong length for token ${i}", expectedToken
.length, token.length); | |
2045 JUnitTestCase.assertEqualsMsg("Wrong lexeme for token ${i}", expectedToken
.lexeme, token.lexeme); | |
2046 token = token.next; | |
2047 JUnitTestCase.assertNotNull(token); | |
2048 } | |
2049 JUnitTestCase.assertEquals(TokenType.EOF, token.type); | |
2050 } | |
2051 Token scan2(String source) { | |
2052 GatheringErrorListener listener = new GatheringErrorListener(); | |
2053 Token token = scan(source, listener); | |
2054 listener.assertNoErrors(); | |
2055 return token; | |
2056 } | |
2057 } | |
2058 main() { | |
2059 CharBufferScannerTest.dartSuite(); | |
2060 KeywordStateTest.dartSuite(); | |
2061 StringScannerTest.dartSuite(); | |
2062 TokenTypeTest.dartSuite(); | |
2063 } | |
OLD | NEW |