Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(243)

Side by Side Diff: pkg/unittest/test/matchers_test.dart

Issue 11821039: More fixes to unittest (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/unittest/lib/src/future_matchers.dart ('k') | pkg/unittest/test/test_utils.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 part 'test_utils.dart'; 8 part 'test_utils.dart';
8 9
9 doesNotThrow() {} 10 doesNotThrow() {}
10 doesThrow() { throw 'X'; } 11 doesThrow() { throw 'X'; }
11 12
12 class PrefixMatcher extends BaseMatcher { 13 class PrefixMatcher extends BaseMatcher {
13 final String _prefix; 14 final String _prefix;
14 const PrefixMatcher(this._prefix); 15 const PrefixMatcher(this._prefix);
15 bool matches(item, MatchState matchState) { 16 bool matches(item, MatchState matchState) {
16 return item is String && 17 return item is String &&
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 }); 508 });
508 509
509 test('allOf', () { 510 test('allOf', () {
510 shouldPass(1, allOf([lessThan(10), greaterThan(0)])); 511 shouldPass(1, allOf([lessThan(10), greaterThan(0)]));
511 shouldFail(-1, allOf([lessThan(10), greaterThan(0)]), 512 shouldFail(-1, allOf([lessThan(10), greaterThan(0)]),
512 "Expected: (a value less than <10> and a value greater than <0>) " 513 "Expected: (a value less than <10> and a value greater than <0>) "
513 "but: a value greater than <0> was <-1>."); 514 "but: a value greater than <0> was <-1>.");
514 }); 515 });
515 }); 516 });
516 517
518 group('Future Matchers', () {
519
520 test('completes - unexpected error', () {
521 var completer = new Completer();
522 completer.completeError('X');
523 shouldFail(completer.future, completes,
524 contains('Expected future to complete successfully, '
525 'but it failed with X'),
526 isAsync: true);
527 });
528
529 test('completes - successfully', () {
530 var completer = new Completer();
531 completer.complete('1');
532 shouldPass(completer.future, completes, isAsync: true);
533 });
534
535 test('throws - unexpected to see normal completion', () {
536 var completer = new Completer();
537 completer.complete('1');
538 shouldFail(completer.future, throws,
539 contains("Expected future to fail, but succeeded with '1'"),
540 isAsync: true);
541 });
542
543 test('throws - expected to see exception', () {
544 var completer = new Completer();
545 completer.completeError('X');
546 shouldPass(completer.future, throws, isAsync: true);
547 });
548
549 test('throws - expected to see exception thrown later on', () {
550 var completer = new Completer();
551 var chained = completer.future.then((_) { throw 'X'; });
552 shouldPass(chained, throws, isAsync: true);
553 completer.complete('1');
554 });
555
556 test('throwsA - unexpected normal completion', () {
557 var completer = new Completer();
558 completer.complete('1');
559 shouldFail(completer.future, throwsA(equals('X')),
560 contains("Expected future to fail, but succeeded with '1'"),
561 isAsync: true);
562 });
563
564 test('throwsA - correct error', () {
565 var completer = new Completer();
566 completer.completeError('X');
567 shouldPass(completer.future, throwsA(equals('X')), isAsync: true);
568 });
569
570 test('throwsA - wrong error', () {
571 var completer = new Completer();
572 completer.completeError('X');
573 shouldFail(completer.future, throwsA(equals('Y')),
574 "Expected: 'Y' but: was 'X'.",
575 isAsync: true);
576 });
577 });
578
517 group('Predicate Matchers', () { 579 group('Predicate Matchers', () {
518 test('isInstanceOf', () { 580 test('isInstanceOf', () {
519 shouldFail(0, predicate((x) => x is String, "an instance of String"), 581 shouldFail(0, predicate((x) => x is String, "an instance of String"),
520 "Expected: an instance of String but: was <0>."); 582 "Expected: an instance of String but: was <0>.");
521 shouldPass('cow', predicate((x) => x is String, "an instance of String")); 583 shouldPass('cow', predicate((x) => x is String, "an instance of String"));
522 }); 584 });
523 }); 585 });
524 586
525 group('Feature Matchers', () { 587 group('Feature Matchers', () {
526 test("Feature Matcher", () { 588 test("Feature Matcher", () {
527 var w = new Widget(); 589 var w = new Widget();
528 w.price = 10; 590 w.price = 10;
529 shouldPass(w, new HasPrice(greaterThan(0))); 591 shouldPass(w, new HasPrice(greaterThan(0)));
530 shouldFail(w, new HasPrice(greaterThan(10)), 592 shouldFail(w, new HasPrice(greaterThan(10)),
531 'Expected: Widget with a price that is a value greater than <10> ' 593 'Expected: Widget with a price that is a value greater than <10> '
532 'but: price was <10>.'); 594 'but: price was <10>.');
533 }); 595 });
534 }); 596 });
535 } 597 }
536 598
OLDNEW
« no previous file with comments | « pkg/unittest/lib/src/future_matchers.dart ('k') | pkg/unittest/test/test_utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698