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

Unified Diff: pkg/analysis_server/test/plugin/protocol_dart_test.dart

Issue 1398333002: Extract protocol_dart.dart APIs. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Add new files. Created 5 years, 2 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/plugin/protocol_dart_test.dart
diff --git a/pkg/analysis_server/test/protocol_server_test.dart b/pkg/analysis_server/test/plugin/protocol_dart_test.dart
similarity index 65%
copy from pkg/analysis_server/test/protocol_server_test.dart
copy to pkg/analysis_server/test/plugin/protocol_dart_test.dart
index d770e3505a32f9ce30498deecc42b78968048ccb..35cf37d82bd34026b2632b091d5a3dd76626f530 100644
--- a/pkg/analysis_server/test/protocol_server_test.dart
+++ b/pkg/analysis_server/test/plugin/protocol_dart_test.dart
@@ -4,148 +4,49 @@
library test.computer.element;
-import 'dart:mirrors';
-
-import 'package:analysis_server/src/constants.dart';
-import 'package:analysis_server/src/protocol_server.dart';
-import 'package:analysis_server/src/services/search/search_engine.dart';
+import 'package:analysis_server/plugin/protocol/protocol.dart';
+import 'package:analysis_server/plugin/protocol/protocol_dart.dart';
import 'package:analyzer/src/generated/ast.dart' as engine;
import 'package:analyzer/src/generated/element.dart' as engine;
import 'package:analyzer/src/generated/error.dart' as engine;
import 'package:analyzer/src/generated/source.dart' as engine;
import 'package:test_reflective_loader/test_reflective_loader.dart';
-import 'package:typed_mock/typed_mock.dart';
import 'package:unittest/unittest.dart';
-import 'abstract_context.dart';
-import 'mocks.dart';
-import 'utils.dart';
+import '../abstract_context.dart';
+import '../utils.dart';
main() {
initializeTestEnvironment();
- defineReflectiveTests(AnalysisErrorTest);
defineReflectiveTests(ElementTest);
defineReflectiveTests(ElementKindTest);
- defineReflectiveTests(EnumTest);
-}
-
-class AnalysisErrorMock extends TypedMock implements engine.AnalysisError {
- noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
-}
-
-@reflectiveTest
-class AnalysisErrorTest {
- engine.Source source = new MockSource();
- engine.LineInfo lineInfo;
- engine.AnalysisError engineError = new AnalysisErrorMock();
-
- void setUp() {
- // prepare Source
- when(source.fullName).thenReturn('foo.dart');
- // prepare LineInfo
- lineInfo = new engine.LineInfo([0, 5, 9, 20]);
- // prepare AnalysisError
- when(engineError.source).thenReturn(source);
- when(engineError.errorCode)
- .thenReturn(engine.CompileTimeErrorCode.AMBIGUOUS_EXPORT);
- when(engineError.message).thenReturn('my message');
- when(engineError.offset).thenReturn(10);
- when(engineError.length).thenReturn(20);
- }
-
- void tearDown() {
- source = null;
- engineError = null;
- }
-
- void test_fromEngine_hasCorrection() {
- when(engineError.correction).thenReturn('my correction');
- AnalysisError error = newAnalysisError_fromEngine(lineInfo, engineError);
- expect(error.toJson(), {
- SEVERITY: 'ERROR',
- TYPE: 'COMPILE_TIME_ERROR',
- LOCATION: {
- FILE: 'foo.dart',
- OFFSET: 10,
- LENGTH: 20,
- START_LINE: 3,
- START_COLUMN: 2
- },
- MESSAGE: 'my message',
- CORRECTION: 'my correction',
- HAS_FIX : false
- });
- }
-
- void test_fromEngine_noCorrection() {
- when(engineError.correction).thenReturn(null);
- AnalysisError error = newAnalysisError_fromEngine(lineInfo, engineError);
- expect(error.toJson(), {
- SEVERITY: 'ERROR',
- TYPE: 'COMPILE_TIME_ERROR',
- LOCATION: {
- FILE: 'foo.dart',
- OFFSET: 10,
- LENGTH: 20,
- START_LINE: 3,
- START_COLUMN: 2
- },
- MESSAGE: 'my message',
- HAS_FIX : false
- });
- }
-
- void test_fromEngine_noLineInfo() {
- when(engineError.correction).thenReturn(null);
- AnalysisError error = newAnalysisError_fromEngine(null, engineError);
- expect(error.toJson(), {
- SEVERITY: 'ERROR',
- TYPE: 'COMPILE_TIME_ERROR',
- LOCATION: {
- FILE: 'foo.dart',
- OFFSET: 10,
- LENGTH: 20,
- START_LINE: -1,
- START_COLUMN: -1
- },
- MESSAGE: 'my message',
- HAS_FIX : false
- });
- }
}
@reflectiveTest
class ElementKindTest {
void test_fromEngine() {
- expect(
- newElementKind_fromEngine(engine.ElementKind.CLASS), ElementKind.CLASS);
- expect(newElementKind_fromEngine(engine.ElementKind.COMPILATION_UNIT),
+ expect(convertElementKind(engine.ElementKind.CLASS), ElementKind.CLASS);
+ expect(convertElementKind(engine.ElementKind.COMPILATION_UNIT),
ElementKind.COMPILATION_UNIT);
- expect(newElementKind_fromEngine(engine.ElementKind.CONSTRUCTOR),
+ expect(convertElementKind(engine.ElementKind.CONSTRUCTOR),
ElementKind.CONSTRUCTOR);
+ expect(convertElementKind(engine.ElementKind.FIELD), ElementKind.FIELD);
expect(
- newElementKind_fromEngine(engine.ElementKind.FIELD), ElementKind.FIELD);
- expect(newElementKind_fromEngine(engine.ElementKind.FUNCTION),
- ElementKind.FUNCTION);
- expect(newElementKind_fromEngine(engine.ElementKind.FUNCTION_TYPE_ALIAS),
+ convertElementKind(engine.ElementKind.FUNCTION), ElementKind.FUNCTION);
+ expect(convertElementKind(engine.ElementKind.FUNCTION_TYPE_ALIAS),
ElementKind.FUNCTION_TYPE_ALIAS);
- expect(newElementKind_fromEngine(engine.ElementKind.GETTER),
- ElementKind.GETTER);
- expect(
- newElementKind_fromEngine(engine.ElementKind.LABEL), ElementKind.LABEL);
- expect(newElementKind_fromEngine(engine.ElementKind.LIBRARY),
- ElementKind.LIBRARY);
- expect(newElementKind_fromEngine(engine.ElementKind.LOCAL_VARIABLE),
+ expect(convertElementKind(engine.ElementKind.GETTER), ElementKind.GETTER);
+ expect(convertElementKind(engine.ElementKind.LABEL), ElementKind.LABEL);
+ expect(convertElementKind(engine.ElementKind.LIBRARY), ElementKind.LIBRARY);
+ expect(convertElementKind(engine.ElementKind.LOCAL_VARIABLE),
ElementKind.LOCAL_VARIABLE);
- expect(newElementKind_fromEngine(engine.ElementKind.METHOD),
- ElementKind.METHOD);
- expect(newElementKind_fromEngine(engine.ElementKind.PARAMETER),
+ expect(convertElementKind(engine.ElementKind.METHOD), ElementKind.METHOD);
+ expect(convertElementKind(engine.ElementKind.PARAMETER),
ElementKind.PARAMETER);
- expect(newElementKind_fromEngine(engine.ElementKind.SETTER),
- ElementKind.SETTER);
- expect(newElementKind_fromEngine(engine.ElementKind.TOP_LEVEL_VARIABLE),
+ expect(convertElementKind(engine.ElementKind.SETTER), ElementKind.SETTER);
+ expect(convertElementKind(engine.ElementKind.TOP_LEVEL_VARIABLE),
ElementKind.TOP_LEVEL_VARIABLE);
- expect(newElementKind_fromEngine(engine.ElementKind.TYPE_PARAMETER),
+ expect(convertElementKind(engine.ElementKind.TYPE_PARAMETER),
ElementKind.TYPE_PARAMETER);
}
@@ -207,7 +108,7 @@ class B<K, V> {}''');
{
engine.ClassElement engineElement = findElementInUnit(unit, '_A');
// create notification Element
- Element element = newElement_fromEngine(engineElement);
+ Element element = convertElement(engineElement);
expect(element.kind, ElementKind.CLASS);
expect(element.name, '_A');
expect(element.typeParameters, isNull);
@@ -229,7 +130,7 @@ class B<K, V> {}''');
{
engine.ClassElement engineElement = findElementInUnit(unit, 'B');
// create notification Element
- Element element = newElement_fromEngine(engineElement);
+ Element element = convertElement(engineElement);
expect(element.kind, ElementKind.CLASS);
expect(element.name, 'B');
expect(element.typeParameters, '<K, V>');
@@ -248,7 +149,7 @@ class A {
engine.ConstructorElement engineElement =
findElementInUnit(unit, 'myConstructor');
// create notification Element
- Element element = newElement_fromEngine(engineElement);
+ Element element = convertElement(engineElement);
expect(element.kind, ElementKind.CONSTRUCTOR);
expect(element.name, 'myConstructor');
expect(element.typeParameters, isNull);
@@ -268,7 +169,7 @@ class A {
void test_fromElement_dynamic() {
var engineElement = engine.DynamicElementImpl.instance;
// create notification Element
- Element element = newElement_fromEngine(engineElement);
+ Element element = convertElement(engineElement);
expect(element.kind, ElementKind.UNKNOWN);
expect(element.name, 'dynamic');
expect(element.location, isNull);
@@ -289,7 +190,7 @@ enum E2 { three, four }''');
engine.ClassElement engineElement = findElementInUnit(unit, '_E1');
expect(engineElement.isDeprecated, isTrue);
// create notification Element
- Element element = newElement_fromEngine(engineElement);
+ Element element = convertElement(engineElement);
expect(element.kind, ElementKind.ENUM);
expect(element.name, '_E1');
expect(element.typeParameters, isNull);
@@ -310,7 +211,7 @@ enum E2 { three, four }''');
{
engine.ClassElement engineElement = findElementInUnit(unit, 'E2');
// create notification Element
- Element element = newElement_fromEngine(engineElement);
+ Element element = convertElement(engineElement);
expect(element.kind, ElementKind.ENUM);
expect(element.name, 'E2');
expect(element.typeParameters, isNull);
@@ -329,7 +230,7 @@ enum E2 { three, four }''');
{
engine.FieldElement engineElement = findElementInUnit(unit, 'one');
// create notification Element
- Element element = newElement_fromEngine(engineElement);
+ Element element = convertElement(engineElement);
expect(element.kind, ElementKind.ENUM_CONSTANT);
expect(element.name, 'one');
{
@@ -353,7 +254,7 @@ enum E2 { three, four }''');
{
engine.FieldElement engineElement = findElementInUnit(unit, 'three');
// create notification Element
- Element element = newElement_fromEngine(engineElement);
+ Element element = convertElement(engineElement);
expect(element.kind, ElementKind.ENUM_CONSTANT);
expect(element.name, 'three');
{
@@ -371,7 +272,7 @@ enum E2 { three, four }''');
{
engine.FieldElement engineElement = findElementInUnit(unit, 'index');
// create notification Element
- Element element = newElement_fromEngine(engineElement);
+ Element element = convertElement(engineElement);
expect(element.kind, ElementKind.FIELD);
expect(element.name, 'index');
{
@@ -389,7 +290,7 @@ enum E2 { three, four }''');
{
engine.FieldElement engineElement = findElementInUnit(unit, 'values');
// create notification Element
- Element element = newElement_fromEngine(engineElement);
+ Element element = convertElement(engineElement);
expect(element.kind, ElementKind.FIELD);
expect(element.name, 'values');
{
@@ -416,7 +317,7 @@ class A {
engine.CompilationUnit unit = resolveLibraryUnit(source);
engine.FieldElement engineElement = findElementInUnit(unit, 'myField');
// create notification Element
- Element element = newElement_fromEngine(engineElement);
+ Element element = convertElement(engineElement);
expect(element.kind, ElementKind.FIELD);
expect(element.name, 'myField');
{
@@ -442,7 +343,7 @@ typedef int F<T>(String x);
engine.FunctionTypeAliasElement engineElement =
findElementInUnit(unit, 'F');
// create notification Element
- Element element = newElement_fromEngine(engineElement);
+ Element element = convertElement(engineElement);
expect(element.kind, ElementKind.FUNCTION_TYPE_ALIAS);
expect(element.name, 'F');
expect(element.typeParameters, '<T>');
@@ -470,7 +371,7 @@ class A {
engine.PropertyAccessorElement engineElement =
findElementInUnit(unit, 'myGetter', engine.ElementKind.GETTER);
// create notification Element
- Element element = newElement_fromEngine(engineElement);
+ Element element = convertElement(engineElement);
expect(element.kind, ElementKind.GETTER);
expect(element.name, 'myGetter');
{
@@ -499,7 +400,7 @@ myLabel:
engine.CompilationUnit unit = resolveLibraryUnit(source);
engine.LabelElement engineElement = findElementInUnit(unit, 'myLabel');
// create notification Element
- Element element = newElement_fromEngine(engineElement);
+ Element element = convertElement(engineElement);
expect(element.kind, ElementKind.LABEL);
expect(element.name, 'myLabel');
{
@@ -527,7 +428,7 @@ class A {
engine.CompilationUnit unit = resolveLibraryUnit(source);
engine.MethodElement engineElement = findElementInUnit(unit, 'myMethod');
// create notification Element
- Element element = newElement_fromEngine(engineElement);
+ Element element = convertElement(engineElement);
expect(element.kind, ElementKind.METHOD);
expect(element.name, 'myMethod');
{
@@ -555,7 +456,7 @@ class A {
findElementInUnit(unit, 'mySetter', engine.ElementKind.FIELD);
engine.PropertyAccessorElement engineElement = engineFieldElement.setter;
// create notification Element
- Element element = newElement_fromEngine(engineElement);
+ Element element = convertElement(engineElement);
expect(element.kind, ElementKind.SETTER);
expect(element.name, 'mySetter');
{
@@ -571,86 +472,3 @@ class A {
expect(element.flags, 0);
}
}
-
-@reflectiveTest
-class EnumTest {
- void test_AnalysisErrorSeverity() {
- new EnumTester<engine.ErrorSeverity, AnalysisErrorSeverity>().run(
- (engine.ErrorSeverity engineErrorSeverity) =>
- new AnalysisErrorSeverity(engineErrorSeverity.name),
- exceptions: {engine.ErrorSeverity.NONE: null});
- }
-
- void test_AnalysisErrorType() {
- new EnumTester<engine.ErrorType, AnalysisErrorType>().run(
- (engine.ErrorType engineErrorType) =>
- new AnalysisErrorType(engineErrorType.name));
- }
-
- void test_ElementKind() {
- new EnumTester<engine.ElementKind, ElementKind>()
- .run(newElementKind_fromEngine, exceptions: {
- // TODO(paulberry): do any of the exceptions below constitute bugs?
- engine.ElementKind.DYNAMIC: ElementKind.UNKNOWN,
- engine.ElementKind.EMBEDDED_HTML_SCRIPT: ElementKind.UNKNOWN,
- engine.ElementKind.ERROR: ElementKind.UNKNOWN,
- engine.ElementKind.EXPORT: ElementKind.UNKNOWN,
- engine.ElementKind.EXTERNAL_HTML_SCRIPT: ElementKind.UNKNOWN,
- engine.ElementKind.HTML: ElementKind.UNKNOWN,
- engine.ElementKind.IMPORT: ElementKind.UNKNOWN,
- engine.ElementKind.NAME: ElementKind.UNKNOWN,
- engine.ElementKind.UNIVERSE: ElementKind.UNKNOWN
- });
- }
-
- void test_SearchResultKind() {
- // TODO(paulberry): why does the MatchKind class exist at all? Can't we
- // use SearchResultKind inside the analysis server?
- new EnumTester<MatchKind, SearchResultKind>()
- .run(newSearchResultKind_fromEngine);
- }
-}
-
-/**
- * Helper class for testing the correspondence between an analysis engine enum
- * and an analysis server API enum.
- */
-class EnumTester<EngineEnum, ApiEnum extends Enum> {
- /**
- * Test that the function [convert] properly converts all possible values of
- * [EngineEnum] to an [ApiEnum] with the same name, with the exceptions noted
- * in [exceptions]. For each key in [exceptions], if the corresponding value
- * is null, then we check that converting the given key results in an error.
- * If the corresponding value is an [ApiEnum], then we check that converting
- * the given key results in the given value.
- */
- void run(ApiEnum convert(EngineEnum value),
- {Map<EngineEnum, ApiEnum> exceptions: const {}}) {
- ClassMirror engineClass = reflectClass(EngineEnum);
- engineClass.staticMembers.forEach((Symbol symbol, MethodMirror method) {
- if (symbol == #values) {
- return;
- }
- if (!method.isGetter) {
- return;
- }
- String enumName = MirrorSystem.getName(symbol);
- EngineEnum engineValue = engineClass.getField(symbol).reflectee;
- expect(engineValue, new isInstanceOf<EngineEnum>());
- if (exceptions.containsKey(engineValue)) {
- ApiEnum expectedResult = exceptions[engineValue];
- if (expectedResult == null) {
- expect(() {
- convert(engineValue);
- }, throws);
- } else {
- ApiEnum apiValue = convert(engineValue);
- expect(apiValue, equals(expectedResult));
- }
- } else {
- ApiEnum apiValue = convert(engineValue);
- expect(apiValue.name, equals(enumName));
- }
- });
- }
-}
« no previous file with comments | « pkg/analysis_server/lib/src/services/completion/suggestion_builder.dart ('k') | pkg/analysis_server/test/plugin/test_all.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698