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

Side by Side Diff: pkg/analysis_server/test/integration/analysis/get_imported_elements_test.dart

Issue 3001733002: Correctly handle adding imports when pasting into part files (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:path/path.dart' as path;
8 import 'package:test/test.dart'; 9 import 'package:test/test.dart';
9 import 'package:test_reflective_loader/test_reflective_loader.dart'; 10 import 'package:test_reflective_loader/test_reflective_loader.dart';
10 11
11 import '../support/integration_tests.dart'; 12 import '../support/integration_tests.dart';
12 13
13 main() { 14 main() {
14 defineReflectiveSuite(() { 15 defineReflectiveSuite(() {
15 defineReflectiveTests(AnalysisGetImportedElementsIntegrationTest); 16 defineReflectiveTests(AnalysisGetImportedElementsIntegrationTest);
16 }); 17 });
17 } 18 }
(...skipping 12 matching lines...) Expand all
30 String text; 31 String text;
31 32
32 /** 33 /**
33 * Check that an analysis.getImportedElements request on the region starting 34 * Check that an analysis.getImportedElements request on the region starting
34 * with the first character that matches [target] and having the given 35 * with the first character that matches [target] and having the given
35 * [length] matches the given list of [expected] imported elements. 36 * [length] matches the given list of [expected] imported elements.
36 */ 37 */
37 checkElements(String target, List<ImportedElements> expected) async { 38 checkElements(String target, List<ImportedElements> expected) async {
38 bool equals( 39 bool equals(
39 ImportedElements actualElements, ImportedElements expectedElements) { 40 ImportedElements actualElements, ImportedElements expectedElements) {
40 // We can't test the path because the paths are relative to a generated 41 if (actualElements.path.endsWith(expectedElements.path) &&
41 // temporary directory. 42 actualElements.prefix == expectedElements.prefix) {
42 if (actualElements.prefix == expectedElements.prefix) {
43 List<String> actual = actualElements.elements; 43 List<String> actual = actualElements.elements;
44 List<String> expected = expectedElements.elements; 44 List<String> expected = expectedElements.elements;
45 if (actual.length == expected.length) { 45 if (actual.length == expected.length) {
46 for (int i = 0; i < actual.length; i++) { 46 for (int i = 0; i < actual.length; i++) {
47 if (!expected.contains(actual[i])) { 47 if (!expected.contains(actual[i])) {
48 return false; 48 return false;
49 } 49 }
50 } 50 }
51 return true; 51 return true;
52 } 52 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 } 98 }
99 99
100 test_getImportedElements_none() async { 100 test_getImportedElements_none() async {
101 text = r''' 101 text = r'''
102 main() {} 102 main() {}
103 '''; 103 ''';
104 writeFile(pathname, text); 104 writeFile(pathname, text);
105 standardAnalysisSetup(); 105 standardAnalysisSetup();
106 await analysisFinished; 106 await analysisFinished;
107 107
108 List<Future> tests = []; 108 await checkNoElements('main() {}');
109 tests.add(checkNoElements('main() {}'));
110 return Future.wait(tests);
111 } 109 }
112 110
113 test_getImportedElements_some() async { 111 test_getImportedElements_some() async {
114 text = r''' 112 String selection = r'''
115 main() { 113 main() {
116 String s = ''; 114 Random r = new Random();
115 String s = r.nextBool().toString();
117 print(s); 116 print(s);
118 } 117 }
119 '''; 118 ''';
119 text = '''
120 import 'dart:math';
121
122 $selection
123 ''';
120 writeFile(pathname, text); 124 writeFile(pathname, text);
121 standardAnalysisSetup(); 125 standardAnalysisSetup();
122 await analysisFinished; 126 await analysisFinished;
123 127
124 List<Future> tests = []; 128 await checkElements(selection, [
125 tests.add(checkElements(text, [ 129 new ImportedElements(
126 new ImportedElements('', '', ['String', 'print']) 130 path.join('lib', 'core', 'core.dart'), '', ['String', 'print']),
127 ])); 131 new ImportedElements(
128 return Future.wait(tests); 132 path.join('lib', 'math', 'math.dart'), '', ['Random'])
133 ]);
129 } 134 }
130 } 135 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698