| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 test.integration.analysis; | 5 library test.integration.analysis; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 import 'dart:convert'; | 9 import 'dart:convert'; |
| 10 import 'dart:io'; | 10 import 'dart:io'; |
| (...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 } else { | 449 } else { |
| 450 return iterableMatcher.describeMismatch(item, mismatchDescription, | 450 return iterableMatcher.describeMismatch(item, mismatchDescription, |
| 451 matchState, verbose); | 451 matchState, verbose); |
| 452 } | 452 } |
| 453 } | 453 } |
| 454 } | 454 } |
| 455 | 455 |
| 456 Matcher isListOf(Matcher elementMatcher) => new _ListOf(elementMatcher); | 456 Matcher isListOf(Matcher elementMatcher) => new _ListOf(elementMatcher); |
| 457 | 457 |
| 458 /** | 458 /** |
| 459 * Type of closures used by LazyMatcher. |
| 460 */ |
| 461 typedef Matcher MatcherCreator(); |
| 462 |
| 463 /** |
| 464 * Wrapper class for Matcher which doesn't create the underlying Matcher object |
| 465 * until it is needed. This is necessary in order to create matchers that can |
| 466 * refer to themselves (so that recursive data structures can be represented). |
| 467 */ |
| 468 class LazyMatcher implements Matcher { |
| 469 /** |
| 470 * Callback that will be used to create the matcher the first time it is |
| 471 * needed. |
| 472 */ |
| 473 final MatcherCreator _creator; |
| 474 |
| 475 /** |
| 476 * The matcher returned by [_creator], if it has already been called. |
| 477 * Otherwise null. |
| 478 */ |
| 479 Matcher _wrappedMatcher; |
| 480 |
| 481 LazyMatcher(this._creator); |
| 482 |
| 483 @override |
| 484 Description describe(Description description) { |
| 485 _createMatcher(); |
| 486 return _wrappedMatcher.describe(description); |
| 487 } |
| 488 |
| 489 @override |
| 490 Description describeMismatch(item, Description mismatchDescription, Map matchS
tate, bool verbose) { |
| 491 _createMatcher(); |
| 492 return _wrappedMatcher.describeMismatch(item, mismatchDescription, matchStat
e, verbose); |
| 493 } |
| 494 |
| 495 @override |
| 496 bool matches(item, Map matchState) { |
| 497 _createMatcher(); |
| 498 return _wrappedMatcher.matches(item, matchState); |
| 499 } |
| 500 |
| 501 /** |
| 502 * Create the wrapped matcher object, if it hasn't been created already. |
| 503 */ |
| 504 void _createMatcher() { |
| 505 if (_wrappedMatcher == null) { |
| 506 _wrappedMatcher = _creator(); |
| 507 } |
| 508 } |
| 509 } |
| 510 |
| 511 /** |
| 459 * Matcher that matches a union of different types, each of which is described | 512 * Matcher that matches a union of different types, each of which is described |
| 460 * by a matcher. | 513 * by a matcher. |
| 461 */ | 514 */ |
| 462 class _OneOf extends Matcher { | 515 class _OneOf extends Matcher { |
| 463 /** | 516 /** |
| 464 * Matchers for the individual choices. | 517 * Matchers for the individual choices. |
| 465 */ | 518 */ |
| 466 final List<Matcher> choiceMatchers; | 519 final List<Matcher> choiceMatchers; |
| 467 | 520 |
| 468 _OneOf(this.choiceMatchers); | 521 _OneOf(this.choiceMatchers); |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 776 */ | 829 */ |
| 777 void _recordStdio(String line) { | 830 void _recordStdio(String line) { |
| 778 double elapsedTime = _time.elapsedTicks / _time.frequency; | 831 double elapsedTime = _time.elapsedTicks / _time.frequency; |
| 779 line = "$elapsedTime: $line"; | 832 line = "$elapsedTime: $line"; |
| 780 if (_debuggingStdio) { | 833 if (_debuggingStdio) { |
| 781 print(line); | 834 print(line); |
| 782 } | 835 } |
| 783 _recordedStdio.add(line); | 836 _recordedStdio.add(line); |
| 784 } | 837 } |
| 785 } | 838 } |
| OLD | NEW |