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

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

Issue 438473002: pkg/matcher: refactored code around data-structure vs execution-based matchers (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 5 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/throws_matchers.dart ('k') | pkg/matcher/pubspec.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/matcher/lib/src/util.dart
diff --git a/pkg/matcher/lib/src/util.dart b/pkg/matcher/lib/src/util.dart
new file mode 100644
index 0000000000000000000000000000000000000000..08cba77eb49ddf6da3d9598019c1118df0e57e7b
--- /dev/null
+++ b/pkg/matcher/lib/src/util.dart
@@ -0,0 +1,30 @@
+// Copyright (c) 2014, 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 matcher.util;
+
+import 'core_matchers.dart';
+import 'interfaces.dart';
+
+/// Useful utility for nesting match states.
+void addStateInfo(Map matchState, Map values) {
+ var innerState = new Map.from(matchState);
+ matchState.clear();
+ matchState['state'] = innerState;
+ matchState.addAll(values);
+}
+
+/// Takes an argument and returns an equivalent matcher.
+/// If the argument is already a matcher this does nothing,
+/// else if the argument is a function, it generates a predicate
+/// function matcher, else it generates an equals matcher.
+Matcher wrapMatcher(x) {
+ if (x is Matcher) {
+ return x;
+ } else if (x is Function) {
+ return predicate(x);
+ } else {
+ return equals(x);
+ }
+}
« no previous file with comments | « pkg/matcher/lib/src/throws_matchers.dart ('k') | pkg/matcher/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698