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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 library test.analysis.get_navigation;
6
7 import 'package:analysis_server/src/domain_analysis.dart';
8 import 'package:analysis_server/src/protocol.dart';
9 import 'package:analyzer/file_system/file_system.dart';
10 import 'package:test_reflective_loader/test_reflective_loader.dart';
11 import 'package:unittest/unittest.dart';
12
13 import 'notification_navigation_test.dart';
14
15 main() {
16 groupSep = ' | ';
17 defineReflectiveTests(GetNavigationTest);
18 }
19
20 @reflectiveTest
21 class GetNavigationTest extends AbstractNavigationTest {
22 static const String requestId = 'test-getNavigtion';
23
24 @override
25 void setUp() {
26 super.setUp();
27 server.handlers = [new AnalysisDomainHandler(server),];
28 createProject();
29 }
30
31 test_afterAnalysisComplete() async {
32 addTestFile('''
33 main() {
34 var test = 0;
35 print(test);
36 }
37 ''');
38 await waitForTasksFinished();
39 await _getNavigation(testFile, testCode.indexOf('test);'), 0);
40 assertHasRegion('test);');
41 assertHasTarget('test = 0');
42 }
43
44 test_beforeAnalysisComplete() async {
45 addTestFile('''
46 main() {
47 var test = 0;
48 print(test);
49 }
50 ''');
51 await _getNavigation(testFile, testCode.indexOf('test);'), 0);
52 assertHasRegion('test);');
53 assertHasTarget('test = 0');
54 }
55
56 test_fileDoesNotExist() {
57 String file = '$projectPath/doesNotExist.dart';
58 return _checkInvalid(file, -1, -1);
59 }
60
61 test_fileWithoutContext() {
62 String file = '/outside.dart';
63 addFile(file, '''
64 main() {
65 print(42);
66 }
67 ''');
68 return _checkInvalid(file, -1, -1);
69 }
70
71 test_removeContextAfterRequest() async {
72 addTestFile('''
73 main() {
74 var test = 0;
75 print(test);
76 }
77 ''');
78 // handle the request synchronously
79 Request request =
80 _createGetNavigationRequest(testFile, testCode.indexOf('test);'), 0);
81 server.handleRequest(request);
82 // remove context, causes sending an "invalid file" error
83 {
84 Folder projectFolder = resourceProvider.getResource(projectPath);
85 server.contextDirectoryManager.removeContext(projectFolder);
86 }
87 // wait for an error response
88 Response response = await serverChannel.waitForResponse(request);
89 expect(response.error, isNotNull);
90 expect(response.error.code, RequestErrorCode.GET_NAVIGATION_INVALID_FILE);
91 }
92
93 _checkInvalid(String file, int offset, int length) async {
94 Request request = _createGetNavigationRequest(file, offset, length);
95 Response response = await serverChannel.sendRequest(request);
96 expect(response.error, isNotNull);
97 expect(response.error.code, RequestErrorCode.GET_NAVIGATION_INVALID_FILE);
98 }
99
100 Request _createGetNavigationRequest(String file, int offset, int length) {
101 return new AnalysisGetNavigationParams(file, offset, length)
102 .toRequest(requestId);
103 }
104
105 _getNavigation(String file, int offset, int length) async {
106 Request request = _createGetNavigationRequest(file, offset, length);
107 Response response = await serverChannel.sendRequest(request);
108 AnalysisGetNavigationResult result =
109 new AnalysisGetNavigationResult.fromResponse(response);
110 targetFiles = result.files;
111 targets = result.targets;
112 regions = result.regions;
113 }
114 }
OLDNEW
« 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