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

Unified Diff: pkg/analysis_server/test/mocks.dart

Issue 334543002: Use a mock SDK for most analysis server tests. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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/analysis_server/test/domain_analysis_test.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analysis_server/test/mocks.dart
diff --git a/pkg/analysis_server/test/mocks.dart b/pkg/analysis_server/test/mocks.dart
index f8f3f9a66b8b30d3cf811d5db64b6f59379a852f..ac90e2403d2962452905255864c295faa8bf5fef 100644
--- a/pkg/analysis_server/test/mocks.dart
+++ b/pkg/analysis_server/test/mocks.dart
@@ -11,10 +11,13 @@ import 'dart:io';
import 'dart:mirrors';
import 'package:analyzer/src/generated/engine.dart';
+import 'package:analyzer/src/generated/sdk.dart';
+import 'package:analyzer/src/generated/sdk_io.dart';
import 'package:analyzer/src/generated/source.dart';
import 'package:analysis_server/src/analysis_server.dart';
import 'package:analysis_server/src/channel.dart';
import 'package:analysis_server/src/protocol.dart';
+import 'package:analysis_server/src/resource.dart' as resource;
import 'package:matcher/matcher.dart';
import 'package:mock/mock.dart';
import 'package:unittest/unittest.dart';
@@ -294,3 +297,117 @@ class _IsResponseFailure extends Matcher {
return mismatchDescription;
}
}
+
+class MockSdk implements DartSdk {
+
+ final resource.MemoryResourceProvider provider = new resource.MemoryResourceProvider();
+
+ MockSdk() {
+ // TODO(paulberry): Add to this as needed.
+ const Map<String, String> pathToSource = const {
+ "/lib/core/core.dart": '''
+ library dart.core;
+ class Object {}
+ class Function {}
+ class StackTrace {}
+ class Symbol {}
+ class Type {}
+
+ class String extends Object {}
+ class bool extends Object {}
+ abstract class num extends Object {
+ num operator +(num other);
+ num operator -(num other);
+ num operator *(num other);
+ num operator /(num other);
+ }
+ abstract class int extends num {
+ int operator -();
+ }
+ class double extends num {}
+ class DateTime extends Object {}
+ class Null extends Object {}
+
+ class Deprecated extends Object {
+ final String expires;
+ const Deprecated(this.expires);
+ }
+ const Object deprecated = const Deprecated("next release");
+
+ abstract class List<E> extends Object {
+ void add(E value);
+ E operator [](int index);
+ void operator []=(int index, E value);
+ }
+ class Map<K, V> extends Object {}
+
+ void print(Object object) {}
+ ''',
+
+ "/lib/html/dartium/html_dartium.dart": '''
+ library dart.html;
+ class HtmlElement {}
+ ''',
+
+ "/lib/math/math.dart": '''
+ library dart.math;
+ '''
+ };
+
+ pathToSource.forEach((String path, String source) {
+ provider.newFile(path, source);
+ });
+ }
+
+ // Not used
+ @override
+ AnalysisContext get context => throw unimplemented;
+
+ @override
+ Source fromEncoding(UriKind kind, Uri uri) {
+ // Not used
+ throw unimplemented;
+ }
+
+ UnimplementedError get unimplemented => new UnimplementedError();
+
+ @override
+ SdkLibrary getSdkLibrary(String dartUri) {
+ // getSdkLibrary() is only used to determine whether a library is internal
+ // to the SDK. The mock SDK doesn't have any internals, so it's safe to
+ // return null.
+ return null;
+ }
+
+ @override
+ Source mapDartUri(String dartUri) {
+ const Map<String, String> uriToPath = const {
+ "dart:core": "/lib/core/core.dart",
+ "dart:html": "/lib/html/dartium/html_dartium.dart",
+ "dart:math": "/lib/math/math.dart"
+ };
+
+ String path = uriToPath[dartUri];
+ if (path != null) {
+ resource.File file = provider.getResource(path);
+ return file.createSource(UriKind.DART_URI);
+ }
+
+ // If we reach here then we tried to use a dartUri that's not in the
+ // table above.
+ throw unimplemented;
+ }
+
+ // Not used.
+ @override
+ List<SdkLibrary> get sdkLibraries => throw unimplemented;
+
+ // Not used.
+ @override
+ String get sdkVersion => throw unimplemented;
+
+ // Not used.
+ @override
+ List<String> get uris => throw unimplemented;
+}
+
« no previous file with comments | « pkg/analysis_server/test/domain_analysis_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698