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

Unified Diff: pkg/analysis_server/test/analysis/get_navigation_test.dart

Issue 1229833004: Add test for 'getNavigation'. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analysis_server/test/analysis/get_navigation_test.dart
diff --git a/pkg/analysis_server/test/analysis/get_navigation_test.dart b/pkg/analysis_server/test/analysis/get_navigation_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..b5c224e43233b6e1850bcbae820cfb52ecf453eb
--- /dev/null
+++ b/pkg/analysis_server/test/analysis/get_navigation_test.dart
@@ -0,0 +1,114 @@
+// 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 test.analysis.get_navigation;
+
+import 'package:analysis_server/src/domain_analysis.dart';
+import 'package:analysis_server/src/protocol.dart';
+import 'package:analyzer/file_system/file_system.dart';
+import 'package:test_reflective_loader/test_reflective_loader.dart';
+import 'package:unittest/unittest.dart';
+
+import 'notification_navigation_test.dart';
+
+main() {
+ groupSep = ' | ';
+ defineReflectiveTests(GetNavigationTest);
+}
+
+@reflectiveTest
+class GetNavigationTest extends AbstractNavigationTest {
+ static const String requestId = 'test-getNavigtion';
+
+ @override
+ void setUp() {
+ super.setUp();
+ server.handlers = [new AnalysisDomainHandler(server),];
+ createProject();
+ }
+
+ test_afterAnalysisComplete() async {
+ addTestFile('''
+main() {
+ var test = 0;
+ print(test);
+}
+''');
+ await waitForTasksFinished();
+ await _getNavigation(testFile, testCode.indexOf('test);'), 0);
+ assertHasRegion('test);');
+ assertHasTarget('test = 0');
+ }
+
+ test_beforeAnalysisComplete() async {
+ addTestFile('''
+main() {
+ var test = 0;
+ print(test);
+}
+''');
+ await _getNavigation(testFile, testCode.indexOf('test);'), 0);
+ assertHasRegion('test);');
+ assertHasTarget('test = 0');
+ }
+
+ test_fileDoesNotExist() {
+ String file = '$projectPath/doesNotExist.dart';
+ return _checkInvalid(file, -1, -1);
+ }
+
+ test_fileWithoutContext() {
+ String file = '/outside.dart';
+ addFile(file, '''
+main() {
+ print(42);
+}
+''');
+ return _checkInvalid(file, -1, -1);
+ }
+
+ test_removeContextAfterRequest() async {
+ addTestFile('''
+main() {
+ var test = 0;
+ print(test);
+}
+''');
+ // handle the request synchronously
+ Request request =
+ _createGetNavigationRequest(testFile, testCode.indexOf('test);'), 0);
+ server.handleRequest(request);
+ // remove context, causes sending an "invalid file" error
+ {
+ Folder projectFolder = resourceProvider.getResource(projectPath);
+ server.contextDirectoryManager.removeContext(projectFolder);
+ }
+ // wait for an error response
+ Response response = await serverChannel.waitForResponse(request);
+ expect(response.error, isNotNull);
+ expect(response.error.code, RequestErrorCode.GET_NAVIGATION_INVALID_FILE);
+ }
+
+ _checkInvalid(String file, int offset, int length) async {
+ Request request = _createGetNavigationRequest(file, offset, length);
+ Response response = await serverChannel.sendRequest(request);
+ expect(response.error, isNotNull);
+ expect(response.error.code, RequestErrorCode.GET_NAVIGATION_INVALID_FILE);
+ }
+
+ Request _createGetNavigationRequest(String file, int offset, int length) {
+ return new AnalysisGetNavigationParams(file, offset, length)
+ .toRequest(requestId);
+ }
+
+ _getNavigation(String file, int offset, int length) async {
+ Request request = _createGetNavigationRequest(file, offset, length);
+ Response response = await serverChannel.sendRequest(request);
+ AnalysisGetNavigationResult result =
+ new AnalysisGetNavigationResult.fromResponse(response);
+ targetFiles = result.files;
+ targets = result.targets;
+ regions = result.regions;
+ }
+}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698