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

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

Issue 469673002: Add union types to the analysis server API spec. (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
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 798e7432e68fb4cdb80ceb0b0e9c1ed9f35788ba..d7112737a4daf9247eece4d0570c78dde3119f06 100644
--- a/pkg/analysis_server/test/integration/integration_tests.dart
+++ b/pkg/analysis_server/test/integration/integration_tests.dart
@@ -456,6 +456,50 @@ class _ListOf extends Matcher {
Matcher isListOf(Matcher elementMatcher) => new _ListOf(elementMatcher);
/**
+ * Matcher that matches a union of different types, each of which is described
+ * by a matcher.
+ */
+class _OneOf extends Matcher {
+ /**
+ * Matchers for the individual choices.
+ */
+ final List<Matcher> choiceMatchers;
+
+ _OneOf(this.choiceMatchers);
+
+ @override
+ bool matches(item, Map matchState) {
+ for (Matcher choiceMatcher in choiceMatchers) {
+ Map subState = {};
+ if (choiceMatcher.matches(item, subState)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @override
+ Description describe(Description description) {
+ for (int i = 0; i < choiceMatchers.length; i++) {
+ if (i != 0) {
+ if (choiceMatchers.length == 2) {
+ description = description.add(' or ');
+ } else {
+ description = description.add(', ');
+ if (i == choiceMatchers.length - 1) {
+ description = description.add('or ');
+ }
+ }
+ }
+ description = description.addDescriptionOf(choiceMatchers[i]);
+ }
+ return description;
+ }
+}
+
+Matcher isOneOf(List<Matcher> choiceMatchers) => new _OneOf(choiceMatchers);
+
+/**
* Matcher that matches a map of objects, where each key/value pair in the
* map satisies the given key and value matchers.
*/

Powered by Google App Engine
This is Rietveld 408576698