| 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 unittest.matcher.test_utils; | 5 library unittest.matcher.test_utils; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:unittest/unittest.dart'; | 9 import 'package:unittest/unittest.dart'; |
| 10 | 10 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 configureExpectFailureHandler(null); | 34 configureExpectFailureHandler(null); |
| 35 expect(_errorCount, equals(1)); | 35 expect(_errorCount, equals(1)); |
| 36 if (expected is String) { | 36 if (expected is String) { |
| 37 expect(_errorString, equalsIgnoringWhitespace(expected)); | 37 expect(_errorString, equalsIgnoringWhitespace(expected)); |
| 38 } else { | 38 } else { |
| 39 expect(_errorString.replaceAll('\n', ''), expected); | 39 expect(_errorString.replaceAll('\n', ''), expected); |
| 40 } | 40 } |
| 41 } | 41 } |
| 42 | 42 |
| 43 if (isAsync) { | 43 if (isAsync) { |
| 44 Timer.run(expectAsync(afterTest)); | 44 Timer.run(expectAsync0(afterTest)); |
| 45 } else { | 45 } else { |
| 46 afterTest(); | 46 afterTest(); |
| 47 } | 47 } |
| 48 } | 48 } |
| 49 | 49 |
| 50 void shouldPass(value, Matcher matcher, {bool isAsync: false}) { | 50 void shouldPass(value, Matcher matcher, {bool isAsync: false}) { |
| 51 configureExpectFailureHandler(_testHandler); | 51 configureExpectFailureHandler(_testHandler); |
| 52 _errorCount = 0; | 52 _errorCount = 0; |
| 53 _errorString = ''; | 53 _errorString = ''; |
| 54 expect(value, matcher); | 54 expect(value, matcher); |
| 55 afterTest() { | 55 afterTest() { |
| 56 configureExpectFailureHandler(null); | 56 configureExpectFailureHandler(null); |
| 57 expect(_errorCount, equals(0)); | 57 expect(_errorCount, equals(0)); |
| 58 } | 58 } |
| 59 if (isAsync) { | 59 if (isAsync) { |
| 60 Timer.run(expectAsync(afterTest)); | 60 Timer.run(expectAsync0(afterTest)); |
| 61 } else { | 61 } else { |
| 62 afterTest(); | 62 afterTest(); |
| 63 } | 63 } |
| 64 } | 64 } |
| 65 | 65 |
| 66 doesNotThrow() {} | 66 doesNotThrow() {} |
| 67 doesThrow() { | 67 doesThrow() { |
| 68 throw 'X'; | 68 throw 'X'; |
| 69 } | 69 } |
| 70 | 70 |
| 71 class PrefixMatcher extends Matcher { | 71 class PrefixMatcher extends Matcher { |
| 72 final String _prefix; | 72 final String _prefix; |
| 73 const PrefixMatcher(this._prefix); | 73 const PrefixMatcher(this._prefix); |
| 74 bool matches(item, Map matchState) { | 74 bool matches(item, Map matchState) { |
| 75 return item is String && | 75 return item is String && |
| 76 (collapseWhitespace(item)).startsWith(collapseWhitespace(_prefix)); | 76 (collapseWhitespace(item)).startsWith(collapseWhitespace(_prefix)); |
| 77 } | 77 } |
| 78 | 78 |
| 79 Description describe(Description description) => description | 79 Description describe(Description description) => description |
| 80 .add('a string starting with ') | 80 .add('a string starting with ') |
| 81 .addDescriptionOf(collapseWhitespace(_prefix)) | 81 .addDescriptionOf(collapseWhitespace(_prefix)) |
| 82 .add(' ignoring whitespace'); | 82 .add(' ignoring whitespace'); |
| 83 } | 83 } |
| OLD | NEW |