Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(787)

Side by Side Diff: pkg/analysis_server/test/src/computer/imported_elements_computer_test.dart

Issue 3002643002: Fix insertion of imports when there are no existing directives (issue 30430) (Closed)
Patch Set: Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 List<ImportedElements> elementsList = await _computeElements( 125 List<ImportedElements> elementsList = await _computeElements(
126 content, content.indexOf(selection), selection.length); 126 content, content.indexOf(selection), selection.length);
127 expect(elementsList, hasLength(1)); 127 expect(elementsList, hasLength(1));
128 ImportedElements elements = elementsList[0]; 128 ImportedElements elements = elementsList[0];
129 expect(elements, isNotNull); 129 expect(elements, isNotNull);
130 expect(elements.path, '/lib/core/core.dart'); 130 expect(elements.path, '/lib/core/core.dart');
131 expect(elements.prefix, 'core'); 131 expect(elements.prefix, 'core');
132 expect(elements.elements, unorderedEquals(['String'])); 132 expect(elements.elements, unorderedEquals(['String']));
133 } 133 }
134 134
135 test_dartMath_noPrefix() async {
136 String selection = "new Random();";
137 String content = """
138 import 'dart:math';
139 bool randomBool() {
140 Random r = $selection
141 return r.nextBool();
142 }
143 """;
144 List<ImportedElements> elementsList = await _computeElements(
145 content, content.indexOf(selection), selection.length);
146 expect(elementsList, hasLength(1));
147 ImportedElements elements = elementsList[0];
148 expect(elements, isNotNull);
149 expect(elements.path, '/lib/math/math.dart');
150 expect(elements.prefix, '');
151 expect(elements.elements, unorderedEquals(['Random']));
152 }
153
135 test_none_comment() async { 154 test_none_comment() async {
136 String selection = 'comment'; 155 String selection = 'comment';
137 String content = """ 156 String content = """
138 // Method $selection. 157 // Method $selection.
139 blankLine() { 158 blankLine() {
140 print(''); 159 print('');
141 } 160 }
142 """; 161 """;
143 List<ImportedElements> elementsList = await _computeElements( 162 List<ImportedElements> elementsList = await _computeElements(
144 content, content.indexOf(selection), selection.length); 163 content, content.indexOf(selection), selection.length);
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 346
328 Future<List<ImportedElements>> _computeElements( 347 Future<List<ImportedElements>> _computeElements(
329 String sourceContent, int offset, int length) async { 348 String sourceContent, int offset, int length) async {
330 provider.newFile(sourcePath, sourceContent); 349 provider.newFile(sourcePath, sourceContent);
331 ResolveResult result = await driver.getResult(sourcePath); 350 ResolveResult result = await driver.getResult(sourcePath);
332 ImportedElementsComputer computer = 351 ImportedElementsComputer computer =
333 new ImportedElementsComputer(result.unit, offset, length); 352 new ImportedElementsComputer(result.unit, offset, length);
334 return computer.compute(); 353 return computer.compute();
335 } 354 }
336 } 355 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698