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

Side by Side Diff: pkg/analysis_server/test/analysis_hover_test.dart

Issue 407443002: Fix analysis server 'analysis.getHover' when there is no hover information. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library test.domain.analysis.hover; 5 library test.domain.analysis.hover;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/src/computer/computer_hover.dart'; 9 import 'package:analysis_server/src/computer/computer_hover.dart';
10 import 'package:analysis_server/src/constants.dart'; 10 import 'package:analysis_server/src/constants.dart';
11 import 'package:analysis_server/src/protocol.dart'; 11 import 'package:analysis_server/src/protocol.dart';
12 import 'package:analysis_testing/reflective_tests.dart'; 12 import 'package:analysis_testing/reflective_tests.dart';
13 import 'package:unittest/unittest.dart'; 13 import 'package:unittest/unittest.dart';
14 14
15 import 'analysis_abstract.dart'; 15 import 'analysis_abstract.dart';
16 16
17 17
18 main() { 18 main() {
19 group('notification.hover', () { 19 group('notification.hover', () {
20 runReflectiveTests(AnalysisHoverTest); 20 runReflectiveTests(AnalysisHoverTest);
21 }); 21 });
22 } 22 }
23 23
24 24
25 @ReflectiveTestCase() 25 @ReflectiveTestCase()
26 class AnalysisHoverTest extends AbstractAnalysisTest { 26 class AnalysisHoverTest extends AbstractAnalysisTest {
27 List<Hover> hovers; 27 Future<Hover> prepareHover(String search) {
28 Hover hover;
29
30 Future prepareHover(String search, then()) {
31 int offset = findOffset(search); 28 int offset = findOffset(search);
32 return prepareHoverAt(offset, then); 29 return prepareHoverAt(offset);
33 } 30 }
34 31
35 Future prepareHoverAt(int offset, then()) { 32 Future<Hover> prepareHoverAt(int offset) {
36 return waitForTasksFinished().then((_) { 33 return waitForTasksFinished().then((_) {
37 Request request = new Request('0', ANALYSIS_GET_HOVER); 34 Request request = new Request('0', ANALYSIS_GET_HOVER);
38 request.setParameter(FILE, testFile); 35 request.setParameter(FILE, testFile);
39 request.setParameter(OFFSET, offset); 36 request.setParameter(OFFSET, offset);
40 Response response = handleSuccessfulRequest(request); 37 Response response = handleSuccessfulRequest(request);
41 List<Map<String, Object>> hoverJsons = response.getResult(HOVERS); 38 List<Map<String, Object>> hoverJsons = response.getResult(HOVERS);
42 hovers = hoverJsons.map((json) { 39 List<Hover> hovers = hoverJsons.map((json) {
43 return new Hover.fromJson(json); 40 return new Hover.fromJson(json);
44 }).toList(); 41 }).toList();
45 hover = hovers.isNotEmpty ? hovers.first : null; 42 return hovers.isNotEmpty ? hovers.first : null;
46 then();
47 }); 43 });
48 } 44 }
49 45
50 @override 46 @override
51 void setUp() { 47 void setUp() {
52 super.setUp(); 48 super.setUp();
53 createProject(); 49 createProject();
54 } 50 }
55 51
56 test_dartDoc_clunky() { 52 test_dartDoc_clunky() {
57 addTestFile(''' 53 addTestFile('''
58 library my.library; 54 library my.library;
59 /** 55 /**
60 * doc aaa 56 * doc aaa
61 * doc bbb 57 * doc bbb
62 */ 58 */
63 main() { 59 main() {
64 } 60 }
65 '''); 61 ''');
66 return prepareHover('main() {', () { 62 return prepareHover('main() {').then((Hover hover) {
67 expect(hover.dartDoc, '''doc aaa\ndoc bbb'''); 63 expect(hover.dartDoc, '''doc aaa\ndoc bbb''');
68 }); 64 });
69 } 65 }
70 66
71 test_dartDoc_elegant() { 67 test_dartDoc_elegant() {
72 addTestFile(''' 68 addTestFile('''
73 library my.library; 69 library my.library;
74 /// doc aaa 70 /// doc aaa
75 /// doc bbb 71 /// doc bbb
76 main() { 72 main() {
77 } 73 }
78 '''); 74 ''');
79 return prepareHover('main() {', () { 75 return prepareHover('main() {').then((Hover hover) {
80 expect(hover.dartDoc, '''doc aaa\ndoc bbb'''); 76 expect(hover.dartDoc, '''doc aaa\ndoc bbb''');
81 }); 77 });
82 } 78 }
83 79
84 test_expression_function() { 80 test_expression_function() {
85 addTestFile(''' 81 addTestFile('''
86 library my.library; 82 library my.library;
87 /// doc aaa 83 /// doc aaa
88 /// doc bbb 84 /// doc bbb
89 List<String> fff(int a, String b) { 85 List<String> fff(int a, String b) {
90 } 86 }
91 '''); 87 ''');
92 return prepareHover('fff(int a', () { 88 return prepareHover('fff(int a').then((Hover hover) {
93 // element 89 // element
94 expect(hover.containingLibraryName, 'my.library'); 90 expect(hover.containingLibraryName, 'my.library');
95 expect(hover.containingLibraryPath, testFile); 91 expect(hover.containingLibraryPath, testFile);
96 expect(hover.dartDoc, '''doc aaa\ndoc bbb'''); 92 expect(hover.dartDoc, '''doc aaa\ndoc bbb''');
97 expect(hover.elementDescription, 'fff(int a, String b) → List<String>'); 93 expect(hover.elementDescription, 'fff(int a, String b) → List<String>');
98 expect(hover.elementKind, 'function'); 94 expect(hover.elementKind, 'function');
99 // types 95 // types
100 expect(hover.staticType, '(int, String) → List<String>'); 96 expect(hover.staticType, '(int, String) → List<String>');
101 expect(hover.propagatedType, isNull); 97 expect(hover.propagatedType, isNull);
102 // no parameter 98 // no parameter
103 expect(hover.parameter, isNull); 99 expect(hover.parameter, isNull);
104 }); 100 });
105 } 101 }
106 102
107 test_expression_literal_noElement() { 103 test_expression_literal_noElement() {
108 addTestFile(''' 104 addTestFile('''
109 main() { 105 main() {
110 foo(123); 106 foo(123);
111 } 107 }
112 foo(Object myParameter) {} 108 foo(Object myParameter) {}
113 '''); 109 ''');
114 return prepareHover('123', () { 110 return prepareHover('123').then((Hover hover) {
115 // literal, no Element 111 // literal, no Element
116 expect(hover.elementDescription, isNull); 112 expect(hover.elementDescription, isNull);
117 expect(hover.elementKind, isNull); 113 expect(hover.elementKind, isNull);
118 // types 114 // types
119 expect(hover.staticType, 'int'); 115 expect(hover.staticType, 'int');
120 expect(hover.propagatedType, isNull); 116 expect(hover.propagatedType, isNull);
121 // parameter 117 // parameter
122 expect(hover.parameter, 'Object myParameter'); 118 expect(hover.parameter, 'Object myParameter');
123 }); 119 });
124 } 120 }
125 121
126 test_expression_method() { 122 test_expression_method() {
127 addTestFile(''' 123 addTestFile('''
128 library my.library; 124 library my.library;
129 class A { 125 class A {
130 /// doc aaa 126 /// doc aaa
131 /// doc bbb 127 /// doc bbb
132 List<String> mmm(int a, String b) { 128 List<String> mmm(int a, String b) {
133 } 129 }
134 } 130 }
135 '''); 131 ''');
136 return prepareHover('mmm(int a', () { 132 return prepareHover('mmm(int a').then((Hover hover) {
137 // element 133 // element
138 expect(hover.containingLibraryName, 'my.library'); 134 expect(hover.containingLibraryName, 'my.library');
139 expect(hover.containingLibraryPath, testFile); 135 expect(hover.containingLibraryPath, testFile);
140 expect(hover.dartDoc, '''doc aaa\ndoc bbb'''); 136 expect(hover.dartDoc, '''doc aaa\ndoc bbb''');
141 expect(hover.elementDescription, 'A.mmm(int a, String b) → List<String>'); 137 expect(hover.elementDescription, 'A.mmm(int a, String b) → List<String>');
142 expect(hover.elementKind, 'method'); 138 expect(hover.elementKind, 'method');
143 // types 139 // types
144 expect(hover.staticType, '(int, String) → List<String>'); 140 expect(hover.staticType, '(int, String) → List<String>');
145 expect(hover.propagatedType, isNull); 141 expect(hover.propagatedType, isNull);
146 // no parameter 142 // no parameter
147 expect(hover.parameter, isNull); 143 expect(hover.parameter, isNull);
148 }); 144 });
149 } 145 }
150 146
151 test_expression_method_nvocation() { 147 test_expression_method_nvocation() {
152 addTestFile(''' 148 addTestFile('''
153 library my.library; 149 library my.library;
154 class A { 150 class A {
155 List<String> mmm(int a, String b) { 151 List<String> mmm(int a, String b) {
156 } 152 }
157 } 153 }
158 main(A a) { 154 main(A a) {
159 a.mmm(42, 'foo'); 155 a.mmm(42, 'foo');
160 } 156 }
161 '''); 157 ''');
162 return prepareHover('mm(42, ', () { 158 return prepareHover('mm(42, ').then((Hover hover) {
163 // range 159 // range
164 expect(hover.offset, findOffset('mmm(42, ')); 160 expect(hover.offset, findOffset('mmm(42, '));
165 expect(hover.length, 'mmm'.length); 161 expect(hover.length, 'mmm'.length);
166 // element 162 // element
167 expect(hover.containingLibraryName, 'my.library'); 163 expect(hover.containingLibraryName, 'my.library');
168 expect(hover.containingLibraryPath, testFile); 164 expect(hover.containingLibraryPath, testFile);
169 expect(hover.elementDescription, 'A.mmm(int a, String b) → List<String>'); 165 expect(hover.elementDescription, 'A.mmm(int a, String b) → List<String>');
170 expect(hover.elementKind, 'method'); 166 expect(hover.elementKind, 'method');
171 // types 167 // types
172 expect(hover.staticType, isNull); 168 expect(hover.staticType, isNull);
173 expect(hover.propagatedType, isNull); 169 expect(hover.propagatedType, isNull);
174 // no parameter 170 // no parameter
175 expect(hover.parameter, isNull); 171 expect(hover.parameter, isNull);
176 }); 172 });
177 } 173 }
178 174
179 test_expression_syntheticGetter() { 175 test_expression_syntheticGetter() {
180 addTestFile(''' 176 addTestFile('''
181 library my.library; 177 library my.library;
182 class A { 178 class A {
183 /// doc aaa 179 /// doc aaa
184 /// doc bbb 180 /// doc bbb
185 String fff; 181 String fff;
186 } 182 }
187 main(A a) { 183 main(A a) {
188 print(a.fff); 184 print(a.fff);
189 } 185 }
190 '''); 186 ''');
191 return prepareHover('fff);', () { 187 return prepareHover('fff);').then((Hover hover) {
192 // element 188 // element
193 expect(hover.containingLibraryName, 'my.library'); 189 expect(hover.containingLibraryName, 'my.library');
194 expect(hover.containingLibraryPath, testFile); 190 expect(hover.containingLibraryPath, testFile);
195 expect(hover.dartDoc, '''doc aaa\ndoc bbb'''); 191 expect(hover.dartDoc, '''doc aaa\ndoc bbb''');
196 expect(hover.elementDescription, 'String fff'); 192 expect(hover.elementDescription, 'String fff');
197 expect(hover.elementKind, 'field'); 193 expect(hover.elementKind, 'field');
198 // types 194 // types
199 expect(hover.staticType, 'String'); 195 expect(hover.staticType, 'String');
200 expect(hover.propagatedType, isNull); 196 expect(hover.propagatedType, isNull);
201 }); 197 });
202 } 198 }
203 199
204 test_expression_variable_hasPropagatedType() { 200 test_expression_variable_hasPropagatedType() {
205 addTestFile(''' 201 addTestFile('''
206 library my.library; 202 library my.library;
207 main() { 203 main() {
208 var vvv = 123; 204 var vvv = 123;
209 print(vvv); 205 print(vvv);
210 } 206 }
211 '''); 207 ''');
212 return prepareHover('vvv);', () { 208 return prepareHover('vvv);').then((Hover hover) {
213 // element 209 // element
214 expect(hover.containingLibraryName, 'my.library'); 210 expect(hover.containingLibraryName, 'my.library');
215 expect(hover.containingLibraryPath, testFile); 211 expect(hover.containingLibraryPath, testFile);
216 expect(hover.dartDoc, isNull); 212 expect(hover.dartDoc, isNull);
217 expect(hover.elementDescription, 'dynamic vvv'); 213 expect(hover.elementDescription, 'dynamic vvv');
218 expect(hover.elementKind, 'local variable'); 214 expect(hover.elementKind, 'local variable');
219 // types 215 // types
220 expect(hover.staticType, 'dynamic'); 216 expect(hover.staticType, 'dynamic');
221 expect(hover.propagatedType, 'int'); 217 expect(hover.propagatedType, 'int');
222 }); 218 });
223 } 219 }
220
221 test_noHoverInfo() {
222 addTestFile('''
223 library my.library;
224 main() {
225 // nothing
224 } 226 }
227 ''');
228 return prepareHover('nothing').then((Hover hover) {
229 expect(hover, isNull);
230 });
231 }
232 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/domain_analysis.dart ('k') | pkg/analysis_server/test/integration/analysis_domain_inttest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698