| 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('matcherTest'); | 5 #library('matcherTest'); |
| 6 #import('../../../pkg/unittest/unittest.dart'); | 6 #import('../../../pkg/unittest/unittest.dart'); |
| 7 #source('test_utils.dart'); | 7 #source('test_utils.dart'); |
| 8 | 8 |
| 9 doesNotThrow() {} | 9 doesNotThrow() {} |
| 10 doesThrow() { throw 'X'; } | 10 doesThrow() { throw 'X'; } |
| 11 | 11 |
| 12 class PrefixMatcher extends BaseMatcher { | 12 class PrefixMatcher extends BaseMatcher { |
| 13 final String _prefix; | 13 final String _prefix; |
| 14 const PrefixMatcher(this._prefix); | 14 const PrefixMatcher(this._prefix); |
| 15 bool matches(item, MatchState matchState) { | 15 bool matches(item, MatchState matchState) { |
| 16 return item is String && | 16 return item is String && |
| 17 (collapseWhitespace(item)).startsWith(collapseWhitespace(_prefix)); | 17 (collapseWhitespace(item)).startsWith(collapseWhitespace(_prefix)); |
| 18 } | 18 } |
| 19 | 19 |
| 20 Description describe(Description description) => | 20 Description describe(Description description) => |
| 21 description.add('a string starting with '). | 21 description.add('a string starting with '). |
| 22 addDescriptionOf(collapseWhitespace(_prefix)). | 22 addDescriptionOf(collapseWhitespace(_prefix)). |
| 23 add(' ignoring whitespace'); | 23 add(' ignoring whitespace'); |
| 24 } | 24 } |
| 25 | 25 |
| 26 class Widget { |
| 27 int price; |
| 28 } |
| 29 |
| 30 class HasPrice extends FeatureMatcher { |
| 31 const HasPrice(matcher) : |
| 32 super("Widget with a price that is", "price", matcher); |
| 33 featureValueOf(actual) => actual.price; |
| 34 } |
| 35 |
| 26 void main() { | 36 void main() { |
| 27 | 37 |
| 28 initUtils(); | 38 initUtils(); |
| 29 | 39 |
| 30 // Core matchers | 40 // Core matchers |
| 31 | 41 |
| 32 group('Core matchers', () { | 42 group('Core matchers', () { |
| 33 | 43 |
| 34 test('isTrue', () { | 44 test('isTrue', () { |
| 35 shouldPass(true, isTrue); | 45 shouldPass(true, isTrue); |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 | 527 |
| 518 group('Predicate Matchers', () { | 528 group('Predicate Matchers', () { |
| 519 test('isInstanceOf', () { | 529 test('isInstanceOf', () { |
| 520 shouldFail(0, predicate((x) => x is String, | 530 shouldFail(0, predicate((x) => x is String, |
| 521 description: "an instance of String"), | 531 description: "an instance of String"), |
| 522 "Expected: an instance of String but: was <0>."); | 532 "Expected: an instance of String but: was <0>."); |
| 523 shouldPass('cow', predicate((x) => x is String, | 533 shouldPass('cow', predicate((x) => x is String, |
| 524 description: "an instance of String")); | 534 description: "an instance of String")); |
| 525 }); | 535 }); |
| 526 }); | 536 }); |
| 537 |
| 538 group('Feature Matchers', () { |
| 539 test("Feature Matcher", () { |
| 540 var w = new Widget(); |
| 541 w.price = 10; |
| 542 shouldPass(w, new HasPrice(greaterThan(0))); |
| 543 shouldFail(w, new HasPrice(greaterThan(10)), |
| 544 'Expected: Widget with a price that is a value greater than <10> ' |
| 545 'but: price was <10>.'); |
| 546 }); |
| 547 }); |
| 527 } | 548 } |
| 528 | 549 |
| OLD | NEW |