| 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 library compiler_helper; | 5 library compiler_helper; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import "package:expect/expect.dart"; | 8 import "package:expect/expect.dart"; |
| 9 | 9 |
| 10 import 'package:compiler/src/elements/elements.dart' as lego; | 10 import 'package:compiler/src/elements/elements.dart' as lego; |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 final spaceRe = new RegExp('\\s+'); | 253 final spaceRe = new RegExp('\\s+'); |
| 254 regexp = regexp.replaceAll(spaceRe, '(?:\\s*)'); | 254 regexp = regexp.replaceAll(spaceRe, '(?:\\s*)'); |
| 255 if (shouldMatch) { | 255 if (shouldMatch) { |
| 256 Expect.isTrue(new RegExp(regexp).hasMatch(generated)); | 256 Expect.isTrue(new RegExp(regexp).hasMatch(generated)); |
| 257 } else { | 257 } else { |
| 258 Expect.isFalse(new RegExp(regexp).hasMatch(generated)); | 258 Expect.isFalse(new RegExp(regexp).hasMatch(generated)); |
| 259 } | 259 } |
| 260 }); | 260 }); |
| 261 } | 261 } |
| 262 | 262 |
| 263 | |
| 264 /// Returns a 'check' function that uses comments in [test] to drive checking. | 263 /// Returns a 'check' function that uses comments in [test] to drive checking. |
| 265 /// | 264 /// |
| 266 /// The comments contains one or more 'present:' or 'absent:' tags, each | 265 /// The comments contains one or more 'present:' or 'absent:' tags, each |
| 267 /// followed by a quoted string. For example, the returned checker for the | 266 /// followed by a quoted string. For example, the returned checker for the |
| 268 /// following text will ensure that the argument contains the three characters | 267 /// following text will ensure that the argument contains the three characters |
| 269 /// 'foo' and does not contain the two characters '""': | 268 /// 'foo' and does not contain the two characters '""': |
| 270 /// | 269 /// |
| 271 /// // present: "foo" | 270 /// // present: "foo" |
| 272 /// // absent: '""' | 271 /// // absent: '""' |
| 273 checkerForAbsentPresent(String test) { | 272 checkerForAbsentPresent(String test) { |
| 274 var matches = _directivePattern.allMatches(test).toList(); | 273 var matches = _directivePattern.allMatches(test).toList(); |
| 275 checker(String generated) { | 274 checker(String generated) { |
| 276 if (matches.isEmpty) { | 275 if (matches.isEmpty) { |
| 277 Expect.fail("No 'absent:' or 'present:' directives in '$test'"); | 276 Expect.fail("No 'absent:' or 'present:' directives in '$test'"); |
| 278 } | 277 } |
| 279 for (Match match in matches) { | 278 for (Match match in matches) { |
| 280 String directive = match.group(1); | 279 String directive = match.group(1); |
| 281 String pattern = match.groups([2, 3]).where((s) => s != null).single; | 280 String pattern = match.groups([2, 3]).where((s) => s != null).single; |
| 282 if (directive == 'present') { | 281 if (directive == 'present') { |
| 283 Expect.isTrue(generated.contains(pattern), | 282 Expect.isTrue(generated.contains(pattern), |
| 284 "Cannot find '$pattern' in:\n$generated"); | 283 "Cannot find '$pattern' in:\n$generated"); |
| 285 } else { | 284 } else { |
| 286 assert(directive == 'absent'); | 285 assert(directive == 'absent'); |
| 287 Expect.isFalse(generated.contains(pattern), | 286 Expect.isFalse(generated.contains(pattern), |
| 288 "Must not find '$pattern' in:\n$generated"); | 287 "Must not find '$pattern' in:\n$generated"); |
| 289 } | 288 } |
| 290 } | 289 } |
| 291 } | 290 } |
| 291 |
| 292 return checker; | 292 return checker; |
| 293 } | 293 } |
| 294 | 294 |
| 295 RegExp _directivePattern = new RegExp( | 295 RegExp _directivePattern = new RegExp( |
| 296 // \1 \2 \3 | 296 // \1 \2 \3 |
| 297 r'''// *(present|absent): *(?:"([^"]*)"|'([^'']*)')''', | 297 r'''// *(present|absent): *(?:"([^"]*)"|'([^'']*)')''', |
| 298 multiLine: true); | 298 multiLine: true); |
| OLD | NEW |