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

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

Issue 21085010: Added hasProperty matcher. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 4 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
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 import 'dart:async'; 5 import 'dart:async';
6 import 'dart:collection'; 6 import 'dart:collection';
7 7
8 import 'package:unittest/unittest.dart'; 8 import 'package:unittest/unittest.dart';
9 9
10 import 'test_common.dart'; 10 import 'test_common.dart';
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 test('lessThanOrEqualTo', () { 196 test('lessThanOrEqualTo', () {
197 shouldPass(10, lessThanOrEqualTo(10)); 197 shouldPass(10, lessThanOrEqualTo(10));
198 shouldFail(11, lessThanOrEqualTo(10), 198 shouldFail(11, lessThanOrEqualTo(10),
199 "Expected: a value less than or equal to <10> " 199 "Expected: a value less than or equal to <10> "
200 "Actual: <11> " 200 "Actual: <11> "
201 "Which: is not a value less than or equal to <10>"); 201 "Which: is not a value less than or equal to <10>");
202 }); 202 });
203 203
204 test('isZero', () { 204 test('isZero', () {
205 shouldPass(0, isZero); 205 shouldPass(0, isZero);
206 shouldFail(1, isZero, 206 shouldFail(1, isZero,
207 "Expected: a value equal to <0> " 207 "Expected: a value equal to <0> "
208 "Actual: <1> " 208 "Actual: <1> "
209 "Which: is not a value equal to <0>"); 209 "Which: is not a value equal to <0>");
210 }); 210 });
211 211
212 test('isNonZero', () { 212 test('isNonZero', () {
213 shouldFail(0, isNonZero, 213 shouldFail(0, isNonZero,
214 "Expected: a value not equal to <0> " 214 "Expected: a value not equal to <0> "
215 "Actual: <0> " 215 "Actual: <0> "
216 "Which: is not a value not equal to <0>"); 216 "Which: is not a value not equal to <0>");
217 shouldPass(1, isNonZero); 217 shouldPass(1, isNonZero);
218 }); 218 });
219 219
220 test('isPositive', () { 220 test('isPositive', () {
221 shouldFail(-1, isPositive, 221 shouldFail(-1, isPositive,
222 "Expected: a positive value " 222 "Expected: a positive value "
223 "Actual: <-1> " 223 "Actual: <-1> "
224 "Which: is not a positive value"); 224 "Which: is not a positive value");
225 shouldFail(0, isPositive, 225 shouldFail(0, isPositive,
226 "Expected: a positive value " 226 "Expected: a positive value "
227 "Actual: <0> " 227 "Actual: <0> "
228 "Which: is not a positive value"); 228 "Which: is not a positive value");
229 shouldPass(1, isPositive); 229 shouldPass(1, isPositive);
230 }); 230 });
231 231
232 test('isNegative', () { 232 test('isNegative', () {
233 shouldPass(-1, isNegative); 233 shouldPass(-1, isNegative);
234 shouldFail(0, isNegative, 234 shouldFail(0, isNegative,
235 "Expected: a negative value " 235 "Expected: a negative value "
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 test('nested everyElement', () { 421 test('nested everyElement', () {
422 var d = [['foo', 'bar'], ['foo'], []]; 422 var d = [['foo', 'bar'], ['foo'], []];
423 var e = [['foo', 'bar'], ['foo'], 3, []]; 423 var e = [['foo', 'bar'], ['foo'], 3, []];
424 shouldPass(d, everyElement(anyOf(isEmpty, contains('foo')))); 424 shouldPass(d, everyElement(anyOf(isEmpty, contains('foo'))));
425 shouldFail(d, everyElement(everyElement(equals('foo'))), 425 shouldFail(d, everyElement(everyElement(equals('foo'))),
426 "Expected: every element(every element('foo')) " 426 "Expected: every element(every element('foo')) "
427 "Actual: [['foo', 'bar'], ['foo'], []] " 427 "Actual: [['foo', 'bar'], ['foo'], []] "
428 "Which: has value ['foo', 'bar'] which has value 'bar' " 428 "Which: has value ['foo', 'bar'] which has value 'bar' "
429 "which is different. Expected: foo Actual: bar ^ " 429 "which is different. Expected: foo Actual: bar ^ "
430 "Differ at offset 0 at index 1 at index 0"); 430 "Differ at offset 0 at index 1 at index 0");
431 shouldFail(d, everyElement(allOf(hasLength(greaterThan(0)), 431 shouldFail(d, everyElement(allOf(hasLength(greaterThan(0)),
432 contains('foo'))), 432 contains('foo'))),
433 "Expected: every element((an object with length of a value " 433 "Expected: every element((an object with length of a value "
434 "greater than <0> and contains 'foo')) " 434 "greater than <0> and contains 'foo')) "
435 "Actual: [['foo', 'bar'], ['foo'], []] " 435 "Actual: [['foo', 'bar'], ['foo'], []] "
436 "Which: has value [] which has length of <0> at index 2"); 436 "Which: has value [] which has length of <0> at index 2");
437 shouldFail(d, everyElement(allOf(contains('foo'), 437 shouldFail(d, everyElement(allOf(contains('foo'),
438 hasLength(greaterThan(0)))), 438 hasLength(greaterThan(0)))),
439 "Expected: every element((contains 'foo' and " 439 "Expected: every element((contains 'foo' and "
440 "an object with length of a value greater than <0>)) " 440 "an object with length of a value greater than <0>)) "
441 "Actual: [['foo', 'bar'], ['foo'], []] " 441 "Actual: [['foo', 'bar'], ['foo'], []] "
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
738 expect(() { 738 expect(() {
739 var a = 0; 739 var a = 0;
740 switch (a) { 740 switch (a) {
741 case 0: 741 case 0:
742 a += 1; 742 a += 1;
743 case 1: 743 case 1:
744 return; 744 return;
745 } 745 }
746 }, throwsFallThroughError); 746 }, throwsFallThroughError);
747 }); 747 });
748
749 test('hasProperty', () {
750 var foo = [3];
751 expect(foo, hasProperty('length', 1));
752 expect(() => expect(foo, hasProperty('foo')),
753 throwsA(predicate((x) => x is TestFailure &&
754 x.toString().contains('No property named foo'))));
755 expect(() => expect(foo, hasProperty('length', 2)),
756 throwsA(predicate((x) => x is TestFailure &&
757 x.toString().contains(
758 'has property length with value <1>'))));
759
760 });
748 }); 761 });
749 } 762 }
750 763
751 class Bicycle { 764 class Bicycle {
752 static var foo = bar(); 765 static var foo = bar();
753 766
754 static bar() { 767 static bar() {
755 return foo + 1; 768 return foo + 1;
756 } 769 }
757 770
758 X() { 771 X() {
759 print(foo); 772 print(foo);
760 } 773 }
761 } 774 }
762 775
763 abstract class Abstraction { 776 abstract class Abstraction {
764 void norealization(); 777 void norealization();
765 } 778 }
766 779
OLDNEW
« pkg/unittest/lib/src/core_matchers.dart ('K') | « pkg/unittest/lib/src/core_matchers.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698