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

Unified Diff: pkg/unittest/test/matchers_test.dart

Issue 12224053: Updated contains and isEmpty matches to use iterables. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: pkg/unittest/test/matchers_test.dart
diff --git a/pkg/unittest/test/matchers_test.dart b/pkg/unittest/test/matchers_test.dart
index c95bfa18c163983b819dfc2ecb15ccfa3eec2156..bb52e48797ce8336812556a6bc59d50f27349940 100644
--- a/pkg/unittest/test/matchers_test.dart
+++ b/pkg/unittest/test/matchers_test.dart
@@ -34,6 +34,45 @@ class HasPrice extends CustomMatcher {
featureValueOf(actual) => actual.price;
}
+class SimpleIterable extends Iterable {
+ int count;
+ SimpleIterable(this.count);
+
+ bool contains(int val) => count < val ? false : true;
+
+ bool any(bool f(element)) {
+ for(var i = 0; i <= count; i++) {
+ if(f(i)) return true;
+ }
+ return false;
+ }
+
+ String toString() => "<[$count]>";
+
+ Iterator get iterator {
+ return new SimpleIterator(count);
+ }
+}
+
+class SimpleIterator implements Iterator {
+ int _count;
+ int _current;
+
+ SimpleIterator(this._count);
+
+ bool moveNext() {
+ if (_count > 0) {
+ _current = _count;
+ _count--;
+ return true;
+ }
+ _current = null;
+ return false;
+ }
+
+ get current => _current;
+}
+
void main() {
initUtils();
@@ -165,6 +204,16 @@ void main() {
"but: exception <Exception> does not match "
"UnsupportedError.");
});
+
+ test('throwsStateError', () {
+ shouldPass(() { throw new StateError(''); },
+ throwsStateError);
+ shouldFail(() { throw new Exception(); },
+ throwsStateError,
+ "Expected: throws an exception which matches StateError "
+ "but: exception <Exception> does not match "
+ "StateError.");
+ });
test('returnsNormally', () {
shouldPass(doesNotThrow, returnsNormally);
@@ -388,6 +437,21 @@ void main() {
});
});
+ group('Iterable Matchers', () {
+ test('isEmpty', () {
+ var d = new SimpleIterable(0);
+ var e = new SimpleIterable(1);
+ shouldPass(d, isEmpty);
+ shouldFail(e, isEmpty, "Expected: empty but: was <[1]>.");
+ });
+
+ test('contains', () {
+ var d = new SimpleIterable(3);
+ shouldPass(d, contains(2));
+ shouldFail(d, contains(5), "Expected: contains <5> but: was <[3]>.");
+ });
+ });
+
group('Collection Matchers', () {
test('isEmpty', () {
« 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