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

Unified Diff: test/test_utils.dart

Issue 869053002: unittest: refactor ahead of matcher changes (Closed) Base URL: https://github.com/dart-lang/unittest.git@master
Patch Set: nits Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/prints_matcher_test.dart ('k') | test/throws_matchers_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/test_utils.dart
diff --git a/test/test_utils.dart b/test/test_utils.dart
new file mode 100644
index 0000000000000000000000000000000000000000..f86631bbbfaa979d942d624dc37d6c8829a677f4
--- /dev/null
+++ b/test/test_utils.dart
@@ -0,0 +1,81 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library unittest.test_utils;
+
+import 'dart:collection';
+
+import 'package:unittest/unittest.dart';
+
+void shouldFail(value, Matcher matcher, expected) {
+ var failed = false;
+ try {
+ expect(value, matcher);
+ } on TestFailure catch (err) {
+ failed = true;
+
+ var _errorString = err.message;
+
+ if (expected is String) {
+ expect(_errorString, equalsIgnoringWhitespace(expected));
+ } else {
+ expect(_errorString.replaceAll('\n', ''), expected);
+ }
+ }
+
+ expect(failed, isTrue, reason: 'Expected to fail.');
+}
+
+void shouldPass(value, Matcher matcher) {
+ expect(value, matcher);
+}
+
+class Widget {
+ int price;
+}
+
+class HasPrice extends CustomMatcher {
+ HasPrice(matcher) : super("Widget with a price that is", "price", matcher);
+ featureValueOf(actual) => actual.price;
+}
+
+class SimpleIterable extends IterableBase<int> {
+ final 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> {
+ int _count;
+ int _current;
+
+ _SimpleIterator(this._count);
+
+ bool moveNext() {
+ if (_count > 0) {
+ _current = _count;
+ _count--;
+ return true;
+ }
+ _current = null;
+ return false;
+ }
+
+ int get current => _current;
+}
« no previous file with comments | « test/prints_matcher_test.dart ('k') | test/throws_matchers_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698