OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
6 import 'parser_helper.dart'; | 6 import 'parser_helper.dart'; |
7 import 'package:compiler/src/tree/tree.dart'; | 7 import 'package:compiler/src/tree/tree.dart'; |
8 | 8 |
9 void testStatement(String statement) { | 9 void testStatement(String statement) { |
10 Node node = parseStatement(statement); | 10 Node node = parseStatement(statement); |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 FunctionExpression function = parseMember('operator -() => null;'); | 285 FunctionExpression function = parseMember('operator -() => null;'); |
286 Send name = function.name.asSend(); | 286 Send name = function.name.asSend(); |
287 Expect.isNotNull(name); | 287 Expect.isNotNull(name); |
288 Expect.stringEquals('operator', name.receiver.toString()); | 288 Expect.stringEquals('operator', name.receiver.toString()); |
289 Expect.stringEquals('-', name.selector.toString()); | 289 Expect.stringEquals('-', name.selector.toString()); |
290 Expect.isTrue(function.parameters.isEmpty); | 290 Expect.isTrue(function.parameters.isEmpty); |
291 Expect.isNull(function.returnType); | 291 Expect.isNull(function.returnType); |
292 Expect.isNull(function.getOrSet); | 292 Expect.isNull(function.getOrSet); |
293 } | 293 } |
294 | 294 |
295 class Collector extends DiagnosticListener { | 295 class Collector extends DiagnosticReporter { |
296 int token = -1; | 296 int token = -1; |
297 | 297 |
298 void reportFatalError(Token token) { | 298 void reportFatalError(Token token) { |
299 this.token = token.kind; | 299 this.token = token.kind; |
300 throw this; | 300 throw this; |
301 } | 301 } |
302 | 302 |
303 void reportError( | 303 void reportError( |
304 DiagnosticMessage message, | 304 DiagnosticMessage message, |
305 [List<DiagnosticMessage> infos = const <DiagnosticMessage>[]]) { | 305 [List<DiagnosticMessage> infos = const <DiagnosticMessage>[]]) { |
(...skipping 13 matching lines...) Expand all Loading... |
319 return new DiagnosticMessage(null, spannable, null); | 319 return new DiagnosticMessage(null, spannable, null); |
320 } | 320 } |
321 } | 321 } |
322 | 322 |
323 void testMissingCloseParen() { | 323 void testMissingCloseParen() { |
324 final String source = | 324 final String source = |
325 '''foo(x { // <= missing closing ")" | 325 '''foo(x { // <= missing closing ")" |
326 return x; | 326 return x; |
327 }'''; | 327 }'''; |
328 parse() { | 328 parse() { |
329 parseMember(source, diagnosticHandler: new Collector()); | 329 parseMember(source, reporter: new Collector()); |
330 } | 330 } |
331 check(Collector c) { | 331 check(Collector c) { |
332 Expect.equals(OPEN_CURLY_BRACKET_TOKEN, c.token); | 332 Expect.equals(OPEN_CURLY_BRACKET_TOKEN, c.token); |
333 return true; | 333 return true; |
334 } | 334 } |
335 Expect.throws(parse, check); | 335 Expect.throws(parse, check); |
336 } | 336 } |
337 | 337 |
338 void testMissingCloseBraceInClass() { | 338 void testMissingCloseBraceInClass() { |
339 final String source = 'class Foo {'; // Missing close '}'. | 339 final String source = 'class Foo {'; // Missing close '}'. |
340 parse() { | 340 parse() { |
341 fullParseUnit(source, diagnosticHandler: new Collector()); | 341 fullParseUnit(source, reporter: new Collector()); |
342 } | 342 } |
343 check(Collector c) { | 343 check(Collector c) { |
344 Expect.equals(BAD_INPUT_TOKEN, c.token); | 344 Expect.equals(BAD_INPUT_TOKEN, c.token); |
345 return true; | 345 return true; |
346 } | 346 } |
347 Expect.throws(parse, check); | 347 Expect.throws(parse, check); |
348 } | 348 } |
349 | 349 |
350 void testUnmatchedAngleBracket() { | 350 void testUnmatchedAngleBracket() { |
351 final String source = 'A<'; // unmatched '<' | 351 final String source = 'A<'; // unmatched '<' |
352 parse() { | 352 parse() { |
353 fullParseUnit(source, diagnosticHandler: new Collector()); | 353 fullParseUnit(source, reporter: new Collector()); |
354 } | 354 } |
355 check(Collector c) { | 355 check(Collector c) { |
356 Expect.equals(LT_TOKEN, c.token); | 356 Expect.equals(LT_TOKEN, c.token); |
357 return true; | 357 return true; |
358 } | 358 } |
359 Expect.throws(parse, check); | 359 Expect.throws(parse, check); |
360 } | 360 } |
361 | 361 |
362 void main() { | 362 void main() { |
363 testGenericTypes(); | 363 testGenericTypes(); |
364 // TODO(ahe): Enable this test when we handle library prefixes. | 364 // TODO(ahe): Enable this test when we handle library prefixes. |
365 // testPrefixedGenericTypes(); | 365 // testPrefixedGenericTypes(); |
366 testUnaryExpression(); | 366 testUnaryExpression(); |
367 testChainedMethodCalls(); | 367 testChainedMethodCalls(); |
368 testFunctionStatement(); | 368 testFunctionStatement(); |
369 testDoStatement(); | 369 testDoStatement(); |
370 testWhileStatement(); | 370 testWhileStatement(); |
371 testConditionalExpression(); | 371 testConditionalExpression(); |
372 testNullOperators(); | 372 testNullOperators(); |
373 testAssignment(); | 373 testAssignment(); |
374 testIndex(); | 374 testIndex(); |
375 testPostfix(); | 375 testPostfix(); |
376 testOperatorParse(); | 376 testOperatorParse(); |
377 testMissingCloseParen(); | 377 testMissingCloseParen(); |
378 testMissingCloseBraceInClass(); | 378 testMissingCloseBraceInClass(); |
379 testUnmatchedAngleBracket(); | 379 testUnmatchedAngleBracket(); |
380 } | 380 } |
OLD | NEW |