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 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 230 "Expected: an object with length of <2> " | 230 "Expected: an object with length of <2> " |
| 231 "but: was <[0]> with length of <1>."); | 231 "but: was <[0]> with length of <1>."); |
| 232 | 232 |
| 233 b.add(0); | 233 b.add(0); |
| 234 shouldFail(b, hasLength(1), | 234 shouldFail(b, hasLength(1), |
| 235 "Expected: an object with length of <1> " | 235 "Expected: an object with length of <1> " |
| 236 "but: was <[0, 0]> with length of <2>."); | 236 "but: was <[0, 0]> with length of <2>."); |
| 237 shouldPass(b, hasLength(2)); | 237 shouldPass(b, hasLength(2)); |
| 238 }); | 238 }); |
| 239 | 239 |
| 240 test('type mismatch', () { | 240 test('scalar type mismatch', () { |
| 241 var a = new DateTime.utc(2000); | 241 shouldFail('error', equals(5.0), |
| 242 var b = a.toString(); | 242 matches("^Expected: <5\.0>" |
| 243 // We should get something like: | 243 " but: was .*:'error' \\(not type .*\\)\.\$")); |
|
Siggi Cherem (dart-lang)
2013/04/19 17:18:24
now that is shorter, can we spell it out here?
"
| |
| 244 // Expected: '2000-01-01 00:00:00.000Z' | 244 }); |
| 245 // but: expected String:'2000-01-01 00:00:00.000Z' | 245 |
| 246 // but was DateTime:<2000-01-01 00:00:00.000Z>. | 246 test('nested type mismatch', () { |
| 247 // However, if minification is applied, then the type names | 247 shouldFail(['error'], equals([5.0]), |
| 248 // will be shortened to two letters. The key thing is that | 248 matches(r"^Expected: <\[5\.0\]>" |
| 249 // there will be a "but: expected" part in the middle; | 249 " but: expected double:<5\.0> " |
| 250 // this only happens with type mismatches or mismatches | 250 "but was .*:'error' mismatch at position 0\.\$")); |
| 251 // inside container types. | 251 }); |
| 252 shouldFail(a, equals(b), | 252 |
| 253 matches(new RegExp("^Expected.*but: expected .*but was.*\$"))); | 253 test('doubly-nested type mismatch', () { |
| 254 shouldFail([['error']], equals([[5.0]]), | |
| 255 matches(r"^Expected: <\[\[5\.0\]\]>" | |
| 256 " but: expected double:<5\.0> " | |
| 257 "but was .*:'error' mismatch at position 0 " | |
| 258 "mismatch at position 0\.\$")); | |
| 254 }); | 259 }); |
| 255 }); | 260 }); |
| 256 | 261 |
| 257 group('Numeric Matchers', () { | 262 group('Numeric Matchers', () { |
| 258 | 263 |
| 259 test('greaterThan', () { | 264 test('greaterThan', () { |
| 260 shouldPass(10, greaterThan(9)); | 265 shouldPass(10, greaterThan(9)); |
| 261 shouldFail(9, greaterThan(10), | 266 shouldFail(9, greaterThan(10), |
| 262 "Expected: a value greater than <10> but: was <9>."); | 267 "Expected: a value greater than <10> but: was <9>."); |
| 263 }); | 268 }); |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 495 shouldFail(e, someElement(2), | 500 shouldFail(e, someElement(2), |
| 496 "Expected: some element <2> but: was <[1, 1, 1]>."); | 501 "Expected: some element <2> but: was <[1, 1, 1]>."); |
| 497 }); | 502 }); |
| 498 | 503 |
| 499 test('orderedEquals', () { | 504 test('orderedEquals', () { |
| 500 shouldPass([null], orderedEquals([null])); | 505 shouldPass([null], orderedEquals([null])); |
| 501 var d = [1, 2]; | 506 var d = [1, 2]; |
| 502 shouldPass(d, orderedEquals([1, 2])); | 507 shouldPass(d, orderedEquals([1, 2])); |
| 503 shouldFail(d, orderedEquals([2, 1]), | 508 shouldFail(d, orderedEquals([2, 1]), |
| 504 "Expected: equals <[2, 1]> ordered " | 509 "Expected: equals <[2, 1]> ordered " |
| 505 "but: was <1> mismatch at position 0."); | 510 "but: expected <2> but was <1> mismatch at position 0."); |
| 506 }); | 511 }); |
| 507 | 512 |
| 508 test('unorderedEquals', () { | 513 test('unorderedEquals', () { |
| 509 var d = [1, 2]; | 514 var d = [1, 2]; |
| 510 shouldPass(d, unorderedEquals([2, 1])); | 515 shouldPass(d, unorderedEquals([2, 1])); |
| 511 shouldFail(d, unorderedEquals([1]), | 516 shouldFail(d, unorderedEquals([1]), |
| 512 "Expected: equals <[1]> unordered " | 517 "Expected: equals <[1]> unordered " |
| 513 "but: has too many elements (2 > 1)."); | 518 "but: has too many elements (2 > 1)."); |
| 514 shouldFail(d, unorderedEquals([3, 2, 1]), | 519 shouldFail(d, unorderedEquals([3, 2, 1]), |
| 515 "Expected: equals <[3, 2, 1]> unordered " | 520 "Expected: equals <[3, 2, 1]> unordered " |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 703 var w = new Widget(); | 708 var w = new Widget(); |
| 704 w.price = 10; | 709 w.price = 10; |
| 705 shouldPass(w, new HasPrice(greaterThan(0))); | 710 shouldPass(w, new HasPrice(greaterThan(0))); |
| 706 shouldFail(w, new HasPrice(greaterThan(10)), | 711 shouldFail(w, new HasPrice(greaterThan(10)), |
| 707 'Expected: Widget with a price that is a value greater than <10> ' | 712 'Expected: Widget with a price that is a value greater than <10> ' |
| 708 'but: price was <10>.'); | 713 'but: price was <10>.'); |
| 709 }); | 714 }); |
| 710 }); | 715 }); |
| 711 } | 716 } |
| 712 | 717 |
| OLD | NEW |