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