| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 library dart2js.test.message_kind_helper; | 5 library dart2js.test.message_kind_helper; |
| 6 | 6 |
| 7 import 'package:expect/expect.dart'; | 7 import 'package:expect/expect.dart'; |
| 8 | 8 |
| 9 import '../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart' show | 9 import '../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart' show |
| 10 Compiler, | 10 Compiler, |
| 11 MessageKind; | 11 MessageKind; |
| 12 | 12 |
| 13 import 'memory_compiler.dart'; | 13 import 'memory_compiler.dart'; |
| 14 | 14 |
| 15 const String ESCAPE_REGEXP = r'[[\]{}()*+?.\\^$|]'; | 15 const String ESCAPE_REGEXP = r'[[\]{}()*+?.\\^$|]'; |
| 16 | 16 |
| 17 Compiler check(MessageKind kind, Compiler cachedCompiler, | 17 Compiler check(MessageKind kind, Compiler cachedCompiler) { |
| 18 {bool expectNoHowToFix: false}) { | 18 Expect.isNotNull(kind.howToFix); |
| 19 if (expectNoHowToFix) { | |
| 20 Expect.isNull(kind.howToFix); | |
| 21 } else { | |
| 22 Expect.isNotNull(kind.howToFix); | |
| 23 } | |
| 24 Expect.isFalse(kind.examples.isEmpty); | 19 Expect.isFalse(kind.examples.isEmpty); |
| 25 | 20 |
| 26 for (String example in kind.examples) { | 21 for (String example in kind.examples) { |
| 27 List<String> messages = <String>[]; | 22 List<String> messages = <String>[]; |
| 28 void collect(Uri uri, int begin, int end, String message, kind) { | 23 void collect(Uri uri, int begin, int end, String message, kind) { |
| 29 if (kind.name == 'verbose info') { | 24 if (kind.name == 'verbose info') { |
| 30 return; | 25 return; |
| 31 } | 26 } |
| 32 messages.add(message); | 27 messages.add(message); |
| 33 } | 28 } |
| 34 | 29 |
| 35 Compiler compiler = compilerFor( | 30 Compiler compiler = compilerFor( |
| 36 {'main.dart': example}, | 31 {'main.dart': example}, |
| 37 diagnosticHandler: collect, | 32 diagnosticHandler: collect, |
| 38 options: ['--analyze-only'], | 33 options: ['--analyze-only'], |
| 39 cachedCompiler: cachedCompiler); | 34 cachedCompiler: cachedCompiler); |
| 40 | 35 |
| 41 compiler.run(Uri.parse('memory:main.dart')); | 36 compiler.run(Uri.parse('memory:main.dart')); |
| 42 | 37 |
| 43 Expect.isFalse(messages.isEmpty, 'No messages in """$example"""'); | 38 Expect.isFalse(messages.isEmpty, 'No messages in """$example"""'); |
| 44 | 39 |
| 45 String expectedText = kind.howToFix == null | 40 String expectedText = !kind.hasHowToFix |
| 46 ? kind.template : '${kind.template}\n${kind.howToFix}'; | 41 ? kind.template : '${kind.template}\n${kind.howToFix}'; |
| 47 String pattern = expectedText.replaceAllMapped( | 42 String pattern = expectedText.replaceAllMapped( |
| 48 new RegExp(ESCAPE_REGEXP), (m) => '\\${m[0]}'); | 43 new RegExp(ESCAPE_REGEXP), (m) => '\\${m[0]}'); |
| 49 pattern = pattern.replaceAll(new RegExp(r'#\\\{[^}]*\\\}'), '.*'); | 44 pattern = pattern.replaceAll(new RegExp(r'#\\\{[^}]*\\\}'), '.*'); |
| 50 | 45 |
| 51 for (String message in messages) { | 46 for (String message in messages) { |
| 52 Expect.isTrue(new RegExp('^$pattern\$').hasMatch(message), | 47 Expect.isTrue(new RegExp('^$pattern\$').hasMatch(message), |
| 53 '"$pattern" does not match "$message"'); | 48 '"$pattern" does not match "$message"'); |
| 54 } | 49 } |
| 55 return compiler; | 50 cachedCompiler = compiler; |
| 56 } | 51 } |
| 52 |
| 53 return cachedCompiler; |
| 57 } | 54 } |
| OLD | NEW |