Chromium Code Reviews| 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 <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 <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 <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 <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 <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 <Exception> does not match " |
|
gram
2013/05/17 01:00:30
I think now that we have Expected and Actual both
nweiz
2013/05/17 19:50:56
Done.
| |
| 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 <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 }); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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), |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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: was <2> at position 1."); |
| 493 shouldPass(e, everyElement(1)); | 514 shouldPass(e, everyElement(1)); |
| 494 }); | 515 }); |
| 495 | 516 |
| 496 test('someElement', () { | 517 test('someElement', () { |
| 497 var d = [1, 2]; | 518 var d = [1, 2]; |
| 498 var e = [1, 1, 1]; | 519 var e = [1, 1, 1]; |
| 499 shouldPass(d, someElement(2)); | 520 shouldPass(d, someElement(2)); |
| 500 shouldFail(e, someElement(2), | 521 shouldFail(e, someElement(2), |
| 501 "Expected: some element <2> but: was <[1, 1, 1]>."); | 522 "Expected: some element <2> but: was [1, 1, 1]."); |
| 502 }); | 523 }); |
| 503 | 524 |
| 504 test('orderedEquals', () { | 525 test('orderedEquals', () { |
| 505 shouldPass([null], orderedEquals([null])); | 526 shouldPass([null], orderedEquals([null])); |
| 506 var d = [1, 2]; | 527 var d = [1, 2]; |
| 507 shouldPass(d, orderedEquals([1, 2])); | 528 shouldPass(d, orderedEquals([1, 2])); |
| 508 shouldFail(d, orderedEquals([2, 1]), | 529 shouldFail(d, orderedEquals([2, 1]), |
| 509 "Expected: equals <[2, 1]> ordered " | 530 "Expected: equals [2, 1] ordered " |
| 510 "but: expected <2> but was <1> mismatch at position 0."); | 531 "but: expected <2> but was <1> mismatch at position 0. " |
| 532 "Actual: [1, 2]"); | |
| 511 }); | 533 }); |
| 512 | 534 |
| 513 test('unorderedEquals', () { | 535 test('unorderedEquals', () { |
| 514 var d = [1, 2]; | 536 var d = [1, 2]; |
| 515 shouldPass(d, unorderedEquals([2, 1])); | 537 shouldPass(d, unorderedEquals([2, 1])); |
| 516 shouldFail(d, unorderedEquals([1]), | 538 shouldFail(d, unorderedEquals([1]), |
| 517 "Expected: equals <[1]> unordered " | 539 "Expected: equals [1] unordered " |
| 518 "but: has too many elements (2 > 1)."); | 540 "but: has too many elements (2 > 1). " |
| 541 "Actual: [1, 2]"); | |
| 519 shouldFail(d, unorderedEquals([3, 2, 1]), | 542 shouldFail(d, unorderedEquals([3, 2, 1]), |
| 520 "Expected: equals <[3, 2, 1]> unordered " | 543 "Expected: equals [3, 2, 1] unordered " |
| 521 "but: has too few elements (2 < 3)."); | 544 "but: has too few elements (2 < 3). " |
| 545 "Actual: [1, 2]"); | |
| 522 shouldFail(d, unorderedEquals([3, 1]), | 546 shouldFail(d, unorderedEquals([3, 1]), |
| 523 "Expected: equals <[3, 1]> unordered " | 547 "Expected: equals [3, 1] unordered " |
| 524 "but: has no match for element <3> at position 0."); | 548 "but: has no match for element <3> at position 0. " |
| 549 "Actual: [1, 2]"); | |
| 525 }); | 550 }); |
| 526 | 551 |
| 527 test('pairwise compare', () { | 552 test('pairwise compare', () { |
| 528 var c = [1, 2]; | 553 var c = [1, 2]; |
| 529 var d = [1, 2, 3]; | 554 var d = [1, 2, 3]; |
| 530 var e = [1, 4, 9]; | 555 var e = [1, 4, 9]; |
| 531 shouldFail('x', pairwiseCompare(e, (e,a) => a <= e, | 556 shouldFail('x', pairwiseCompare(e, (e,a) => a <= e, |
| 532 "less than or equal"), | 557 "less than or equal"), |
| 533 "Expected: pairwise less than or equal <[1, 4, 9]> but: " | 558 "Expected: pairwise less than or equal [1, 4, 9] " |
| 534 "not an Iterable."); | 559 "but: not an Iterable. " |
| 560 "Actual: 'x'"); | |
| 535 shouldFail(c, pairwiseCompare(e, (e,a) => a <= e, "less than or equal"), | 561 shouldFail(c, pairwiseCompare(e, (e,a) => a <= e, "less than or equal"), |
| 536 "Expected: pairwise less than or equal <[1, 4, 9]> but: " | 562 "Expected: pairwise less than or equal [1, 4, 9] " |
| 537 "length was 2 instead of 3."); | 563 "but: length was 2 instead of 3. " |
| 564 "Actual: [1, 2]"); | |
| 538 shouldPass(d, pairwiseCompare(e, (e,a) => a <= e, "less than or equal")); | 565 shouldPass(d, pairwiseCompare(e, (e,a) => a <= e, "less than or equal")); |
| 539 shouldFail(d, pairwiseCompare(e, (e,a) => a < e, "less than"), | 566 shouldFail(d, pairwiseCompare(e, (e,a) => a < e, "less than"), |
| 540 "Expected: pairwise less than <[1, 4, 9]> but: " | 567 "Expected: pairwise less than [1, 4, 9] " |
| 541 "<1> not less than <1> at position 0."); | 568 "but: <1> not less than <1> at position 0. " |
| 569 "Actual: [1, 2, 3]"); | |
| 542 shouldPass(d, pairwiseCompare(e, (e,a) => a * a == e, "square root of")); | 570 shouldPass(d, pairwiseCompare(e, (e,a) => a * a == e, "square root of")); |
| 543 shouldFail(d, pairwiseCompare(e, (e,a) => a + a == e, "double"), | 571 shouldFail(d, pairwiseCompare(e, (e,a) => a + a == e, "double"), |
| 544 "Expected: pairwise double <[1, 4, 9]> but: " | 572 "Expected: pairwise double [1, 4, 9] " |
| 545 "<1> not double <1> at position 0."); | 573 "but: <1> not double <1> at position 0. " |
| 574 "Actual: [1, 2, 3]"); | |
| 546 }); | 575 }); |
| 547 }); | 576 }); |
| 548 | 577 |
| 549 group('Map Matchers', () { | 578 group('Map Matchers', () { |
| 550 | 579 |
| 551 test('isEmpty', () { | 580 test('isEmpty', () { |
| 552 var a = new Map(); | 581 var a = new Map(); |
| 553 shouldPass({}, isEmpty); | 582 shouldPass({}, isEmpty); |
| 554 shouldPass(a, isEmpty); | 583 shouldPass(a, isEmpty); |
| 555 a['foo'] = 'bar'; | 584 a['foo'] = 'bar'; |
| 556 shouldFail(a, isEmpty, "Expected: empty but: was <{foo: bar}>."); | 585 shouldFail(a, isEmpty, "Expected: empty but: was {'foo': 'bar'}."); |
| 557 }); | 586 }); |
| 558 | 587 |
| 559 test('equals', () { | 588 test('equals', () { |
| 560 var a = new Map(); | 589 var a = new Map(); |
| 561 a['foo'] = 'bar'; | 590 a['foo'] = 'bar'; |
| 562 var b = new Map(); | 591 var b = new Map(); |
| 563 b['foo'] = 'bar'; | 592 b['foo'] = 'bar'; |
| 564 var c = new Map(); | 593 var c = new Map(); |
| 565 c['bar'] = 'foo'; | 594 c['bar'] = 'foo'; |
| 566 shouldPass(a, equals(b)); | 595 shouldPass(a, equals(b)); |
| 567 shouldFail(b, equals(c), | 596 shouldFail(b, equals(c), |
| 568 "Expected: <{bar: foo}> but: missing map key 'bar'."); | 597 "Expected: {'bar': 'foo'} but: missing map key 'bar'. " |
| 598 "Actual: {'foo': 'bar'}"); | |
| 569 }); | 599 }); |
| 570 | 600 |
| 571 test('equals with different lengths', () { | 601 test('equals with different lengths', () { |
| 572 var a = new LinkedHashMap(); | 602 var a = new LinkedHashMap(); |
| 573 a['foo'] = 'bar'; | 603 a['foo'] = 'bar'; |
| 574 var b = new LinkedHashMap(); | 604 var b = new LinkedHashMap(); |
| 575 b['foo'] = 'bar'; | 605 b['foo'] = 'bar'; |
| 576 b['bar'] = 'foo'; | 606 b['bar'] = 'foo'; |
| 577 var c = new LinkedHashMap(); | 607 var c = new LinkedHashMap(); |
| 578 c['bar'] = 'foo'; | 608 c['bar'] = 'foo'; |
| 579 c['barrista'] = 'caffeine'; | 609 c['barrista'] = 'caffeine'; |
| 580 shouldFail(a, equals(b), | 610 shouldFail(a, equals(b), |
| 581 "Expected: <{foo: bar, bar: foo}> " | 611 "Expected: {'foo': 'bar', 'bar': 'foo'} " |
| 582 "but: different map lengths; missing map key 'bar'."); | 612 "but: different map lengths; missing map key 'bar'. " |
| 613 "Actual: {'foo': 'bar'}"); | |
| 583 shouldFail(b, equals(a), | 614 shouldFail(b, equals(a), |
| 584 "Expected: <{foo: bar}> " | 615 "Expected: {'foo': 'bar'} " |
| 585 "but: different map lengths; extra map key 'bar'."); | 616 "but: different map lengths; extra map key 'bar'. " |
| 617 "Actual: {'foo': 'bar', 'bar': 'foo'}"); | |
| 586 shouldFail(b, equals(c), | 618 shouldFail(b, equals(c), |
| 587 "Expected: <{bar: foo, barrista: caffeine}> " | 619 "Expected: {'bar': 'foo', 'barrista': 'caffeine'} " |
| 588 "but: missing map key 'barrista'."); | 620 "but: missing map key 'barrista'. " |
| 621 "Actual: {'foo': 'bar', 'bar': 'foo'}"); | |
| 589 shouldFail(c, equals(b), | 622 shouldFail(c, equals(b), |
| 590 "Expected: <{foo: bar, bar: foo}> " | 623 "Expected: {'foo': 'bar', 'bar': 'foo'} " |
| 591 "but: missing map key 'foo'."); | 624 "but: missing map key 'foo'. " |
| 625 "Actual: {'bar': 'foo', 'barrista': 'caffeine'}"); | |
| 592 shouldFail(a, equals(c), | 626 shouldFail(a, equals(c), |
| 593 "Expected: <{bar: foo, barrista: caffeine}> " | 627 "Expected: {'bar': 'foo', 'barrista': 'caffeine'} " |
| 594 "but: different map lengths; missing map key 'bar'."); | 628 "but: different map lengths; missing map key 'bar'. " |
| 629 "Actual: {'foo': 'bar'}"); | |
| 595 shouldFail(c, equals(a), | 630 shouldFail(c, equals(a), |
| 596 "Expected: <{foo: bar}> " | 631 "Expected: {'foo': 'bar'} " |
| 597 "but: different map lengths; missing map key 'foo'."); | 632 "but: different map lengths; missing map key 'foo'. " |
| 633 "Actual: {'bar': 'foo', 'barrista': 'caffeine'}"); | |
| 598 }); | 634 }); |
| 599 | 635 |
| 600 test('contains', () { | 636 test('contains', () { |
| 601 var a = new Map(); | 637 var a = new Map(); |
| 602 a['foo'] = 'bar'; | 638 a['foo'] = 'bar'; |
| 603 var b = new Map(); | 639 var b = new Map(); |
| 604 shouldPass(a, contains('foo')); | 640 shouldPass(a, contains('foo')); |
| 605 shouldFail(b, contains('foo'), | 641 shouldFail(b, contains('foo'), |
| 606 "Expected: contains 'foo' but: was <{}>."); | 642 "Expected: contains 'foo' but: was {}."); |
| 607 shouldFail(10, contains('foo'), | 643 shouldFail(10, contains('foo'), |
| 608 "Expected: contains 'foo' but: was <10>."); | 644 "Expected: contains 'foo' but: was <10>."); |
| 609 }); | 645 }); |
| 610 | 646 |
| 611 test('containsValue', () { | 647 test('containsValue', () { |
| 612 var a = new Map(); | 648 var a = new Map(); |
| 613 a['foo'] = 'bar'; | 649 a['foo'] = 'bar'; |
| 614 shouldPass(a, containsValue('bar')); | 650 shouldPass(a, containsValue('bar')); |
| 615 shouldFail(a, containsValue('ba'), | 651 shouldFail(a, containsValue('ba'), |
| 616 "Expected: contains value 'ba' but: was <{foo: bar}>."); | 652 "Expected: contains value 'ba' but: was {'foo': 'bar'}."); |
| 617 }); | 653 }); |
|
gram
2013/05/17 01:00:30
You seem to have established a new pattern for out
nweiz
2013/05/17 19:50:56
It seems weird to me when the "But" clause would j
gram
2013/05/17 20:38:32
I agree with you that it could be weird, but havin
nweiz
2013/05/17 21:07:21
I think there's room to improve and normalize thes
| |
| 618 | 654 |
| 619 test('containsPair', () { | 655 test('containsPair', () { |
| 620 var a = new Map(); | 656 var a = new Map(); |
| 621 a['foo'] = 'bar'; | 657 a['foo'] = 'bar'; |
| 622 shouldPass(a, containsPair('foo', 'bar')); | 658 shouldPass(a, containsPair('foo', 'bar')); |
| 623 shouldFail(a, containsPair('foo', 'ba'), | 659 shouldFail(a, containsPair('foo', 'ba'), |
| 624 "Expected: contains pair 'foo' => 'ba' " | 660 "Expected: contains pair 'foo' => 'ba' " |
| 625 "but: contains key 'foo' but with value was 'bar'."); | 661 "but: contains key 'foo' but with value was 'bar'. " |
| 662 "Actual: {'foo': 'bar'}"); | |
| 626 shouldFail(a, containsPair('fo', 'bar'), | 663 shouldFail(a, containsPair('fo', 'bar'), |
| 627 "Expected: contains pair 'fo' => 'bar' " | 664 "Expected: contains pair 'fo' => 'bar' " |
| 628 "but: <{foo: bar}> doesn't contain key 'fo'."); | 665 "but: doesn't contain key 'fo'. " |
| 666 "Actual: {'foo': 'bar'}"); | |
| 629 }); | 667 }); |
| 630 | 668 |
| 631 test('hasLength', () { | 669 test('hasLength', () { |
| 632 var a = new Map(); | 670 var a = new Map(); |
| 633 a['foo'] = 'bar'; | 671 a['foo'] = 'bar'; |
| 634 var b = new Map(); | 672 var b = new Map(); |
| 635 shouldPass(a, hasLength(1)); | 673 shouldPass(a, hasLength(1)); |
| 636 shouldFail(b, hasLength(1), | 674 shouldFail(b, hasLength(1), |
| 637 "Expected: an object with length of <1> " | 675 "Expected: an object with length of <1> " |
| 638 "but: was <{}> with length of <0>."); | 676 "but: had length of <0>. " |
| 677 "Actual: {}"); | |
| 639 }); | 678 }); |
| 640 }); | 679 }); |
| 641 | 680 |
| 642 group('Operator Matchers', () { | 681 group('Operator Matchers', () { |
| 643 | 682 |
| 644 test('anyOf', () { | 683 test('anyOf', () { |
| 645 shouldFail(0, anyOf([equals(1), equals(2)]), | 684 shouldFail(0, anyOf([equals(1), equals(2)]), |
| 646 "Expected: (<1> or <2>) but: was <0>."); | 685 "Expected: (<1> or <2>) but: was <0>."); |
| 647 shouldPass(1, anyOf([equals(1), equals(2)])); | 686 shouldPass(1, anyOf([equals(1), equals(2)])); |
| 648 }); | 687 }); |
| 649 | 688 |
| 650 test('allOf', () { | 689 test('allOf', () { |
| 651 shouldPass(1, allOf([lessThan(10), greaterThan(0)])); | 690 shouldPass(1, allOf([lessThan(10), greaterThan(0)])); |
| 652 shouldFail(-1, allOf([lessThan(10), greaterThan(0)]), | 691 shouldFail(-1, allOf([lessThan(10), greaterThan(0)]), |
| 653 "Expected: (a value less than <10> and a value greater than <0>) " | 692 "Expected: (a value less than <10> and a value greater than <0>) " |
| 654 "but: a value greater than <0> was <-1>."); | 693 "but: was <-1> (a value greater than <0>)."); |
|
gram
2013/05/17 01:00:30
Another inconsistent case.
nweiz
2013/05/17 19:50:56
This case is weird. If all of the uses of [allOf]
| |
| 655 }); | 694 }); |
| 656 }); | 695 }); |
| 657 | 696 |
| 658 group('Future Matchers', () { | 697 group('Future Matchers', () { |
| 659 | 698 |
| 660 test('completes - unexpected error', () { | 699 test('completes - unexpected error', () { |
| 661 var completer = new Completer(); | 700 var completer = new Completer(); |
| 662 completer.completeError('X'); | 701 completer.completeError('X'); |
| 663 shouldFail(completer.future, completes, | 702 shouldFail(completer.future, completes, |
| 664 contains('Expected future to complete successfully, ' | 703 contains('Expected future to complete successfully, ' |
| 665 'but it failed with X'), | 704 'but it failed with X'), |
| 666 isAsync: true); | 705 isAsync: true); |
|
gram
2013/05/17 01:00:30
Inconsistent pattern here and more below
nweiz
2013/05/17 19:50:56
I think the future matchers just work completely d
| |
| 667 }); | 706 }); |
| 668 | 707 |
| 669 test('completes - successfully', () { | 708 test('completes - successfully', () { |
| 670 var completer = new Completer(); | 709 var completer = new Completer(); |
| 671 completer.complete('1'); | 710 completer.complete('1'); |
| 672 shouldPass(completer.future, completes, isAsync: true); | 711 shouldPass(completer.future, completes, isAsync: true); |
| 673 }); | 712 }); |
| 674 | 713 |
| 675 test('throws - unexpected to see normal completion', () { | 714 test('throws - unexpected to see normal completion', () { |
| 676 var completer = new Completer(); | 715 var completer = new Completer(); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 724 }); | 763 }); |
| 725 }); | 764 }); |
| 726 | 765 |
| 727 group('Feature Matchers', () { | 766 group('Feature Matchers', () { |
| 728 test("Feature Matcher", () { | 767 test("Feature Matcher", () { |
| 729 var w = new Widget(); | 768 var w = new Widget(); |
| 730 w.price = 10; | 769 w.price = 10; |
| 731 shouldPass(w, new HasPrice(10)); | 770 shouldPass(w, new HasPrice(10)); |
| 732 shouldPass(w, new HasPrice(greaterThan(0))); | 771 shouldPass(w, new HasPrice(greaterThan(0))); |
| 733 shouldFail(w, new HasPrice(greaterThan(10)), | 772 shouldFail(w, new HasPrice(greaterThan(10)), |
| 734 'Expected: Widget with a price that is a value greater than <10> ' | 773 "Expected: Widget with a price that is a value greater than <10> " |
| 735 'but: price was <10>.'); | 774 "but: price was <10>. " |
| 775 "Actual: <Instance of 'Widget'>"); | |
| 736 }); | 776 }); |
| 737 }); | 777 }); |
| 738 } | 778 } |
| 739 | 779 |
| OLD | NEW |