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 matcher.core_matchers_test; | 5 library matcher.core_matchers_test; |
6 | 6 |
7 import 'package:matcher/matcher.dart'; | 7 import 'package:matcher/matcher.dart'; |
8 import 'package:unittest/unittest.dart' show test, group; | 8 import 'package:unittest/unittest.dart' show test, group; |
9 | 9 |
10 import 'test_utils.dart'; | 10 import 'test_utils.dart'; |
11 | 11 |
12 void main() { | 12 void main() { |
13 initUtils(); | |
14 | |
15 test('isTrue', () { | 13 test('isTrue', () { |
16 shouldPass(true, isTrue); | 14 shouldPass(true, isTrue); |
17 shouldFail(false, isTrue, "Expected: true Actual: <false>"); | 15 shouldFail(false, isTrue, "Expected: true Actual: <false>"); |
18 }); | 16 }); |
19 | 17 |
20 test('isFalse', () { | 18 test('isFalse', () { |
21 shouldPass(false, isFalse); | 19 shouldPass(false, isFalse); |
22 shouldFail(10, isFalse, "Expected: false Actual: <10>"); | 20 shouldFail(10, isFalse, "Expected: false Actual: <10>"); |
23 shouldFail(true, isFalse, "Expected: false Actual: <true>"); | 21 shouldFail(true, isFalse, "Expected: false Actual: <true>"); |
24 }); | 22 }); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
110 r"from Function 'doesThrow': static\.)?>" | 108 r"from Function 'doesThrow': static\.)?>" |
111 r" Which: threw 'X'")); | 109 r" Which: threw 'X'")); |
112 }); | 110 }); |
113 | 111 |
114 test('hasLength', () { | 112 test('hasLength', () { |
115 var a = new Map(); | 113 var a = new Map(); |
116 var b = new List(); | 114 var b = new List(); |
117 shouldPass(a, hasLength(0)); | 115 shouldPass(a, hasLength(0)); |
118 shouldPass(b, hasLength(0)); | 116 shouldPass(b, hasLength(0)); |
119 shouldPass('a', hasLength(1)); | 117 shouldPass('a', hasLength(1)); |
120 shouldFail(0, hasLength(0), new PrefixMatcher( | 118 shouldFail(0, hasLength(0), new _PrefixMatcher( |
121 "Expected: an object with length of <0> " | 119 "Expected: an object with length of <0> " |
122 "Actual: <0> " | 120 "Actual: <0> " |
123 "Which: has no length property")); | 121 "Which: has no length property")); |
124 | 122 |
125 b.add(0); | 123 b.add(0); |
126 shouldPass(b, hasLength(1)); | 124 shouldPass(b, hasLength(1)); |
127 shouldFail(b, hasLength(2), "Expected: an object with length of <2> " | 125 shouldFail(b, hasLength(2), "Expected: an object with length of <2> " |
128 "Actual: [0] " | 126 "Actual: [0] " |
129 "Which: has length of <1>"); | 127 "Which: has length of <1>"); |
130 | 128 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
183 }); | 181 }); |
184 | 182 |
185 group('Predicate Matchers', () { | 183 group('Predicate Matchers', () { |
186 test('isInstanceOf', () { | 184 test('isInstanceOf', () { |
187 shouldFail(0, predicate((x) => x is String, "an instance of String"), | 185 shouldFail(0, predicate((x) => x is String, "an instance of String"), |
188 "Expected: an instance of String Actual: <0>"); | 186 "Expected: an instance of String Actual: <0>"); |
189 shouldPass('cow', predicate((x) => x is String, "an instance of String")); | 187 shouldPass('cow', predicate((x) => x is String, "an instance of String")); |
190 }); | 188 }); |
191 }); | 189 }); |
192 } | 190 } |
191 | |
192 class _PrefixMatcher extends Matcher { | |
nweiz
2015/02/17 23:17:42
Add at least a short description of this.
kevmoo
2015/02/18 00:33:40
Or remove it. Much easier. :-)
| |
193 final String _prefix; | |
194 const _PrefixMatcher(this._prefix); | |
195 bool matches(item, Map matchState) { | |
196 return item is String && | |
197 (collapseWhitespace(item)).startsWith(collapseWhitespace(_prefix)); | |
198 } | |
199 | |
200 Description describe(Description description) => description | |
201 .add('a string starting with ') | |
202 .addDescriptionOf(collapseWhitespace(_prefix)) | |
203 .add(' ignoring whitespace'); | |
204 } | |
OLD | NEW |