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