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

Unified Diff: pkg/analysis_server/test/integration/integration_tests.dart

Issue 475143003: Fix code generated matchers to handle recursive objects. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analysis_server/test/integration/protocol_matchers.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analysis_server/test/integration/integration_tests.dart
diff --git a/pkg/analysis_server/test/integration/integration_tests.dart b/pkg/analysis_server/test/integration/integration_tests.dart
index d7112737a4daf9247eece4d0570c78dde3119f06..305ea8a5671fb17be7638c4fbe67b72d457a289d 100644
--- a/pkg/analysis_server/test/integration/integration_tests.dart
+++ b/pkg/analysis_server/test/integration/integration_tests.dart
@@ -456,6 +456,59 @@ class _ListOf extends Matcher {
Matcher isListOf(Matcher elementMatcher) => new _ListOf(elementMatcher);
/**
+ * Type of closures used by LazyMatcher.
+ */
+typedef Matcher MatcherCreator();
+
+/**
+ * Wrapper class for Matcher which doesn't create the underlying Matcher object
+ * until it is needed. This is necessary in order to create matchers that can
+ * refer to themselves (so that recursive data structures can be represented).
+ */
+class LazyMatcher implements Matcher {
+ /**
+ * Callback that will be used to create the matcher the first time it is
+ * needed.
+ */
+ final MatcherCreator _creator;
+
+ /**
+ * The matcher returned by [_creator], if it has already been called.
+ * Otherwise null.
+ */
+ Matcher _wrappedMatcher;
+
+ LazyMatcher(this._creator);
+
+ @override
+ Description describe(Description description) {
+ _createMatcher();
+ return _wrappedMatcher.describe(description);
+ }
+
+ @override
+ Description describeMismatch(item, Description mismatchDescription, Map matchState, bool verbose) {
+ _createMatcher();
+ return _wrappedMatcher.describeMismatch(item, mismatchDescription, matchState, verbose);
+ }
+
+ @override
+ bool matches(item, Map matchState) {
+ _createMatcher();
+ return _wrappedMatcher.matches(item, matchState);
+ }
+
+ /**
+ * Create the wrapped matcher object, if it hasn't been created already.
+ */
+ void _createMatcher() {
+ if (_wrappedMatcher == null) {
+ _wrappedMatcher = _creator();
+ }
+ }
+}
+
+/**
* Matcher that matches a union of different types, each of which is described
* by a matcher.
*/
« no previous file with comments | « no previous file | pkg/analysis_server/test/integration/protocol_matchers.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698