| 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 Expect.isNotNull(kind.howToFix); | 18 {bool expectNoHowToFix: false}) { |
| 19 if (expectNoHowToFix) { |
| 20 Expect.isNull(kind.howToFix); |
| 21 } else { |
| 22 Expect.isNotNull(kind.howToFix); |
| 23 } |
| 19 Expect.isFalse(kind.examples.isEmpty); | 24 Expect.isFalse(kind.examples.isEmpty); |
| 20 | 25 |
| 21 for (String example in kind.examples) { | 26 for (String example in kind.examples) { |
| 22 List<String> messages = <String>[]; | 27 List<String> messages = <String>[]; |
| 23 void collect(Uri uri, int begin, int end, String message, kind) { | 28 void collect(Uri uri, int begin, int end, String message, kind) { |
| 24 if (kind.name == 'verbose info') { | 29 if (kind.name == 'verbose info') { |
| 25 return; | 30 return; |
| 26 } | 31 } |
| 27 messages.add(message); | 32 messages.add(message); |
| 28 } | 33 } |
| 29 | 34 |
| 30 Compiler compiler = compilerFor( | 35 Compiler compiler = compilerFor( |
| 31 {'main.dart': example}, | 36 {'main.dart': example}, |
| 32 diagnosticHandler: collect, | 37 diagnosticHandler: collect, |
| 33 options: ['--analyze-only'], | 38 options: ['--analyze-only'], |
| 34 cachedCompiler: cachedCompiler); | 39 cachedCompiler: cachedCompiler); |
| 35 | 40 |
| 36 compiler.run(Uri.parse('memory:main.dart')); | 41 compiler.run(Uri.parse('memory:main.dart')); |
| 37 | 42 |
| 38 Expect.isFalse(messages.isEmpty, 'No messages in """$example"""'); | 43 Expect.isFalse(messages.isEmpty, 'No messages in """$example"""'); |
| 39 | 44 |
| 40 String pattern = '${kind.template}\n${kind.howToFix}'.replaceAllMapped( | 45 String expectedText = kind.howToFix == null |
| 46 ? kind.template : '${kind.template}\n${kind.howToFix}'; |
| 47 String pattern = expectedText.replaceAllMapped( |
| 41 new RegExp(ESCAPE_REGEXP), (m) => '\\${m[0]}'); | 48 new RegExp(ESCAPE_REGEXP), (m) => '\\${m[0]}'); |
| 42 pattern = pattern.replaceAll(new RegExp(r'#\\\{[^}]*\\\}'), '.*'); | 49 pattern = pattern.replaceAll(new RegExp(r'#\\\{[^}]*\\\}'), '.*'); |
| 43 | 50 |
| 44 for (String message in messages) { | 51 for (String message in messages) { |
| 45 Expect.isTrue(new RegExp('^$pattern\$').hasMatch(message), | 52 Expect.isTrue(new RegExp('^$pattern\$').hasMatch(message), |
| 46 '"$pattern" does not match "$message"'); | 53 '"$pattern" does not match "$message"'); |
| 47 } | 54 } |
| 48 return compiler; | 55 return compiler; |
| 49 } | 56 } |
| 50 } | 57 } |
| OLD | NEW |