| OLD | NEW |
| (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.domain.analysis.hover; | |
| 6 | |
| 7 import 'dart:async'; | |
| 8 | |
| 9 import 'package:analysis_server/src/protocol.dart'; | |
| 10 import 'reflective_tests.dart'; | |
| 11 import 'package:unittest/unittest.dart'; | |
| 12 | |
| 13 import 'analysis_abstract.dart'; | |
| 14 | |
| 15 | |
| 16 main() { | |
| 17 groupSep = ' | '; | |
| 18 runReflectiveTests(AnalysisHoverTest); | |
| 19 } | |
| 20 | |
| 21 | |
| 22 @ReflectiveTestCase() | |
| 23 class AnalysisHoverTest extends AbstractAnalysisTest { | |
| 24 Future<HoverInformation> prepareHover(String search) { | |
| 25 int offset = findOffset(search); | |
| 26 return prepareHoverAt(offset); | |
| 27 } | |
| 28 | |
| 29 Future<HoverInformation> prepareHoverAt(int offset) { | |
| 30 return waitForTasksFinished().then((_) { | |
| 31 Request request = new AnalysisGetHoverParams(testFile, | |
| 32 offset).toRequest('0'); | |
| 33 Response response = handleSuccessfulRequest(request); | |
| 34 var result = new AnalysisGetHoverResult.fromResponse(response); | |
| 35 List<HoverInformation> hovers = result.hovers; | |
| 36 return hovers.isNotEmpty ? hovers.first : null; | |
| 37 }); | |
| 38 } | |
| 39 | |
| 40 @override | |
| 41 void setUp() { | |
| 42 super.setUp(); | |
| 43 createProject(); | |
| 44 } | |
| 45 | |
| 46 test_dartdoc_clunky() { | |
| 47 addTestFile(''' | |
| 48 library my.library; | |
| 49 /** | |
| 50 * doc aaa | |
| 51 * doc bbb | |
| 52 */ | |
| 53 main() { | |
| 54 } | |
| 55 '''); | |
| 56 return prepareHover('main() {').then((HoverInformation hover) { | |
| 57 expect(hover.dartdoc, '''doc aaa\ndoc bbb'''); | |
| 58 }); | |
| 59 } | |
| 60 | |
| 61 test_dartdoc_elegant() { | |
| 62 addTestFile(''' | |
| 63 library my.library; | |
| 64 /// doc aaa | |
| 65 /// doc bbb | |
| 66 main() { | |
| 67 } | |
| 68 '''); | |
| 69 return prepareHover('main() {').then((HoverInformation hover) { | |
| 70 expect(hover.dartdoc, '''doc aaa\ndoc bbb'''); | |
| 71 }); | |
| 72 } | |
| 73 | |
| 74 test_expression_function() { | |
| 75 addTestFile(''' | |
| 76 library my.library; | |
| 77 /// doc aaa | |
| 78 /// doc bbb | |
| 79 List<String> fff(int a, String b) { | |
| 80 } | |
| 81 '''); | |
| 82 return prepareHover('fff(int a').then((HoverInformation hover) { | |
| 83 // element | |
| 84 expect(hover.containingLibraryName, 'my.library'); | |
| 85 expect(hover.containingLibraryPath, testFile); | |
| 86 expect(hover.dartdoc, '''doc aaa\ndoc bbb'''); | |
| 87 expect(hover.elementDescription, 'fff(int a, String b) → List<String>'); | |
| 88 expect(hover.elementKind, 'function'); | |
| 89 // types | |
| 90 expect(hover.staticType, '(int, String) → List<String>'); | |
| 91 expect(hover.propagatedType, isNull); | |
| 92 // no parameter | |
| 93 expect(hover.parameter, isNull); | |
| 94 }); | |
| 95 } | |
| 96 | |
| 97 test_expression_literal_noElement() { | |
| 98 addTestFile(''' | |
| 99 main() { | |
| 100 foo(123); | |
| 101 } | |
| 102 foo(Object myParameter) {} | |
| 103 '''); | |
| 104 return prepareHover('123').then((HoverInformation hover) { | |
| 105 // literal, no Element | |
| 106 expect(hover.elementDescription, isNull); | |
| 107 expect(hover.elementKind, isNull); | |
| 108 // types | |
| 109 expect(hover.staticType, 'int'); | |
| 110 expect(hover.propagatedType, isNull); | |
| 111 // parameter | |
| 112 expect(hover.parameter, 'Object myParameter'); | |
| 113 }); | |
| 114 } | |
| 115 | |
| 116 test_expression_method() { | |
| 117 addTestFile(''' | |
| 118 library my.library; | |
| 119 class A { | |
| 120 /// doc aaa | |
| 121 /// doc bbb | |
| 122 List<String> mmm(int a, String b) { | |
| 123 } | |
| 124 } | |
| 125 '''); | |
| 126 return prepareHover('mmm(int a').then((HoverInformation hover) { | |
| 127 // element | |
| 128 expect(hover.containingLibraryName, 'my.library'); | |
| 129 expect(hover.containingLibraryPath, testFile); | |
| 130 expect(hover.dartdoc, '''doc aaa\ndoc bbb'''); | |
| 131 expect(hover.elementDescription, 'A.mmm(int a, String b) → List<String>'); | |
| 132 expect(hover.elementKind, 'method'); | |
| 133 // types | |
| 134 expect(hover.staticType, '(int, String) → List<String>'); | |
| 135 expect(hover.propagatedType, isNull); | |
| 136 // no parameter | |
| 137 expect(hover.parameter, isNull); | |
| 138 }); | |
| 139 } | |
| 140 | |
| 141 test_expression_method_nvocation() { | |
| 142 addTestFile(''' | |
| 143 library my.library; | |
| 144 class A { | |
| 145 List<String> mmm(int a, String b) { | |
| 146 } | |
| 147 } | |
| 148 main(A a) { | |
| 149 a.mmm(42, 'foo'); | |
| 150 } | |
| 151 '''); | |
| 152 return prepareHover('mm(42, ').then((HoverInformation hover) { | |
| 153 // range | |
| 154 expect(hover.offset, findOffset('mmm(42, ')); | |
| 155 expect(hover.length, 'mmm'.length); | |
| 156 // element | |
| 157 expect(hover.containingLibraryName, 'my.library'); | |
| 158 expect(hover.containingLibraryPath, testFile); | |
| 159 expect(hover.elementDescription, 'A.mmm(int a, String b) → List<String>'); | |
| 160 expect(hover.elementKind, 'method'); | |
| 161 // types | |
| 162 expect(hover.staticType, isNull); | |
| 163 expect(hover.propagatedType, isNull); | |
| 164 // no parameter | |
| 165 expect(hover.parameter, isNull); | |
| 166 }); | |
| 167 } | |
| 168 | |
| 169 test_expression_syntheticGetter() { | |
| 170 addTestFile(''' | |
| 171 library my.library; | |
| 172 class A { | |
| 173 /// doc aaa | |
| 174 /// doc bbb | |
| 175 String fff; | |
| 176 } | |
| 177 main(A a) { | |
| 178 print(a.fff); | |
| 179 } | |
| 180 '''); | |
| 181 return prepareHover('fff);').then((HoverInformation hover) { | |
| 182 // element | |
| 183 expect(hover.containingLibraryName, 'my.library'); | |
| 184 expect(hover.containingLibraryPath, testFile); | |
| 185 expect(hover.dartdoc, '''doc aaa\ndoc bbb'''); | |
| 186 expect(hover.elementDescription, 'String fff'); | |
| 187 expect(hover.elementKind, 'field'); | |
| 188 // types | |
| 189 expect(hover.staticType, 'String'); | |
| 190 expect(hover.propagatedType, isNull); | |
| 191 }); | |
| 192 } | |
| 193 | |
| 194 test_expression_variable_hasPropagatedType() { | |
| 195 addTestFile(''' | |
| 196 library my.library; | |
| 197 main() { | |
| 198 var vvv = 123; | |
| 199 print(vvv); | |
| 200 } | |
| 201 '''); | |
| 202 return prepareHover('vvv);').then((HoverInformation hover) { | |
| 203 // element | |
| 204 expect(hover.containingLibraryName, 'my.library'); | |
| 205 expect(hover.containingLibraryPath, testFile); | |
| 206 expect(hover.dartdoc, isNull); | |
| 207 expect(hover.elementDescription, 'dynamic vvv'); | |
| 208 expect(hover.elementKind, 'local variable'); | |
| 209 // types | |
| 210 expect(hover.staticType, 'dynamic'); | |
| 211 expect(hover.propagatedType, 'int'); | |
| 212 }); | |
| 213 } | |
| 214 | |
| 215 test_noHoverInfo() { | |
| 216 addTestFile(''' | |
| 217 library my.library; | |
| 218 main() { | |
| 219 // nothing | |
| 220 } | |
| 221 '''); | |
| 222 return prepareHover('nothing').then((HoverInformation hover) { | |
| 223 expect(hover, isNull); | |
| 224 }); | |
| 225 } | |
| 226 } | |
| OLD | NEW |