| 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'; | 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'; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 /// doc bbb | 88 /// doc bbb |
| 89 List<String> fff(int a, String b) { | 89 List<String> fff(int a, String b) { |
| 90 } | 90 } |
| 91 '''); | 91 '''); |
| 92 return prepareHover('fff(int a', () { | 92 return prepareHover('fff(int a', () { |
| 93 // element | 93 // element |
| 94 expect(hover.containingLibraryName, 'my.library'); | 94 expect(hover.containingLibraryName, 'my.library'); |
| 95 expect(hover.containingLibraryPath, testFile); | 95 expect(hover.containingLibraryPath, testFile); |
| 96 expect(hover.dartDoc, '''doc aaa\ndoc bbb'''); | 96 expect(hover.dartDoc, '''doc aaa\ndoc bbb'''); |
| 97 expect(hover.elementDescription, 'fff(int a, String b) → List<String>'); | 97 expect(hover.elementDescription, 'fff(int a, String b) → List<String>'); |
| 98 expect(hover.elementKind, 'function'); |
| 98 // types | 99 // types |
| 99 expect(hover.staticType, '(int, String) → List<String>'); | 100 expect(hover.staticType, '(int, String) → List<String>'); |
| 100 expect(hover.propagatedType, isNull); | 101 expect(hover.propagatedType, isNull); |
| 101 // no parameter | 102 // no parameter |
| 102 expect(hover.parameter, isNull); | 103 expect(hover.parameter, isNull); |
| 103 }); | 104 }); |
| 104 } | 105 } |
| 105 | 106 |
| 106 test_expression_literal_noElement() { | 107 test_expression_literal_noElement() { |
| 107 addTestFile(''' | 108 addTestFile(''' |
| 108 main() { | 109 main() { |
| 109 foo(123); | 110 foo(123); |
| 110 } | 111 } |
| 111 foo(Object myParameter) {} | 112 foo(Object myParameter) {} |
| 112 '''); | 113 '''); |
| 113 return prepareHover('123', () { | 114 return prepareHover('123', () { |
| 114 // literal, no Element | 115 // literal, no Element |
| 115 expect(hover.elementDescription, isNull); | 116 expect(hover.elementDescription, isNull); |
| 117 expect(hover.elementKind, isNull); |
| 116 // types | 118 // types |
| 117 expect(hover.staticType, 'int'); | 119 expect(hover.staticType, 'int'); |
| 118 expect(hover.propagatedType, isNull); | 120 expect(hover.propagatedType, isNull); |
| 119 // parameter | 121 // parameter |
| 120 expect(hover.parameter, 'Object myParameter'); | 122 expect(hover.parameter, 'Object myParameter'); |
| 121 }); | 123 }); |
| 122 } | 124 } |
| 123 | 125 |
| 124 test_expression_method() { | 126 test_expression_method() { |
| 125 addTestFile(''' | 127 addTestFile(''' |
| 126 library my.library; | 128 library my.library; |
| 127 class A { | 129 class A { |
| 128 /// doc aaa | 130 /// doc aaa |
| 129 /// doc bbb | 131 /// doc bbb |
| 130 List<String> mmm(int a, String b) { | 132 List<String> mmm(int a, String b) { |
| 131 } | 133 } |
| 132 } | 134 } |
| 133 '''); | 135 '''); |
| 134 return prepareHover('mmm(int a', () { | 136 return prepareHover('mmm(int a', () { |
| 135 // element | 137 // element |
| 136 expect(hover.containingLibraryName, 'my.library'); | 138 expect(hover.containingLibraryName, 'my.library'); |
| 137 expect(hover.containingLibraryPath, testFile); | 139 expect(hover.containingLibraryPath, testFile); |
| 138 expect(hover.dartDoc, '''doc aaa\ndoc bbb'''); | 140 expect(hover.dartDoc, '''doc aaa\ndoc bbb'''); |
| 139 expect(hover.elementDescription, 'A.mmm(int a, String b) → List<String>'); | 141 expect(hover.elementDescription, 'A.mmm(int a, String b) → List<String>'); |
| 142 expect(hover.elementKind, 'method'); |
| 140 // types | 143 // types |
| 141 expect(hover.staticType, '(int, String) → List<String>'); | 144 expect(hover.staticType, '(int, String) → List<String>'); |
| 142 expect(hover.propagatedType, isNull); | 145 expect(hover.propagatedType, isNull); |
| 143 // no parameter | 146 // no parameter |
| 144 expect(hover.parameter, isNull); | 147 expect(hover.parameter, isNull); |
| 145 }); | 148 }); |
| 146 } | 149 } |
| 147 | 150 |
| 151 test_expression_method_nvocation() { |
| 152 addTestFile(''' |
| 153 library my.library; |
| 154 class A { |
| 155 List<String> mmm(int a, String b) { |
| 156 } |
| 157 } |
| 158 main(A a) { |
| 159 a.mmm(42, 'foo'); |
| 160 } |
| 161 '''); |
| 162 return prepareHover('mm(42, ', () { |
| 163 // range |
| 164 expect(hover.offset, findOffset('mmm(42, ')); |
| 165 expect(hover.length, 'mmm'.length); |
| 166 // element |
| 167 expect(hover.containingLibraryName, 'my.library'); |
| 168 expect(hover.containingLibraryPath, testFile); |
| 169 expect(hover.elementDescription, 'A.mmm(int a, String b) → List<String>'); |
| 170 expect(hover.elementKind, 'method'); |
| 171 // types |
| 172 expect(hover.staticType, isNull); |
| 173 expect(hover.propagatedType, isNull); |
| 174 // no parameter |
| 175 expect(hover.parameter, isNull); |
| 176 }); |
| 177 } |
| 178 |
| 148 test_expression_syntheticGetter() { | 179 test_expression_syntheticGetter() { |
| 149 addTestFile(''' | 180 addTestFile(''' |
| 150 library my.library; | 181 library my.library; |
| 151 class A { | 182 class A { |
| 152 /// doc aaa | 183 /// doc aaa |
| 153 /// doc bbb | 184 /// doc bbb |
| 154 String fff; | 185 String fff; |
| 155 } | 186 } |
| 156 main(A a) { | 187 main(A a) { |
| 157 print(a.fff); | 188 print(a.fff); |
| 158 } | 189 } |
| 159 '''); | 190 '''); |
| 160 return prepareHover('fff);', () { | 191 return prepareHover('fff);', () { |
| 161 // element | 192 // element |
| 162 expect(hover.containingLibraryName, 'my.library'); | 193 expect(hover.containingLibraryName, 'my.library'); |
| 163 expect(hover.containingLibraryPath, testFile); | 194 expect(hover.containingLibraryPath, testFile); |
| 164 expect(hover.dartDoc, '''doc aaa\ndoc bbb'''); | 195 expect(hover.dartDoc, '''doc aaa\ndoc bbb'''); |
| 165 expect(hover.elementDescription, 'String fff'); | 196 expect(hover.elementDescription, 'String fff'); |
| 197 expect(hover.elementKind, 'field'); |
| 166 // types | 198 // types |
| 167 expect(hover.staticType, 'String'); | 199 expect(hover.staticType, 'String'); |
| 168 expect(hover.propagatedType, isNull); | 200 expect(hover.propagatedType, isNull); |
| 169 }); | 201 }); |
| 170 } | 202 } |
| 171 | 203 |
| 172 test_expression_variable_hasPropagatedType() { | 204 test_expression_variable_hasPropagatedType() { |
| 173 addTestFile(''' | 205 addTestFile(''' |
| 174 library my.library; | 206 library my.library; |
| 175 main() { | 207 main() { |
| 176 var vvv = 123; | 208 var vvv = 123; |
| 177 print(vvv); | 209 print(vvv); |
| 178 } | 210 } |
| 179 '''); | 211 '''); |
| 180 return prepareHover('vvv);', () { | 212 return prepareHover('vvv);', () { |
| 181 // element | 213 // element |
| 182 expect(hover.containingLibraryName, 'my.library'); | 214 expect(hover.containingLibraryName, 'my.library'); |
| 183 expect(hover.containingLibraryPath, testFile); | 215 expect(hover.containingLibraryPath, testFile); |
| 184 expect(hover.dartDoc, isNull); | 216 expect(hover.dartDoc, isNull); |
| 185 expect(hover.elementDescription, 'dynamic vvv'); | 217 expect(hover.elementDescription, 'dynamic vvv'); |
| 218 expect(hover.elementKind, 'local variable'); |
| 186 // types | 219 // types |
| 187 expect(hover.staticType, 'dynamic'); | 220 expect(hover.staticType, 'dynamic'); |
| 188 expect(hover.propagatedType, 'int'); | 221 expect(hover.propagatedType, 'int'); |
| 189 }); | 222 }); |
| 190 } | 223 } |
| 191 } | 224 } |
| OLD | NEW |