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

Unified Diff: pkg/matcher/lib/src/operator_matchers.dart

Issue 317733006: pkg/matcher: reapply 36881,36896 working around Issue 19173 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: nit Created 6 years, 6 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 | « pkg/matcher/lib/src/numeric_matchers.dart ('k') | pkg/matcher/lib/src/pretty_print.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/matcher/lib/src/operator_matchers.dart
diff --git a/pkg/matcher/lib/src/operator_matchers.dart b/pkg/matcher/lib/src/operator_matchers.dart
index fa17aba3ef74b94a34c1a83e614bf36c42a1e13e..fb79e8fd2586474814893b8e0760103885a15e2a 100644
--- a/pkg/matcher/lib/src/operator_matchers.dart
+++ b/pkg/matcher/lib/src/operator_matchers.dart
@@ -2,11 +2,13 @@
// 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.
-part of matcher;
+library matcher.operator_matchers;
-/**
- * This returns a matcher that inverts [matcher] to its logical negation.
- */
+import 'core_matchers.dart';
+import 'expect.dart';
+import 'interfaces.dart';
+
+/// This returns a matcher that inverts [matcher] to its logical negation.
Matcher isNot(matcher) => new _IsNot(wrapMatcher(matcher));
class _IsNot extends Matcher {
@@ -20,13 +22,11 @@ class _IsNot extends Matcher {
description.add('not ').addDescriptionOf(_matcher);
}
-/**
- * This returns a matcher that matches if all of the matchers passed as
- * arguments (up to 7) match. Instead of passing the matchers separately
- * they can be passed as a single List argument.
- * Any argument that is not a matcher is implicitly wrapped in a
- * Matcher to check for equality.
-*/
+/// This returns a matcher that matches if all of the matchers passed as
+/// arguments (up to 7) match. Instead of passing the matchers separately
+/// they can be passed as a single List argument.
+/// Any argument that is not a matcher is implicitly wrapped in a
+/// Matcher to check for equality.
Matcher allOf(arg0,
[arg1 = null,
arg2 = null,
@@ -34,46 +34,11 @@ Matcher allOf(arg0,
arg4 = null,
arg5 = null,
arg6 = null]) {
- if (arg0 is List) {
- expect(arg1, isNull);
- expect(arg2, isNull);
- expect(arg3, isNull);
- expect(arg4, isNull);
- expect(arg5, isNull);
- expect(arg6, isNull);
- for (int i = 0; i < arg0.length; i++) {
- arg0[i] = wrapMatcher(arg0[i]);
- }
- return new _AllOf(arg0);
- } else {
- List matchers = new List();
- if (arg0 != null) {
- matchers.add(wrapMatcher(arg0));
- }
- if (arg1 != null) {
- matchers.add(wrapMatcher(arg1));
- }
- if (arg2 != null) {
- matchers.add(wrapMatcher(arg2));
- }
- if (arg3 != null) {
- matchers.add(wrapMatcher(arg3));
- }
- if (arg4 != null) {
- matchers.add(wrapMatcher(arg4));
- }
- if (arg5 != null) {
- matchers.add(wrapMatcher(arg5));
- }
- if (arg6 != null) {
- matchers.add(wrapMatcher(arg6));
- }
- return new _AllOf(matchers);
- }
+ return new _AllOf(_wrapArgs(arg0, arg1, arg2, arg3, arg4, arg5, arg6));
}
class _AllOf extends Matcher {
- final Iterable<Matcher> _matchers;
+ final List<Matcher> _matchers;
const _AllOf(this._matchers);
@@ -99,17 +64,15 @@ class _AllOf extends Matcher {
description.addAll('(', ' and ', ')', _matchers);
}
-/**
- * Matches if any of the given matchers evaluate to true. The
- * arguments can be a set of matchers as separate parameters
- * (up to 7), or a List of matchers.
- *
- * The matchers are evaluated from left to right using short-circuit
- * evaluation, so evaluation stops as soon as a matcher returns true.
- *
- * Any argument that is not a matcher is implicitly wrapped in a
- * Matcher to check for equality.
-*/
+/// Matches if any of the given matchers evaluate to true. The
+/// arguments can be a set of matchers as separate parameters
+/// (up to 7), or a List of matchers.
+///
+/// The matchers are evaluated from left to right using short-circuit
+/// evaluation, so evaluation stops as soon as a matcher returns true.
+///
+/// Any argument that is not a matcher is implicitly wrapped in a
+/// Matcher to check for equality.
Matcher anyOf(arg0,
[arg1 = null,
@@ -118,59 +81,62 @@ Matcher anyOf(arg0,
arg4 = null,
arg5 = null,
arg6 = null]) {
- if (arg0 is List) {
- expect(arg1, isNull);
- expect(arg2, isNull);
- expect(arg3, isNull);
- expect(arg4, isNull);
- expect(arg5, isNull);
- expect(arg6, isNull);
- for (int i = 0; i < arg0.length; i++) {
- arg0[i] = wrapMatcher(arg0[i]);
- }
- return new _AnyOf(arg0);
- } else {
- List matchers = new List();
- if (arg0 != null) {
- matchers.add(wrapMatcher(arg0));
- }
- if (arg1 != null) {
- matchers.add(wrapMatcher(arg1));
- }
- if (arg2 != null) {
- matchers.add(wrapMatcher(arg2));
- }
- if (arg3 != null) {
- matchers.add(wrapMatcher(arg3));
- }
- if (arg4 != null) {
- matchers.add(wrapMatcher(arg4));
- }
- if (arg5 != null) {
- matchers.add(wrapMatcher(arg5));
- }
- if (arg6 != null) {
- matchers.add(wrapMatcher(arg6));
- }
- return new _AnyOf(matchers);
- }
+ return new _AnyOf(_wrapArgs(arg0, arg1, arg2, arg3, arg4, arg5, arg6));
}
class _AnyOf extends Matcher {
- final Iterable<Matcher> _matchers;
+ final List<Matcher> _matchers;
const _AnyOf(this._matchers);
bool matches(item, Map matchState) {
- for (var matcher in _matchers) {
- if (matcher.matches(item, matchState)) {
- return true;
- }
- }
- return false;
+ for (var matcher in _matchers) {
+ if (matcher.matches(item, matchState)) {
+ return true;
+ }
+ }
+ return false;
}
Description describe(Description description) =>
description.addAll('(', ' or ', ')', _matchers);
}
+List<Matcher> _wrapArgs(arg0, arg1, arg2, arg3, arg4, arg5, arg6) {
+ if (arg0 is List) {
+ // TODO(kevmoo) throw a more helpful error here if any of these args is
+ // not null
+ expect(arg1, isNull);
+ expect(arg2, isNull);
+ expect(arg3, isNull);
+ expect(arg4, isNull);
+ expect(arg5, isNull);
+ expect(arg6, isNull);
+
+ return arg0.map((a) => wrapMatcher(a)).toList();
+ }
+
+ List matchers = new List();
+ if (arg0 != null) {
+ matchers.add(wrapMatcher(arg0));
+ }
+ if (arg1 != null) {
+ matchers.add(wrapMatcher(arg1));
+ }
+ if (arg2 != null) {
+ matchers.add(wrapMatcher(arg2));
+ }
+ if (arg3 != null) {
+ matchers.add(wrapMatcher(arg3));
+ }
+ if (arg4 != null) {
+ matchers.add(wrapMatcher(arg4));
+ }
+ if (arg5 != null) {
+ matchers.add(wrapMatcher(arg5));
+ }
+ if (arg6 != null) {
+ matchers.add(wrapMatcher(arg6));
+ }
+ return matchers;
+}
« no previous file with comments | « pkg/matcher/lib/src/numeric_matchers.dart ('k') | pkg/matcher/lib/src/pretty_print.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698