| 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 unittestTests; | 5 library unittestTests; | 
| 6 import 'package:unittest/unittest.dart'; | 6 import 'package:unittest/unittest.dart'; | 
| 7 import 'dart:async'; | 7 import 'dart:async'; | 
| 8 import 'dart:collection'; | 8 import 'dart:collection'; | 
| 9 part 'test_utils.dart'; | 9 part 'test_utils.dart'; | 
| 10 | 10 | 
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 77 void main() { | 77 void main() { | 
| 78 | 78 | 
| 79   initUtils(); | 79   initUtils(); | 
| 80 | 80 | 
| 81   // Core matchers | 81   // Core matchers | 
| 82 | 82 | 
| 83   group('Core matchers', () { | 83   group('Core matchers', () { | 
| 84 | 84 | 
| 85     test('isTrue', () { | 85     test('isTrue', () { | 
| 86       shouldPass(true, isTrue); | 86       shouldPass(true, isTrue); | 
| 87       shouldFail(false, isTrue, "Expected: true but: was <false>."); | 87       shouldFail(false, isTrue, "Expected: true But: was <false>."); | 
| 88     }); | 88     }); | 
| 89 | 89 | 
| 90     test('isFalse', () { | 90     test('isFalse', () { | 
| 91       shouldPass(false, isFalse); | 91       shouldPass(false, isFalse); | 
| 92       shouldFail(10, isFalse, "Expected: false but: was <10>."); | 92       shouldFail(10, isFalse, "Expected: false But: was <10>."); | 
| 93       shouldFail(true, isFalse, "Expected: false but: was <true>."); | 93       shouldFail(true, isFalse, "Expected: false But: was <true>."); | 
| 94     }); | 94     }); | 
| 95 | 95 | 
| 96     test('isNull', () { | 96     test('isNull', () { | 
| 97       shouldPass(null, isNull); | 97       shouldPass(null, isNull); | 
| 98       shouldFail(false, isNull, "Expected: null but: was <false>."); | 98       shouldFail(false, isNull, "Expected: null But: was <false>."); | 
| 99     }); | 99     }); | 
| 100 | 100 | 
| 101     test('isNotNull', () { | 101     test('isNotNull', () { | 
| 102       shouldPass(false, isNotNull); | 102       shouldPass(false, isNotNull); | 
| 103       shouldFail(null, isNotNull, "Expected: not null but: was <null>."); | 103       shouldFail(null, isNotNull, "Expected: not null But: was <null>."); | 
| 104     }); | 104     }); | 
| 105 | 105 | 
| 106     test('same', () { | 106     test('same', () { | 
| 107       var a = new Map(); | 107       var a = new Map(); | 
| 108       var b = new Map(); | 108       var b = new Map(); | 
| 109       shouldPass(a, same(a)); | 109       shouldPass(a, same(a)); | 
| 110       shouldFail(b, same(a), "Expected: same instance as <{}> but: was <{}>."); | 110       shouldFail(b, same(a), "Expected: same instance as {} But: was {}."); | 
| 111     }); | 111     }); | 
| 112 | 112 | 
| 113     test('equals', () { | 113     test('equals', () { | 
| 114       var a = new Map(); | 114       var a = new Map(); | 
| 115       var b = new Map(); | 115       var b = new Map(); | 
| 116       shouldPass(a, equals(a)); | 116       shouldPass(a, equals(a)); | 
| 117       shouldPass(a, equals(b)); | 117       shouldPass(a, equals(b)); | 
| 118     }); | 118     }); | 
| 119 | 119 | 
| 120     test('anything', () { | 120     test('anything', () { | 
| 121       var a = new Map(); | 121       var a = new Map(); | 
| 122       shouldPass(0, anything); | 122       shouldPass(0, anything); | 
| 123       shouldPass(null, anything); | 123       shouldPass(null, anything); | 
| 124       shouldPass(a, anything); | 124       shouldPass(a, anything); | 
| 125       shouldFail(a, isNot(anything), "Expected: not anything but: was <{}>."); | 125       shouldFail(a, isNot(anything), "Expected: not anything But: was {}."); | 
| 126     }); | 126     }); | 
| 127 | 127 | 
| 128     test('throws', () { | 128     test('throws', () { | 
| 129       shouldFail(doesNotThrow, throws, | 129       shouldFail(doesNotThrow, throws, | 
| 130         "Expected: throws an exception but: no exception."); | 130           "Expected: throws an exception But: no exception. " | 
|  | 131           "Actual: <Closure: (dynamic) => dynamic " | 
|  | 132               "from Function 'doesNotThrow': static.>"); | 
| 131       shouldPass(doesThrow, throws); | 133       shouldPass(doesThrow, throws); | 
| 132       shouldFail(true, throws, | 134       shouldFail(true, throws, | 
| 133           "Expected: throws an exception but: not a Function or Future."); | 135           "Expected: throws an exception But: not a Function or Future. " | 
|  | 136           "Actual: <true>"); | 
| 134     }); | 137     }); | 
| 135 | 138 | 
| 136     test('throwsA', () { | 139     test('throwsA', () { | 
| 137       shouldPass(doesThrow, throwsA(equals('X'))); | 140       shouldPass(doesThrow, throwsA(equals('X'))); | 
| 138       shouldFail(doesThrow, throwsA(equals('Y')), | 141       shouldFail(doesThrow, throwsA(equals('Y')), | 
| 139         "Expected: throws an exception which matches 'Y' " | 142           "Expected: throws an exception which matches 'Y' " | 
| 140         "but:  exception 'X' does not match 'Y'."); | 143           "But:  exception 'X' does not match 'Y'. " | 
|  | 144           "Actual: <Closure: (dynamic) => dynamic " | 
|  | 145               "from Function 'doesThrow': static.>"); | 
| 141     }); | 146     }); | 
| 142 | 147 | 
| 143     test('throwsFormatException', () { | 148     test('throwsFormatException', () { | 
| 144       shouldPass(() { throw new FormatException(''); }, | 149       shouldPass(() { throw new FormatException(''); }, | 
| 145           throwsFormatException); | 150           throwsFormatException); | 
| 146       shouldFail(() { throw new Exception(); }, | 151       shouldFail(() { throw new Exception(); }, | 
| 147           throwsFormatException, | 152           throwsFormatException, | 
| 148         "Expected: throws an exception which matches FormatException " | 153           "Expected: throws an exception which matches FormatException " | 
| 149         "but:  exception <Exception> does not match FormatException."); | 154           "But:  exception Unknown:<Exception> does not match FormatException. " | 
|  | 155           "Actual: <Closure: (dynamic) => dynamic>"); | 
| 150     }); | 156     }); | 
| 151 | 157 | 
| 152     test('throwsArgumentError', () { | 158     test('throwsArgumentError', () { | 
| 153       shouldPass(() { throw new ArgumentError(''); }, | 159       shouldPass(() { throw new ArgumentError(''); }, | 
| 154           throwsArgumentError); | 160           throwsArgumentError); | 
| 155       shouldFail(() { throw new Exception(); }, | 161       shouldFail(() { throw new Exception(); }, | 
| 156           throwsArgumentError, | 162           throwsArgumentError, | 
| 157         "Expected: throws an exception which matches ArgumentError " | 163           "Expected: throws an exception which matches ArgumentError " | 
| 158         "but:  exception <Exception> does not match " | 164           "But:  exception Unknown:<Exception> does not match " | 
| 159             "ArgumentError."); | 165               "ArgumentError. " | 
|  | 166           "Actual: <Closure: (dynamic) => dynamic>"); | 
| 160     }); | 167     }); | 
| 161 | 168 | 
| 162     test('throwsRangeError', () { | 169     test('throwsRangeError', () { | 
| 163       shouldPass(() { throw new RangeError(0); }, | 170       shouldPass(() { throw new RangeError(0); }, | 
| 164           throwsRangeError); | 171           throwsRangeError); | 
| 165       shouldFail(() { throw new Exception(); }, | 172       shouldFail(() { throw new Exception(); }, | 
| 166           throwsRangeError, | 173           throwsRangeError, | 
| 167         "Expected: throws an exception which matches RangeError " | 174           "Expected: throws an exception which matches RangeError " | 
| 168         "but:  exception <Exception> does not match RangeError."); | 175           "But:  exception Unknown:<Exception> does not match RangeError. " | 
|  | 176           "Actual: <Closure: (dynamic) => dynamic>"); | 
| 169     }); | 177     }); | 
| 170 | 178 | 
| 171     test('throwsNoSuchMethodError', () { | 179     test('throwsNoSuchMethodError', () { | 
| 172       shouldPass(() { throw new NoSuchMethodError(null, '', null, null); }, | 180       shouldPass(() { throw new NoSuchMethodError(null, '', null, null); }, | 
| 173           throwsNoSuchMethodError); | 181           throwsNoSuchMethodError); | 
| 174       shouldFail(() { throw new Exception(); }, | 182       shouldFail(() { throw new Exception(); }, | 
| 175           throwsNoSuchMethodError, | 183           throwsNoSuchMethodError, | 
| 176         "Expected: throws an exception which matches NoSuchMethodError " | 184           "Expected: throws an exception which matches NoSuchMethodError " | 
| 177         "but:  exception <Exception> does not match " | 185           "But:  exception Unknown:<Exception> does not match " | 
| 178             "NoSuchMethodError."); | 186               "NoSuchMethodError. " | 
|  | 187           "Actual: <Closure: (dynamic) => dynamic>"); | 
| 179     }); | 188     }); | 
| 180 | 189 | 
| 181     test('throwsUnimplementedError', () { | 190     test('throwsUnimplementedError', () { | 
| 182       shouldPass(() { throw new UnimplementedError(''); }, | 191       shouldPass(() { throw new UnimplementedError(''); }, | 
| 183           throwsUnimplementedError); | 192           throwsUnimplementedError); | 
| 184       shouldFail(() { throw new Exception(); }, | 193       shouldFail(() { throw new Exception(); }, | 
| 185           throwsUnimplementedError, | 194           throwsUnimplementedError, | 
| 186         "Expected: throws an exception which matches UnimplementedError " | 195           "Expected: throws an exception which matches UnimplementedError " | 
| 187         "but:  exception <Exception> does not match " | 196           "But:  exception Unknown:<Exception> does not match " | 
| 188             "UnimplementedError."); | 197               "UnimplementedError. " | 
|  | 198           "Actual: <Closure: (dynamic) => dynamic>"); | 
| 189     }); | 199     }); | 
| 190 | 200 | 
| 191     test('throwsUnsupportedError', () { | 201     test('throwsUnsupportedError', () { | 
| 192       shouldPass(() { throw new UnsupportedError(''); }, | 202       shouldPass(() { throw new UnsupportedError(''); }, | 
| 193           throwsUnsupportedError); | 203           throwsUnsupportedError); | 
| 194       shouldFail(() { throw new Exception(); }, | 204       shouldFail(() { throw new Exception(); }, | 
| 195           throwsUnsupportedError, | 205           throwsUnsupportedError, | 
| 196         "Expected: throws an exception which matches UnsupportedError " | 206           "Expected: throws an exception which matches UnsupportedError " | 
| 197         "but:  exception <Exception> does not match " | 207           "But:  exception Unknown:<Exception> does not match " | 
| 198             "UnsupportedError."); | 208               "UnsupportedError. " | 
|  | 209           "Actual: <Closure: (dynamic) => dynamic>"); | 
| 199     }); | 210     }); | 
| 200 | 211 | 
| 201     test('throwsStateError', () { | 212     test('throwsStateError', () { | 
| 202       shouldPass(() { throw new StateError(''); }, | 213       shouldPass(() { throw new StateError(''); }, | 
| 203           throwsStateError); | 214           throwsStateError); | 
| 204       shouldFail(() { throw new Exception(); }, | 215       shouldFail(() { throw new Exception(); }, | 
| 205           throwsStateError, | 216           throwsStateError, | 
| 206         "Expected: throws an exception which matches StateError " | 217           "Expected: throws an exception which matches StateError " | 
| 207         "but:  exception <Exception> does not match " | 218           "But:  exception Unknown:<Exception> does not match " | 
| 208             "StateError."); | 219               "StateError. " | 
|  | 220           "Actual: <Closure: (dynamic) => dynamic>"); | 
| 209     }); | 221     }); | 
| 210 | 222 | 
| 211     test('returnsNormally', () { | 223     test('returnsNormally', () { | 
| 212       shouldPass(doesNotThrow, returnsNormally); | 224       shouldPass(doesNotThrow, returnsNormally); | 
| 213       shouldFail(doesThrow, returnsNormally, | 225       shouldFail(doesThrow, returnsNormally, | 
| 214         "Expected: return normally but: threw 'X'."); | 226           "Expected: return normally But: threw 'X'. " | 
|  | 227           "Actual: <Closure: (dynamic) => dynamic " | 
|  | 228               "from Function 'doesThrow': static.>"); | 
| 215     }); | 229     }); | 
| 216 | 230 | 
| 217     test('hasLength', () { | 231     test('hasLength', () { | 
| 218       var a = new Map(); | 232       var a = new Map(); | 
| 219       var b = new List(); | 233       var b = new List(); | 
| 220       shouldPass(a, hasLength(0)); | 234       shouldPass(a, hasLength(0)); | 
| 221       shouldPass(b, hasLength(0)); | 235       shouldPass(b, hasLength(0)); | 
| 222       shouldPass('a', hasLength(1)); | 236       shouldPass('a', hasLength(1)); | 
| 223       shouldFail(0, hasLength(0), new PrefixMatcher( | 237       shouldFail(0, hasLength(0), new PrefixMatcher( | 
| 224         "Expected: an object with length of <0> " | 238           "Expected: an object with length of <0> " | 
| 225         "but: was <0> has no length property.")); | 239           "But: had no length property." | 
|  | 240           "Actual: <0>")); | 
| 226 | 241 | 
| 227       b.add(0); | 242       b.add(0); | 
| 228       shouldPass(b, hasLength(1)); | 243       shouldPass(b, hasLength(1)); | 
| 229       shouldFail(b, hasLength(2), | 244       shouldFail(b, hasLength(2), | 
| 230         "Expected: an object with length of <2> " | 245           "Expected: an object with length of <2> " | 
| 231         "but: was <[0]> with length of <1>."); | 246           "But: had length of <1>. " | 
|  | 247           "Actual: [0]"); | 
| 232 | 248 | 
| 233       b.add(0); | 249       b.add(0); | 
| 234       shouldFail(b, hasLength(1), | 250       shouldFail(b, hasLength(1), | 
| 235         "Expected: an object with length of <1> " | 251           "Expected: an object with length of <1> " | 
| 236         "but: was <[0, 0]> with length of <2>."); | 252           "But: had length of <2>. " | 
|  | 253           "Actual: [0, 0]"); | 
| 237       shouldPass(b, hasLength(2)); | 254       shouldPass(b, hasLength(2)); | 
| 238     }); | 255     }); | 
| 239 | 256 | 
| 240     test('scalar type mismatch', () { | 257     test('scalar type mismatch', () { | 
| 241       shouldFail('error', equals(5.1), | 258       shouldFail('error', equals(5.1), | 
| 242           matches("^Expected: <5\.1>" | 259           "Expected: <5.1> " | 
| 243                   "     but: was .*:'error' \\(not type .*\\)\.\$")); | 260           "But: was 'error'."); | 
| 244     }); | 261     }); | 
| 245 | 262 | 
| 246     test('nested type mismatch', () { | 263     test('nested type mismatch', () { | 
| 247       shouldFail(['error'], equals([5.1]), | 264       shouldFail(['error'], equals([5.1]), | 
| 248           matches(r"^Expected: <\[5\.1\]>" | 265           "Expected: [5.1] " | 
| 249                   "     but: expected double:<5\.1> " | 266           "But: expected <5.1> but was 'error' mismatch at position 0. " | 
| 250                   "but was .*:'error' mismatch at position 0\.\$")); | 267           "Actual: ['error']"); | 
| 251     }); | 268     }); | 
| 252 | 269 | 
| 253     test('doubly-nested type mismatch', () { | 270     test('doubly-nested type mismatch', () { | 
| 254       shouldFail([['error']], equals([[5.1]]), | 271       shouldFail([['error']], equals([[5.1]]), | 
| 255           matches(r"^Expected: <\[\[5\.1\]\]>" | 272           "Expected: [[5.1]] " | 
| 256                   "     but: expected double:<5\.1> " | 273           "But: expected <5.1> but was 'error' " | 
| 257                   "but was .*:'error' mismatch at position 0 " | 274           "mismatch at position 0 mismatch at position 0. " | 
| 258                   "mismatch at position 0\.\$")); | 275           "Actual: [['error']]"); | 
| 259     }); | 276     }); | 
| 260   }); | 277   }); | 
| 261 | 278 | 
| 262   group('Numeric Matchers', () { | 279   group('Numeric Matchers', () { | 
| 263 | 280 | 
| 264     test('greaterThan', () { | 281     test('greaterThan', () { | 
| 265       shouldPass(10, greaterThan(9)); | 282       shouldPass(10, greaterThan(9)); | 
| 266       shouldFail(9, greaterThan(10), | 283       shouldFail(9, greaterThan(10), | 
| 267         "Expected: a value greater than <10> but: was <9>."); | 284         "Expected: a value greater than <10> But: was <9>."); | 
| 268     }); | 285     }); | 
| 269 | 286 | 
| 270     test('greaterThanOrEqualTo', () { | 287     test('greaterThanOrEqualTo', () { | 
| 271       shouldPass(10, greaterThanOrEqualTo(10)); | 288       shouldPass(10, greaterThanOrEqualTo(10)); | 
| 272       shouldFail(9, greaterThanOrEqualTo(10), | 289       shouldFail(9, greaterThanOrEqualTo(10), | 
| 273         "Expected: a value greater than or equal to <10> but: was <9>."); | 290         "Expected: a value greater than or equal to <10> But: was <9>."); | 
| 274     }); | 291     }); | 
| 275 | 292 | 
| 276     test('lessThan', () { | 293     test('lessThan', () { | 
| 277       shouldFail(10, lessThan(9), "Expected: a value less than <9> " | 294       shouldFail(10, lessThan(9), "Expected: a value less than <9> " | 
| 278           "but: was <10>."); | 295           "But: was <10>."); | 
| 279       shouldPass(9, lessThan(10)); | 296       shouldPass(9, lessThan(10)); | 
| 280     }); | 297     }); | 
| 281 | 298 | 
| 282     test('lessThanOrEqualTo', () { | 299     test('lessThanOrEqualTo', () { | 
| 283       shouldPass(10, lessThanOrEqualTo(10)); | 300       shouldPass(10, lessThanOrEqualTo(10)); | 
| 284       shouldFail(11, lessThanOrEqualTo(10), | 301       shouldFail(11, lessThanOrEqualTo(10), | 
| 285         "Expected: a value less than or equal to <10> but: was <11>."); | 302         "Expected: a value less than or equal to <10> But: was <11>."); | 
| 286     }); | 303     }); | 
| 287 | 304 | 
| 288     test('isZero', () { | 305     test('isZero', () { | 
| 289       shouldPass(0, isZero); | 306       shouldPass(0, isZero); | 
| 290       shouldFail(1, isZero, "Expected: a value equal to <0> but: was <1>."); | 307       shouldFail(1, isZero, "Expected: a value equal to <0> But: was <1>."); | 
| 291     }); | 308     }); | 
| 292 | 309 | 
| 293     test('isNonZero', () { | 310     test('isNonZero', () { | 
| 294       shouldFail(0, isNonZero, "Expected: a value not equal to <0> " | 311       shouldFail(0, isNonZero, "Expected: a value not equal to <0> " | 
| 295           "but: was <0>."); | 312           "But: was <0>."); | 
| 296       shouldPass(1, isNonZero); | 313       shouldPass(1, isNonZero); | 
| 297     }); | 314     }); | 
| 298 | 315 | 
| 299     test('isPositive', () { | 316     test('isPositive', () { | 
| 300       shouldFail(-1, isPositive, "Expected: a positive value " | 317       shouldFail(-1, isPositive, "Expected: a positive value " | 
| 301           "but: was <-1>."); | 318           "But: was <-1>."); | 
| 302       shouldFail(0, isPositive, "Expected: a positive value " | 319       shouldFail(0, isPositive, "Expected: a positive value " | 
| 303           "but: was <0>."); | 320           "But: was <0>."); | 
| 304       shouldPass(1, isPositive); | 321       shouldPass(1, isPositive); | 
| 305     }); | 322     }); | 
| 306 | 323 | 
| 307     test('isNegative', () { | 324     test('isNegative', () { | 
| 308       shouldPass(-1, isNegative); | 325       shouldPass(-1, isNegative); | 
| 309       shouldFail(0, isNegative, | 326       shouldFail(0, isNegative, | 
| 310           "Expected: a negative value but: was <0>."); | 327           "Expected: a negative value But: was <0>."); | 
| 311     }); | 328     }); | 
| 312 | 329 | 
| 313     test('isNonPositive', () { | 330     test('isNonPositive', () { | 
| 314       shouldPass(-1, isNonPositive); | 331       shouldPass(-1, isNonPositive); | 
| 315       shouldPass(0, isNonPositive); | 332       shouldPass(0, isNonPositive); | 
| 316       shouldFail(1, isNonPositive, | 333       shouldFail(1, isNonPositive, | 
| 317           "Expected: a non-positive value but: was <1>."); | 334           "Expected: a non-positive value But: was <1>."); | 
| 318     }); | 335     }); | 
| 319 | 336 | 
| 320     test('isNonNegative', () { | 337     test('isNonNegative', () { | 
| 321       shouldPass(1, isNonNegative); | 338       shouldPass(1, isNonNegative); | 
| 322       shouldPass(0, isNonNegative); | 339       shouldPass(0, isNonNegative); | 
| 323       shouldFail(-1, isNonNegative, | 340       shouldFail(-1, isNonNegative, | 
| 324         "Expected: a non-negative value but: was <-1>."); | 341         "Expected: a non-negative value But: was <-1>."); | 
| 325     }); | 342     }); | 
| 326 | 343 | 
| 327     test('closeTo', () { | 344     test('closeTo', () { | 
| 328       shouldPass(0, closeTo(0, 1)); | 345       shouldPass(0, closeTo(0, 1)); | 
| 329       shouldPass(-1, closeTo(0, 1)); | 346       shouldPass(-1, closeTo(0, 1)); | 
| 330       shouldPass(1, closeTo(0, 1)); | 347       shouldPass(1, closeTo(0, 1)); | 
| 331       shouldFail(1.001, closeTo(0, 1), | 348       shouldFail(1.001, closeTo(0, 1), | 
| 332           "Expected: a numeric value within <1> of <0> " | 349           "Expected: a numeric value within <1> of <0> " | 
| 333           "but: <1.001> differed by <1.001>."); | 350           "But: differed by <1.001>. " | 
|  | 351           "Actual: <1.001>"); | 
| 334       shouldFail(-1.001, closeTo(0, 1), | 352       shouldFail(-1.001, closeTo(0, 1), | 
| 335           "Expected: a numeric value within <1> of <0> " | 353           "Expected: a numeric value within <1> of <0> " | 
| 336           "but: <-1.001> differed by <1.001>."); | 354           "But: differed by <1.001>. " | 
|  | 355           "Actual: <-1.001>"); | 
| 337     }); | 356     }); | 
| 338 | 357 | 
| 339     test('inInclusiveRange', () { | 358     test('inInclusiveRange', () { | 
| 340       shouldFail(-1, inInclusiveRange(0,2), | 359       shouldFail(-1, inInclusiveRange(0,2), | 
| 341           "Expected: be in range from 0 (inclusive) to 2 (inclusive) " | 360           "Expected: be in range from 0 (inclusive) to 2 (inclusive) " | 
| 342           "but: was <-1>."); | 361           "But: was <-1>."); | 
| 343       shouldPass(0, inInclusiveRange(0,2)); | 362       shouldPass(0, inInclusiveRange(0,2)); | 
| 344       shouldPass(1, inInclusiveRange(0,2)); | 363       shouldPass(1, inInclusiveRange(0,2)); | 
| 345       shouldPass(2, inInclusiveRange(0,2)); | 364       shouldPass(2, inInclusiveRange(0,2)); | 
| 346       shouldFail(3, inInclusiveRange(0,2), | 365       shouldFail(3, inInclusiveRange(0,2), | 
| 347           "Expected: be in range from 0 (inclusive) to 2 (inclusive) " | 366           "Expected: be in range from 0 (inclusive) to 2 (inclusive) " | 
| 348           "but: was <3>."); | 367           "But: was <3>."); | 
| 349     }); | 368     }); | 
| 350 | 369 | 
| 351     test('inExclusiveRange', () { | 370     test('inExclusiveRange', () { | 
| 352       shouldFail(0, inExclusiveRange(0,2), | 371       shouldFail(0, inExclusiveRange(0,2), | 
| 353           "Expected: be in range from 0 (exclusive) to 2 (exclusive) " | 372           "Expected: be in range from 0 (exclusive) to 2 (exclusive) " | 
| 354           "but: was <0>."); | 373           "But: was <0>."); | 
| 355       shouldPass(1, inExclusiveRange(0,2)); | 374       shouldPass(1, inExclusiveRange(0,2)); | 
| 356       shouldFail(2, inExclusiveRange(0,2), | 375       shouldFail(2, inExclusiveRange(0,2), | 
| 357           "Expected: be in range from 0 (exclusive) to 2 (exclusive) " | 376           "Expected: be in range from 0 (exclusive) to 2 (exclusive) " | 
| 358           "but: was <2>."); | 377           "But: was <2>."); | 
| 359     }); | 378     }); | 
| 360 | 379 | 
| 361     test('inOpenClosedRange', () { | 380     test('inOpenClosedRange', () { | 
| 362       shouldFail(0, inOpenClosedRange(0,2), | 381       shouldFail(0, inOpenClosedRange(0,2), | 
| 363           "Expected: be in range from 0 (exclusive) to 2 (inclusive) " | 382           "Expected: be in range from 0 (exclusive) to 2 (inclusive) " | 
| 364           "but: was <0>."); | 383           "But: was <0>."); | 
| 365       shouldPass(1, inOpenClosedRange(0,2)); | 384       shouldPass(1, inOpenClosedRange(0,2)); | 
| 366       shouldPass(2, inOpenClosedRange(0,2)); | 385       shouldPass(2, inOpenClosedRange(0,2)); | 
| 367     }); | 386     }); | 
| 368 | 387 | 
| 369     test('inClosedOpenRange', () { | 388     test('inClosedOpenRange', () { | 
| 370       shouldPass(0, inClosedOpenRange(0,2)); | 389       shouldPass(0, inClosedOpenRange(0,2)); | 
| 371       shouldPass(1, inClosedOpenRange(0,2)); | 390       shouldPass(1, inClosedOpenRange(0,2)); | 
| 372       shouldFail(2, inClosedOpenRange(0,2), | 391       shouldFail(2, inClosedOpenRange(0,2), | 
| 373           "Expected: be in range from 0 (inclusive) to 2 (exclusive) " | 392           "Expected: be in range from 0 (inclusive) to 2 (exclusive) " | 
| 374           "but: was <2>."); | 393           "But: was <2>."); | 
| 375     }); | 394     }); | 
| 376   }); | 395   }); | 
| 377 | 396 | 
| 378   group('String Matchers', () { | 397   group('String Matchers', () { | 
| 379 | 398 | 
| 380     test('isEmpty', () { | 399     test('isEmpty', () { | 
| 381       shouldPass('', isEmpty); | 400       shouldPass('', isEmpty); | 
| 382       shouldFail(null, isEmpty, | 401       shouldFail(null, isEmpty, | 
| 383           "Expected: empty but: was <null>."); | 402           "Expected: empty But: was <null>."); | 
| 384       shouldFail(0, isEmpty, | 403       shouldFail(0, isEmpty, | 
| 385           "Expected: empty but: was <0>."); | 404           "Expected: empty But: was <0>."); | 
| 386       shouldFail('a', isEmpty, "Expected: empty but: was 'a'."); | 405       shouldFail('a', isEmpty, "Expected: empty But: was 'a'."); | 
| 387     }); | 406     }); | 
| 388 | 407 | 
| 389     test('equalsIgnoringCase', () { | 408     test('equalsIgnoringCase', () { | 
| 390       shouldPass('hello', equalsIgnoringCase('HELLO')); | 409       shouldPass('hello', equalsIgnoringCase('HELLO')); | 
| 391       shouldFail('hi', equalsIgnoringCase('HELLO'), | 410       shouldFail('hi', equalsIgnoringCase('HELLO'), | 
| 392           "Expected: 'HELLO' ignoring case but: was 'hi'."); | 411           "Expected: 'HELLO' ignoring case But: was 'hi'."); | 
| 393     }); | 412     }); | 
| 394 | 413 | 
| 395     test('equalsIgnoringWhitespace', () { | 414     test('equalsIgnoringWhitespace', () { | 
| 396       shouldPass(' hello   world  ', equalsIgnoringWhitespace('hello world')); | 415       shouldPass(' hello   world  ', equalsIgnoringWhitespace('hello world')); | 
| 397       shouldFail(' helloworld  ', equalsIgnoringWhitespace('hello world'), | 416       shouldFail(' helloworld  ', equalsIgnoringWhitespace('hello world'), | 
| 398           "Expected: 'hello world' ignoring whitespace but: was 'helloworld'."); | 417           "Expected: 'hello world' ignoring whitespace But: was 'helloworld'."); | 
| 399     }); | 418     }); | 
| 400 | 419 | 
| 401     test('startsWith', () { | 420     test('startsWith', () { | 
| 402       shouldPass('hello', startsWith('')); | 421       shouldPass('hello', startsWith('')); | 
| 403       shouldPass('hello', startsWith('hell')); | 422       shouldPass('hello', startsWith('hell')); | 
| 404       shouldPass('hello', startsWith('hello')); | 423       shouldPass('hello', startsWith('hello')); | 
| 405       shouldFail('hello', startsWith('hello '), | 424       shouldFail('hello', startsWith('hello '), | 
| 406           "Expected: a string starting with 'hello ' but: was 'hello'."); | 425           "Expected: a string starting with 'hello ' But: was 'hello'."); | 
| 407     }); | 426     }); | 
| 408 | 427 | 
| 409     test('endsWith', () { | 428     test('endsWith', () { | 
| 410       shouldPass('hello', endsWith('')); | 429       shouldPass('hello', endsWith('')); | 
| 411       shouldPass('hello', endsWith('lo')); | 430       shouldPass('hello', endsWith('lo')); | 
| 412       shouldPass('hello', endsWith('hello')); | 431       shouldPass('hello', endsWith('hello')); | 
| 413       shouldFail('hello', endsWith(' hello'), | 432       shouldFail('hello', endsWith(' hello'), | 
| 414           "Expected: a string ending with ' hello' but: was 'hello'."); | 433           "Expected: a string ending with ' hello' But: was 'hello'."); | 
| 415     }); | 434     }); | 
| 416 | 435 | 
| 417     test('contains', () { | 436     test('contains', () { | 
| 418       shouldPass('hello', contains('')); | 437       shouldPass('hello', contains('')); | 
| 419       shouldPass('hello', contains('h')); | 438       shouldPass('hello', contains('h')); | 
| 420       shouldPass('hello', contains('o')); | 439       shouldPass('hello', contains('o')); | 
| 421       shouldPass('hello', contains('hell')); | 440       shouldPass('hello', contains('hell')); | 
| 422       shouldPass('hello', contains('hello')); | 441       shouldPass('hello', contains('hello')); | 
| 423       shouldFail('hello', contains(' '), | 442       shouldFail('hello', contains(' '), | 
| 424           "Expected: contains ' ' but: was 'hello'."); | 443           "Expected: contains ' ' But: was 'hello'."); | 
| 425     }); | 444     }); | 
| 426 | 445 | 
| 427     test('stringContainsInOrder', () { | 446     test('stringContainsInOrder', () { | 
| 428       shouldPass('goodbye cruel world', stringContainsInOrder([''])); | 447       shouldPass('goodbye cruel world', stringContainsInOrder([''])); | 
| 429       shouldPass('goodbye cruel world', stringContainsInOrder(['goodbye'])); | 448       shouldPass('goodbye cruel world', stringContainsInOrder(['goodbye'])); | 
| 430       shouldPass('goodbye cruel world', stringContainsInOrder(['cruel'])); | 449       shouldPass('goodbye cruel world', stringContainsInOrder(['cruel'])); | 
| 431       shouldPass('goodbye cruel world', stringContainsInOrder(['world'])); | 450       shouldPass('goodbye cruel world', stringContainsInOrder(['world'])); | 
| 432       shouldPass('goodbye cruel world', | 451       shouldPass('goodbye cruel world', | 
| 433                  stringContainsInOrder(['good', 'bye', 'world'])); | 452                  stringContainsInOrder(['good', 'bye', 'world'])); | 
| 434       shouldPass('goodbye cruel world', | 453       shouldPass('goodbye cruel world', | 
| 435                  stringContainsInOrder(['goodbye', 'cruel'])); | 454                  stringContainsInOrder(['goodbye', 'cruel'])); | 
| 436       shouldPass('goodbye cruel world', | 455       shouldPass('goodbye cruel world', | 
| 437                  stringContainsInOrder(['cruel', 'world'])); | 456                  stringContainsInOrder(['cruel', 'world'])); | 
| 438       shouldPass('goodbye cruel world', | 457       shouldPass('goodbye cruel world', | 
| 439         stringContainsInOrder(['goodbye', 'cruel', 'world'])); | 458         stringContainsInOrder(['goodbye', 'cruel', 'world'])); | 
| 440       shouldFail('goodbye cruel world', | 459       shouldFail('goodbye cruel world', | 
| 441         stringContainsInOrder(['goo', 'cruel', 'bye']), | 460         stringContainsInOrder(['goo', 'cruel', 'bye']), | 
| 442         "Expected: a string containing 'goo', 'cruel', 'bye' in order " | 461         "Expected: a string containing 'goo', 'cruel', 'bye' in order " | 
| 443         "but: was 'goodbye cruel world'."); | 462         "But: was 'goodbye cruel world'."); | 
| 444     }); | 463     }); | 
| 445 | 464 | 
| 446     test('matches', () { | 465     test('matches', () { | 
| 447       shouldPass('c0d', matches('[a-z][0-9][a-z]')); | 466       shouldPass('c0d', matches('[a-z][0-9][a-z]')); | 
| 448       shouldPass('c0d', matches(new RegExp('[a-z][0-9][a-z]'))); | 467       shouldPass('c0d', matches(new RegExp('[a-z][0-9][a-z]'))); | 
| 449       shouldFail('cOd', matches('[a-z][0-9][a-z]'), | 468       shouldFail('cOd', matches('[a-z][0-9][a-z]'), | 
| 450           "Expected: match '[a-z][0-9][a-z]' but: was 'cOd'."); | 469           "Expected: match '[a-z][0-9][a-z]' But: was 'cOd'."); | 
| 451     }); | 470     }); | 
| 452   }); | 471   }); | 
| 453 | 472 | 
| 454   group('Iterable Matchers', () { | 473   group('Iterable Matchers', () { | 
| 455     test('isEmpty', () { | 474     test('isEmpty', () { | 
| 456       var d = new SimpleIterable(0); | 475       var d = new SimpleIterable(0); | 
| 457       var e = new SimpleIterable(1); | 476       var e = new SimpleIterable(1); | 
| 458       shouldPass(d, isEmpty); | 477       shouldPass(d, isEmpty); | 
| 459       shouldFail(e, isEmpty, "Expected: empty but: was <[1]>."); | 478       shouldFail(e, isEmpty, "Expected: empty But: was SimpleIterable:[1]."); | 
| 460     }); | 479     }); | 
| 461 | 480 | 
| 462     test('contains', () { | 481     test('contains', () { | 
| 463       var d = new SimpleIterable(3); | 482       var d = new SimpleIterable(3); | 
| 464       shouldPass(d, contains(2)); | 483       shouldPass(d, contains(2)); | 
| 465       shouldFail(d, contains(5), "Expected: contains <5> but: was <[3]>."); | 484       shouldFail(d, contains(5), | 
|  | 485           "Expected: contains <5> " | 
|  | 486           "But: was SimpleIterable:[3, 2, 1]."); | 
| 466     }); | 487     }); | 
| 467   }); | 488   }); | 
| 468 | 489 | 
| 469   group('Iterable Matchers', () { | 490   group('Iterable Matchers', () { | 
| 470 | 491 | 
| 471     test('isEmpty', () { | 492     test('isEmpty', () { | 
| 472       shouldPass([], isEmpty); | 493       shouldPass([], isEmpty); | 
| 473       shouldFail([1], isEmpty, "Expected: empty but: was <[1]>."); | 494       shouldFail([1], isEmpty, "Expected: empty But: was [1]."); | 
| 474     }); | 495     }); | 
| 475 | 496 | 
| 476     test('contains', () { | 497     test('contains', () { | 
| 477       var d = [1, 2]; | 498       var d = [1, 2]; | 
| 478       shouldPass(d, contains(1)); | 499       shouldPass(d, contains(1)); | 
| 479       shouldFail(d, contains(0), "Expected: contains <0> but: was <[1, 2]>."); | 500       shouldFail(d, contains(0), "Expected: contains <0> But: was [1, 2]."); | 
| 480     }); | 501     }); | 
| 481 | 502 | 
| 482     test('isIn', () { | 503     test('isIn', () { | 
| 483       var d = [1, 2]; | 504       var d = [1, 2]; | 
| 484       shouldPass(1, isIn(d)); | 505       shouldPass(1, isIn(d)); | 
| 485       shouldFail(0, isIn(d), "Expected: is in <[1, 2]> but: was <0>."); | 506       shouldFail(0, isIn(d), "Expected: is in [1, 2] But: was <0>."); | 
| 486     }); | 507     }); | 
| 487 | 508 | 
| 488     test('everyElement', () { | 509     test('everyElement', () { | 
| 489       var d = [1, 2]; | 510       var d = [1, 2]; | 
| 490       var e = [1, 1, 1]; | 511       var e = [1, 1, 1]; | 
| 491       shouldFail(d, everyElement(1), | 512       shouldFail(d, everyElement(1), | 
| 492           "Expected: every element <1> but: was <2> at position 1."); | 513           "Expected: every element <1> But: position 1 was <2>. " | 
|  | 514           "Actual: [1, 2]"); | 
| 493       shouldPass(e, everyElement(1)); | 515       shouldPass(e, everyElement(1)); | 
| 494     }); | 516     }); | 
| 495 | 517 | 
| 496     test('someElement', () { | 518     test('someElement', () { | 
| 497       var d = [1, 2]; | 519       var d = [1, 2]; | 
| 498       var e = [1, 1, 1]; | 520       var e = [1, 1, 1]; | 
| 499       shouldPass(d, someElement(2)); | 521       shouldPass(d, someElement(2)); | 
| 500       shouldFail(e, someElement(2), | 522       shouldFail(e, someElement(2), | 
| 501           "Expected: some element <2> but: was <[1, 1, 1]>."); | 523           "Expected: some element <2> But: was [1, 1, 1]."); | 
| 502     }); | 524     }); | 
| 503 | 525 | 
| 504     test('orderedEquals', () { | 526     test('orderedEquals', () { | 
| 505       shouldPass([null], orderedEquals([null])); | 527       shouldPass([null], orderedEquals([null])); | 
| 506       var d = [1, 2]; | 528       var d = [1, 2]; | 
| 507       shouldPass(d, orderedEquals([1, 2])); | 529       shouldPass(d, orderedEquals([1, 2])); | 
| 508       shouldFail(d, orderedEquals([2, 1]), | 530       shouldFail(d, orderedEquals([2, 1]), | 
| 509           "Expected: equals <[2, 1]> ordered " | 531           "Expected: equals [2, 1] ordered " | 
| 510           "but: expected <2> but was <1> mismatch at position 0."); | 532           "But: expected <2> but was <1> mismatch at position 0. " | 
|  | 533           "Actual: [1, 2]"); | 
| 511     }); | 534     }); | 
| 512 | 535 | 
| 513     test('unorderedEquals', () { | 536     test('unorderedEquals', () { | 
| 514       var d = [1, 2]; | 537       var d = [1, 2]; | 
| 515       shouldPass(d, unorderedEquals([2, 1])); | 538       shouldPass(d, unorderedEquals([2, 1])); | 
| 516       shouldFail(d, unorderedEquals([1]), | 539       shouldFail(d, unorderedEquals([1]), | 
| 517           "Expected: equals <[1]> unordered " | 540           "Expected: equals [1] unordered " | 
| 518           "but: has too many elements (2 > 1)."); | 541           "But: has too many elements (2 > 1). " | 
|  | 542           "Actual: [1, 2]"); | 
| 519       shouldFail(d, unorderedEquals([3, 2, 1]), | 543       shouldFail(d, unorderedEquals([3, 2, 1]), | 
| 520           "Expected: equals <[3, 2, 1]> unordered " | 544           "Expected: equals [3, 2, 1] unordered " | 
| 521           "but: has too few elements (2 < 3)."); | 545           "But: has too few elements (2 < 3). " | 
|  | 546           "Actual: [1, 2]"); | 
| 522       shouldFail(d, unorderedEquals([3, 1]), | 547       shouldFail(d, unorderedEquals([3, 1]), | 
| 523           "Expected: equals <[3, 1]> unordered " | 548           "Expected: equals [3, 1] unordered " | 
| 524           "but: has no match for element <3> at position 0."); | 549           "But: has no match for element <3> at position 0. " | 
|  | 550           "Actual: [1, 2]"); | 
| 525     }); | 551     }); | 
| 526 | 552 | 
| 527     test('pairwise compare', () { | 553     test('pairwise compare', () { | 
| 528       var c = [1, 2]; | 554       var c = [1, 2]; | 
| 529       var d = [1, 2, 3]; | 555       var d = [1, 2, 3]; | 
| 530       var e = [1, 4, 9]; | 556       var e = [1, 4, 9]; | 
| 531       shouldFail('x', pairwiseCompare(e, (e,a) => a <= e, | 557       shouldFail('x', pairwiseCompare(e, (e,a) => a <= e, | 
| 532           "less than or equal"), | 558           "less than or equal"), | 
| 533           "Expected: pairwise less than or equal <[1, 4, 9]> but: " | 559           "Expected: pairwise less than or equal [1, 4, 9] " | 
| 534           "not an Iterable."); | 560           "But: not an Iterable. " | 
|  | 561           "Actual: 'x'"); | 
| 535       shouldFail(c, pairwiseCompare(e, (e,a) => a <= e, "less than or equal"), | 562       shouldFail(c, pairwiseCompare(e, (e,a) => a <= e, "less than or equal"), | 
| 536           "Expected: pairwise less than or equal <[1, 4, 9]> but: " | 563           "Expected: pairwise less than or equal [1, 4, 9] " | 
| 537           "length was 2 instead of 3."); | 564           "But: length was 2 instead of 3. " | 
|  | 565           "Actual: [1, 2]"); | 
| 538       shouldPass(d, pairwiseCompare(e, (e,a) => a <= e, "less than or equal")); | 566       shouldPass(d, pairwiseCompare(e, (e,a) => a <= e, "less than or equal")); | 
| 539       shouldFail(d, pairwiseCompare(e, (e,a) => a < e, "less than"), | 567       shouldFail(d, pairwiseCompare(e, (e,a) => a < e, "less than"), | 
| 540           "Expected: pairwise less than <[1, 4, 9]> but: " | 568           "Expected: pairwise less than [1, 4, 9] " | 
| 541           "<1> not less than <1> at position 0."); | 569           "But: <1> not less than <1> at position 0. " | 
|  | 570           "Actual: [1, 2, 3]"); | 
| 542       shouldPass(d, pairwiseCompare(e, (e,a) => a * a == e, "square root of")); | 571       shouldPass(d, pairwiseCompare(e, (e,a) => a * a == e, "square root of")); | 
| 543       shouldFail(d, pairwiseCompare(e, (e,a) => a + a == e, "double"), | 572       shouldFail(d, pairwiseCompare(e, (e,a) => a + a == e, "double"), | 
| 544           "Expected: pairwise double <[1, 4, 9]> but: " | 573           "Expected: pairwise double [1, 4, 9] " | 
| 545           "<1> not double <1> at position 0."); | 574           "But: <1> not double <1> at position 0. " | 
|  | 575           "Actual: [1, 2, 3]"); | 
| 546     }); | 576     }); | 
| 547   }); | 577   }); | 
| 548 | 578 | 
| 549   group('Map Matchers', () { | 579   group('Map Matchers', () { | 
| 550 | 580 | 
| 551     test('isEmpty', () { | 581     test('isEmpty', () { | 
| 552       var a = new Map(); | 582       var a = new Map(); | 
| 553       shouldPass({}, isEmpty); | 583       shouldPass({}, isEmpty); | 
| 554       shouldPass(a, isEmpty); | 584       shouldPass(a, isEmpty); | 
| 555       a['foo'] = 'bar'; | 585       a['foo'] = 'bar'; | 
| 556       shouldFail(a, isEmpty, "Expected: empty but: was <{foo: bar}>."); | 586       shouldFail(a, isEmpty, "Expected: empty But: was {'foo': 'bar'}."); | 
| 557     }); | 587     }); | 
| 558 | 588 | 
| 559     test('equals', () { | 589     test('equals', () { | 
| 560       var a = new Map(); | 590       var a = new Map(); | 
| 561       a['foo'] = 'bar'; | 591       a['foo'] = 'bar'; | 
| 562       var b = new Map(); | 592       var b = new Map(); | 
| 563       b['foo'] = 'bar'; | 593       b['foo'] = 'bar'; | 
| 564       var c = new Map(); | 594       var c = new Map(); | 
| 565       c['bar'] = 'foo'; | 595       c['bar'] = 'foo'; | 
| 566       shouldPass(a, equals(b)); | 596       shouldPass(a, equals(b)); | 
| 567       shouldFail(b, equals(c), | 597       shouldFail(b, equals(c), | 
| 568           "Expected: <{bar: foo}> but: missing map key 'bar'."); | 598           "Expected: {'bar': 'foo'} But: missing map key 'bar'. " | 
|  | 599           "Actual: {'foo': 'bar'}"); | 
| 569     }); | 600     }); | 
| 570 | 601 | 
| 571     test('equals with different lengths', () { | 602     test('equals with different lengths', () { | 
| 572       var a = new LinkedHashMap(); | 603       var a = new LinkedHashMap(); | 
| 573       a['foo'] = 'bar'; | 604       a['foo'] = 'bar'; | 
| 574       var b = new LinkedHashMap(); | 605       var b = new LinkedHashMap(); | 
| 575       b['foo'] = 'bar'; | 606       b['foo'] = 'bar'; | 
| 576       b['bar'] = 'foo'; | 607       b['bar'] = 'foo'; | 
| 577       var c = new LinkedHashMap(); | 608       var c = new LinkedHashMap(); | 
| 578       c['bar'] = 'foo'; | 609       c['bar'] = 'foo'; | 
| 579       c['barrista'] = 'caffeine'; | 610       c['barrista'] = 'caffeine'; | 
| 580       shouldFail(a, equals(b), | 611       shouldFail(a, equals(b), | 
| 581           "Expected: <{foo: bar, bar: foo}> " | 612           "Expected: {'foo': 'bar', 'bar': 'foo'} " | 
| 582           "but: different map lengths; missing map key 'bar'."); | 613           "But: different map lengths; missing map key 'bar'. " | 
|  | 614           "Actual: {'foo': 'bar'}"); | 
| 583       shouldFail(b, equals(a), | 615       shouldFail(b, equals(a), | 
| 584           "Expected: <{foo: bar}> " | 616           "Expected: {'foo': 'bar'} " | 
| 585           "but: different map lengths; extra map key 'bar'."); | 617           "But: different map lengths; extra map key 'bar'. " | 
|  | 618           "Actual: {'foo': 'bar', 'bar': 'foo'}"); | 
| 586       shouldFail(b, equals(c), | 619       shouldFail(b, equals(c), | 
| 587           "Expected: <{bar: foo, barrista: caffeine}> " | 620           "Expected: {'bar': 'foo', 'barrista': 'caffeine'} " | 
| 588           "but: missing map key 'barrista'."); | 621           "But: missing map key 'barrista'. " | 
|  | 622           "Actual: {'foo': 'bar', 'bar': 'foo'}"); | 
| 589       shouldFail(c, equals(b), | 623       shouldFail(c, equals(b), | 
| 590           "Expected: <{foo: bar, bar: foo}> " | 624           "Expected: {'foo': 'bar', 'bar': 'foo'} " | 
| 591           "but: missing map key 'foo'."); | 625           "But: missing map key 'foo'. " | 
|  | 626           "Actual: {'bar': 'foo', 'barrista': 'caffeine'}"); | 
| 592       shouldFail(a, equals(c), | 627       shouldFail(a, equals(c), | 
| 593           "Expected: <{bar: foo, barrista: caffeine}> " | 628           "Expected: {'bar': 'foo', 'barrista': 'caffeine'} " | 
| 594           "but: different map lengths; missing map key 'bar'."); | 629           "But: different map lengths; missing map key 'bar'. " | 
|  | 630           "Actual: {'foo': 'bar'}"); | 
| 595       shouldFail(c, equals(a), | 631       shouldFail(c, equals(a), | 
| 596           "Expected: <{foo: bar}> " | 632           "Expected: {'foo': 'bar'} " | 
| 597           "but: different map lengths; missing map key 'foo'."); | 633           "But: different map lengths; missing map key 'foo'. " | 
|  | 634           "Actual: {'bar': 'foo', 'barrista': 'caffeine'}"); | 
| 598     }); | 635     }); | 
| 599 | 636 | 
| 600     test('contains', () { | 637     test('contains', () { | 
| 601       var a = new Map(); | 638       var a = new Map(); | 
| 602       a['foo'] = 'bar'; | 639       a['foo'] = 'bar'; | 
| 603       var b = new Map(); | 640       var b = new Map(); | 
| 604       shouldPass(a, contains('foo')); | 641       shouldPass(a, contains('foo')); | 
| 605       shouldFail(b, contains('foo'), | 642       shouldFail(b, contains('foo'), | 
| 606           "Expected: contains 'foo' but: was <{}>."); | 643           "Expected: contains 'foo' But: was {}."); | 
| 607       shouldFail(10, contains('foo'), | 644       shouldFail(10, contains('foo'), | 
| 608           "Expected: contains 'foo' but: was <10>."); | 645           "Expected: contains 'foo' But: was <10>."); | 
| 609     }); | 646     }); | 
| 610 | 647 | 
| 611     test('containsValue', () { | 648     test('containsValue', () { | 
| 612       var a = new Map(); | 649       var a = new Map(); | 
| 613       a['foo'] = 'bar'; | 650       a['foo'] = 'bar'; | 
| 614       shouldPass(a, containsValue('bar')); | 651       shouldPass(a, containsValue('bar')); | 
| 615       shouldFail(a, containsValue('ba'), | 652       shouldFail(a, containsValue('ba'), | 
| 616           "Expected: contains value 'ba' but: was <{foo: bar}>."); | 653           "Expected: contains value 'ba' But: was {'foo': 'bar'}."); | 
| 617     }); | 654     }); | 
| 618 | 655 | 
| 619     test('containsPair', () { | 656     test('containsPair', () { | 
| 620       var a = new Map(); | 657       var a = new Map(); | 
| 621       a['foo'] = 'bar'; | 658       a['foo'] = 'bar'; | 
| 622       shouldPass(a, containsPair('foo', 'bar')); | 659       shouldPass(a, containsPair('foo', 'bar')); | 
| 623       shouldFail(a, containsPair('foo', 'ba'), | 660       shouldFail(a, containsPair('foo', 'ba'), | 
| 624           "Expected: contains pair 'foo' => 'ba' " | 661           "Expected: contains pair 'foo' => 'ba' " | 
| 625           "but:  contains key 'foo' but with value was 'bar'."); | 662           "But:  contains key 'foo' but with value was 'bar'. " | 
|  | 663           "Actual: {'foo': 'bar'}"); | 
| 626       shouldFail(a, containsPair('fo', 'bar'), | 664       shouldFail(a, containsPair('fo', 'bar'), | 
| 627           "Expected: contains pair 'fo' => 'bar' " | 665           "Expected: contains pair 'fo' => 'bar' " | 
| 628           "but: <{foo: bar}> doesn't contain key 'fo'."); | 666           "But: doesn't contain key 'fo'. " | 
|  | 667           "Actual: {'foo': 'bar'}"); | 
| 629     }); | 668     }); | 
| 630 | 669 | 
| 631     test('hasLength', () { | 670     test('hasLength', () { | 
| 632       var a = new Map(); | 671       var a = new Map(); | 
| 633       a['foo'] = 'bar'; | 672       a['foo'] = 'bar'; | 
| 634       var b = new Map(); | 673       var b = new Map(); | 
| 635       shouldPass(a, hasLength(1)); | 674       shouldPass(a, hasLength(1)); | 
| 636       shouldFail(b, hasLength(1), | 675       shouldFail(b, hasLength(1), | 
| 637           "Expected: an object with length of <1> " | 676           "Expected: an object with length of <1> " | 
| 638           "but: was <{}> with length of <0>."); | 677           "But: had length of <0>. " | 
|  | 678           "Actual: {}"); | 
| 639     }); | 679     }); | 
| 640   }); | 680   }); | 
| 641 | 681 | 
| 642   group('Operator Matchers', () { | 682   group('Operator Matchers', () { | 
| 643 | 683 | 
| 644     test('anyOf', () { | 684     test('anyOf', () { | 
| 645       shouldFail(0, anyOf([equals(1), equals(2)]), | 685       shouldFail(0, anyOf([equals(1), equals(2)]), | 
| 646           "Expected: (<1> or <2>) but: was <0>."); | 686           "Expected: (<1> or <2>) But: was <0>."); | 
| 647       shouldPass(1, anyOf([equals(1), equals(2)])); | 687       shouldPass(1, anyOf([equals(1), equals(2)])); | 
| 648     }); | 688     }); | 
| 649 | 689 | 
| 650     test('allOf', () { | 690     test('allOf', () { | 
| 651       shouldPass(1, allOf([lessThan(10), greaterThan(0)])); | 691       shouldPass(1, allOf([lessThan(10), greaterThan(0)])); | 
| 652       shouldFail(-1, allOf([lessThan(10), greaterThan(0)]), | 692       shouldFail(-1, allOf([lessThan(10), greaterThan(0)]), | 
| 653           "Expected: (a value less than <10> and a value greater than <0>) " | 693           "Expected: (a value less than <10> and a value greater than <0>) " | 
| 654           "but: a value greater than <0> was <-1>."); | 694           "But: was <-1> (wasn't a value greater than <0>)."); | 
| 655     }); | 695     }); | 
| 656   }); | 696   }); | 
| 657 | 697 | 
| 658   group('Future Matchers', () { | 698   group('Future Matchers', () { | 
| 659 | 699 | 
| 660     test('completes - unexpected error', () { | 700     test('completes - unexpected error', () { | 
| 661       var completer = new Completer(); | 701       var completer = new Completer(); | 
| 662       completer.completeError('X'); | 702       completer.completeError('X'); | 
| 663       shouldFail(completer.future, completes, | 703       shouldFail(completer.future, completes, | 
| 664           contains('Expected future to complete successfully, ' | 704           contains('Expected future to complete successfully, ' | 
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 704     test('throwsA - correct error', () { | 744     test('throwsA - correct error', () { | 
| 705       var completer = new Completer(); | 745       var completer = new Completer(); | 
| 706       completer.completeError('X'); | 746       completer.completeError('X'); | 
| 707       shouldPass(completer.future, throwsA(equals('X')), isAsync: true); | 747       shouldPass(completer.future, throwsA(equals('X')), isAsync: true); | 
| 708     }); | 748     }); | 
| 709 | 749 | 
| 710     test('throwsA - wrong error', () { | 750     test('throwsA - wrong error', () { | 
| 711       var completer = new Completer(); | 751       var completer = new Completer(); | 
| 712       completer.completeError('X'); | 752       completer.completeError('X'); | 
| 713       shouldFail(completer.future, throwsA(equals('Y')), | 753       shouldFail(completer.future, throwsA(equals('Y')), | 
| 714           "Expected: 'Y' but: was 'X'.", | 754           "Expected: 'Y' But: was 'X'.", | 
| 715           isAsync: true); | 755           isAsync: true); | 
| 716     }); | 756     }); | 
| 717   }); | 757   }); | 
| 718 | 758 | 
| 719   group('Predicate Matchers', () { | 759   group('Predicate Matchers', () { | 
| 720     test('isInstanceOf', () { | 760     test('isInstanceOf', () { | 
| 721       shouldFail(0, predicate((x) => x is String, "an instance of String"), | 761       shouldFail(0, predicate((x) => x is String, "an instance of String"), | 
| 722           "Expected: an instance of String but: was <0>."); | 762           "Expected: an instance of String But: was <0>."); | 
| 723       shouldPass('cow', predicate((x) => x is String, "an instance of String")); | 763       shouldPass('cow', predicate((x) => x is String, "an instance of String")); | 
| 724     }); | 764     }); | 
| 725   }); | 765   }); | 
| 726 | 766 | 
| 727   group('Feature Matchers', () { | 767   group('Feature Matchers', () { | 
| 728     test("Feature Matcher", () { | 768     test("Feature Matcher", () { | 
| 729       var w = new Widget(); | 769       var w = new Widget(); | 
| 730       w.price = 10; | 770       w.price = 10; | 
| 731       shouldPass(w, new HasPrice(10)); | 771       shouldPass(w, new HasPrice(10)); | 
| 732       shouldPass(w, new HasPrice(greaterThan(0))); | 772       shouldPass(w, new HasPrice(greaterThan(0))); | 
| 733       shouldFail(w, new HasPrice(greaterThan(10)), | 773       shouldFail(w, new HasPrice(greaterThan(10)), | 
| 734           'Expected: Widget with a price that is a value greater than <10> ' | 774           "Expected: Widget with a price that is a value greater than <10> " | 
| 735           'but: price was <10>.'); | 775           "But: price was <10>. " | 
|  | 776           "Actual: <Instance of 'Widget'>"); | 
| 736     }); | 777     }); | 
| 737   }); | 778   }); | 
| 738 } | 779 } | 
| 739 | 780 | 
| OLD | NEW | 
|---|