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