| OLD | NEW |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 import 'dart:async'; | 5 import 'dart:async'; |
| 6 | 6 |
| 7 import 'package:analysis_server/protocol/protocol_generated.dart'; | 7 import 'package:analysis_server/protocol/protocol_generated.dart'; |
| 8 import 'package:analysis_server/src/computer/imported_elements_computer.dart'; | 8 import 'package:analysis_server/src/computer/imported_elements_computer.dart'; |
| 9 import 'package:analyzer/dart/analysis/results.dart'; | 9 import 'package:analyzer/dart/analysis/results.dart'; |
| 10 import 'package:test/test.dart'; | 10 import 'package:test/test.dart'; |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 List<ImportedElements> elementsList = await _computeElements( | 144 List<ImportedElements> elementsList = await _computeElements( |
| 145 content, content.indexOf(selection), selection.length); | 145 content, content.indexOf(selection), selection.length); |
| 146 expect(elementsList, hasLength(1)); | 146 expect(elementsList, hasLength(1)); |
| 147 ImportedElements elements = elementsList[0]; | 147 ImportedElements elements = elementsList[0]; |
| 148 expect(elements, isNotNull); | 148 expect(elements, isNotNull); |
| 149 expect(elements.path, '/lib/math/math.dart'); | 149 expect(elements.path, '/lib/math/math.dart'); |
| 150 expect(elements.prefix, ''); | 150 expect(elements.prefix, ''); |
| 151 expect(elements.elements, unorderedEquals(['Random'])); | 151 expect(elements.elements, unorderedEquals(['Random'])); |
| 152 } | 152 } |
| 153 | 153 |
| 154 test_multiple() async { |
| 155 String selection = r''' |
| 156 main() { |
| 157 Random r = new Random(); |
| 158 String s = r.nextBool().toString(); |
| 159 print(s); |
| 160 } |
| 161 '''; |
| 162 String content = ''' |
| 163 import 'dart:math'; |
| 164 |
| 165 $selection |
| 166 '''; |
| 167 List<ImportedElements> elementsList = await _computeElements( |
| 168 content, content.indexOf(selection), selection.length); |
| 169 expect(elementsList, hasLength(2)); |
| 170 |
| 171 ImportedElements mathElements = elementsList[0]; |
| 172 expect(mathElements, isNotNull); |
| 173 expect(mathElements.path, '/lib/math/math.dart'); |
| 174 expect(mathElements.prefix, ''); |
| 175 expect(mathElements.elements, unorderedEquals(['Random'])); |
| 176 |
| 177 ImportedElements coreElements = elementsList[1]; |
| 178 expect(coreElements, isNotNull); |
| 179 expect(coreElements.path, '/lib/core/core.dart'); |
| 180 expect(coreElements.prefix, ''); |
| 181 expect(coreElements.elements, unorderedEquals(['String', 'print'])); |
| 182 } |
| 183 |
| 154 test_none_comment() async { | 184 test_none_comment() async { |
| 155 String selection = 'comment'; | 185 String selection = 'comment'; |
| 156 String content = """ | 186 String content = """ |
| 157 // Method $selection. | 187 // Method $selection. |
| 158 blankLine() { | 188 blankLine() { |
| 159 print(''); | 189 print(''); |
| 160 } | 190 } |
| 161 """; | 191 """; |
| 162 List<ImportedElements> elementsList = await _computeElements( | 192 List<ImportedElements> elementsList = await _computeElements( |
| 163 content, content.indexOf(selection), selection.length); | 193 content, content.indexOf(selection), selection.length); |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 | 376 |
| 347 Future<List<ImportedElements>> _computeElements( | 377 Future<List<ImportedElements>> _computeElements( |
| 348 String sourceContent, int offset, int length) async { | 378 String sourceContent, int offset, int length) async { |
| 349 provider.newFile(sourcePath, sourceContent); | 379 provider.newFile(sourcePath, sourceContent); |
| 350 ResolveResult result = await driver.getResult(sourcePath); | 380 ResolveResult result = await driver.getResult(sourcePath); |
| 351 ImportedElementsComputer computer = | 381 ImportedElementsComputer computer = |
| 352 new ImportedElementsComputer(result.unit, offset, length); | 382 new ImportedElementsComputer(result.unit, offset, length); |
| 353 return computer.compute(); | 383 return computer.compute(); |
| 354 } | 384 } |
| 355 } | 385 } |
| OLD | NEW |