| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 "dart:async"; | 5 import "dart:async"; |
| 6 | 6 |
| 7 import "package:async_helper/async_helper.dart"; | 7 import "package:async_helper/async_helper.dart"; |
| 8 import 'package:compiler/compiler.dart'; | 8 import 'package:compiler/compiler.dart'; |
| 9 import "package:compiler/src/elements/elements.dart"; | 9 import "package:compiler/src/elements/elements.dart"; |
| 10 import "package:compiler/src/old_to_new_api.dart"; | 10 import "package:compiler/src/old_to_new_api.dart"; |
| 11 import "package:expect/expect.dart"; | 11 import "package:expect/expect.dart"; |
| 12 | 12 |
| 13 import "mock_compiler.dart"; | 13 import "mock_compiler.dart"; |
| 14 | 14 |
| 15 Future testErrorHandling() { | 15 Future testErrorHandling() { |
| 16 // Test that compiler.currentElement is set correctly when | 16 // Test that compiler.currentElement is set correctly when |
| 17 // reporting errors/warnings. | 17 // reporting errors/warnings. |
| 18 MockCompiler compiler = new MockCompiler.internal(); | 18 MockCompiler compiler = new MockCompiler.internal(); |
| 19 return compiler.init().then((_) { | 19 return compiler.init().then((_) { |
| 20 compiler.parseScript('NoSuchPrefix.NoSuchType foo() {}'); | 20 compiler.parseScript('NoSuchPrefix.NoSuchType foo() {}'); |
| 21 FunctionElement foo = compiler.mainApp.find('foo'); | 21 LibraryElement mainApp = compiler.mainApp; |
| 22 FunctionElement foo = mainApp.find('foo'); |
| 22 compiler.diagnosticHandler = new LegacyCompilerDiagnostics( | 23 compiler.diagnosticHandler = new LegacyCompilerDiagnostics( |
| 23 (Uri uri, int begin, int end, String message, Diagnostic kind) { | 24 (Uri uri, int begin, int end, String message, Diagnostic kind) { |
| 24 if (kind == Diagnostic.WARNING) { | 25 if (kind == Diagnostic.WARNING) { |
| 25 Expect.equals(foo, compiler.currentElement); | 26 Expect.equals(foo, compiler.currentElement); |
| 26 } | 27 } |
| 27 }); | 28 }); |
| 28 foo.computeType(compiler.resolution); | 29 foo.computeType(compiler.resolution); |
| 29 Expect.equals(1, compiler.diagnosticCollector.warnings.length); | 30 Expect.equals(1, compiler.diagnosticCollector.warnings.length); |
| 30 }); | 31 }); |
| 31 } | 32 } |
| 32 | 33 |
| 33 main() { | 34 main() { |
| 34 asyncTest(() => testErrorHandling()); | 35 asyncTest(() => testErrorHandling()); |
| 35 } | 36 } |
| OLD | NEW |