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

Side by Side Diff: pkg/analysis_server/test/services/correction/util_test.dart

Issue 2975253002: Format analyzer, analysis_server, analyzer_plugin, front_end and kernel with the latest dartfmt. (Closed)
Patch Set: Created 3 years, 5 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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 'package:analysis_server/src/services/correction/util.dart'; 5 import 'package:analysis_server/src/services/correction/util.dart';
6 import 'package:analyzer/src/generated/source.dart'; 6 import 'package:analyzer/src/generated/source.dart';
7 import 'package:analyzer_plugin/protocol/protocol_common.dart'; 7 import 'package:analyzer_plugin/protocol/protocol_common.dart';
8 import 'package:analyzer_plugin/src/utilities/string_utilities.dart'; 8 import 'package:analyzer_plugin/src/utilities/string_utilities.dart';
9 import 'package:test/test.dart'; 9 import 'package:test/test.dart';
10 import 'package:test_reflective_loader/test_reflective_loader.dart'; 10 import 'package:test_reflective_loader/test_reflective_loader.dart';
11 11
12 import '../../abstract_single_unit.dart'; 12 import '../../abstract_single_unit.dart';
13 13
14 main() { 14 main() {
15 defineReflectiveSuite(() { 15 defineReflectiveSuite(() {
16 defineReflectiveTests(UtilTest); 16 defineReflectiveTests(UtilTest);
17 }); 17 });
18 } 18 }
19 19
20 @reflectiveTest 20 @reflectiveTest
21 class UtilTest extends AbstractSingleUnitTest { 21 class UtilTest extends AbstractSingleUnitTest {
22 test_addLibraryImports_dart_hasImports_between() async { 22 test_addLibraryImports_dart_hasImports_between() async {
23 await resolveTestUnit(''' 23 await resolveTestUnit('''
24 import 'dart:async'; 24 import 'dart:async';
25 import 'dart:math'; 25 import 'dart:math';
26 '''); 26 ''');
27 Source newLibrary = _getDartSource('dart:collection'); 27 Source newLibrary = _getDartSource('dart:collection');
28 _assertAddLibraryImport( 28 _assertAddLibraryImport(<Source>[newLibrary], '''
29 <Source>[newLibrary],
30 '''
31 import 'dart:async'; 29 import 'dart:async';
32 import 'dart:collection'; 30 import 'dart:collection';
33 import 'dart:math'; 31 import 'dart:math';
34 '''); 32 ''');
35 } 33 }
36 34
37 test_addLibraryImports_dart_hasImports_first() async { 35 test_addLibraryImports_dart_hasImports_first() async {
38 await resolveTestUnit(''' 36 await resolveTestUnit('''
39 import 'dart:collection'; 37 import 'dart:collection';
40 import 'dart:math'; 38 import 'dart:math';
41 '''); 39 ''');
42 Source newLibrary = _getDartSource('dart:async'); 40 Source newLibrary = _getDartSource('dart:async');
43 _assertAddLibraryImport( 41 _assertAddLibraryImport(<Source>[newLibrary], '''
44 <Source>[newLibrary],
45 '''
46 import 'dart:async'; 42 import 'dart:async';
47 import 'dart:collection'; 43 import 'dart:collection';
48 import 'dart:math'; 44 import 'dart:math';
49 '''); 45 ''');
50 } 46 }
51 47
52 test_addLibraryImports_dart_hasImports_last() async { 48 test_addLibraryImports_dart_hasImports_last() async {
53 await resolveTestUnit(''' 49 await resolveTestUnit('''
54 import 'dart:async'; 50 import 'dart:async';
55 import 'dart:collection'; 51 import 'dart:collection';
56 '''); 52 ''');
57 Source newLibrary = _getDartSource('dart:math'); 53 Source newLibrary = _getDartSource('dart:math');
58 _assertAddLibraryImport( 54 _assertAddLibraryImport(<Source>[newLibrary], '''
59 <Source>[newLibrary],
60 '''
61 import 'dart:async'; 55 import 'dart:async';
62 import 'dart:collection'; 56 import 'dart:collection';
63 import 'dart:math'; 57 import 'dart:math';
64 '''); 58 ''');
65 } 59 }
66 60
67 test_addLibraryImports_dart_hasImports_multiple() async { 61 test_addLibraryImports_dart_hasImports_multiple() async {
68 await resolveTestUnit(''' 62 await resolveTestUnit('''
69 import 'dart:collection'; 63 import 'dart:collection';
70 import 'dart:math'; 64 import 'dart:math';
71 '''); 65 ''');
72 Source newLibrary1 = _getDartSource('dart:async'); 66 Source newLibrary1 = _getDartSource('dart:async');
73 Source newLibrary2 = _getDartSource('dart:html'); 67 Source newLibrary2 = _getDartSource('dart:html');
74 _assertAddLibraryImport( 68 _assertAddLibraryImport(<Source>[newLibrary1, newLibrary2], '''
75 <Source>[newLibrary1, newLibrary2],
76 '''
77 import 'dart:async'; 69 import 'dart:async';
78 import 'dart:collection'; 70 import 'dart:collection';
79 import 'dart:html'; 71 import 'dart:html';
80 import 'dart:math'; 72 import 'dart:math';
81 '''); 73 ''');
82 } 74 }
83 75
84 test_addLibraryImports_dart_hasImports_multiple_first() async { 76 test_addLibraryImports_dart_hasImports_multiple_first() async {
85 await resolveTestUnit(''' 77 await resolveTestUnit('''
86 import 'dart:html'; 78 import 'dart:html';
87 import 'dart:math'; 79 import 'dart:math';
88 '''); 80 ''');
89 Source newLibrary1 = _getDartSource('dart:async'); 81 Source newLibrary1 = _getDartSource('dart:async');
90 Source newLibrary2 = _getDartSource('dart:collection'); 82 Source newLibrary2 = _getDartSource('dart:collection');
91 _assertAddLibraryImport( 83 _assertAddLibraryImport(<Source>[newLibrary1, newLibrary2], '''
92 <Source>[newLibrary1, newLibrary2],
93 '''
94 import 'dart:async'; 84 import 'dart:async';
95 import 'dart:collection'; 85 import 'dart:collection';
96 import 'dart:html'; 86 import 'dart:html';
97 import 'dart:math'; 87 import 'dart:math';
98 '''); 88 ''');
99 } 89 }
100 90
101 test_addLibraryImports_dart_hasImports_multiple_last() async { 91 test_addLibraryImports_dart_hasImports_multiple_last() async {
102 await resolveTestUnit(''' 92 await resolveTestUnit('''
103 import 'dart:async'; 93 import 'dart:async';
104 import 'dart:collection'; 94 import 'dart:collection';
105 '''); 95 ''');
106 Source newLibrary1 = _getDartSource('dart:html'); 96 Source newLibrary1 = _getDartSource('dart:html');
107 Source newLibrary2 = _getDartSource('dart:math'); 97 Source newLibrary2 = _getDartSource('dart:math');
108 _assertAddLibraryImport( 98 _assertAddLibraryImport(<Source>[newLibrary1, newLibrary2], '''
109 <Source>[newLibrary1, newLibrary2],
110 '''
111 import 'dart:async'; 99 import 'dart:async';
112 import 'dart:collection'; 100 import 'dart:collection';
113 import 'dart:html'; 101 import 'dart:html';
114 import 'dart:math'; 102 import 'dart:math';
115 '''); 103 ''');
116 } 104 }
117 105
118 test_addLibraryImports_dart_hasLibraryDirective() async { 106 test_addLibraryImports_dart_hasLibraryDirective() async {
119 await resolveTestUnit(''' 107 await resolveTestUnit('''
120 library test; 108 library test;
121 109
122 class A {} 110 class A {}
123 '''); 111 ''');
124 Source newLibrary1 = _getDartSource('dart:math'); 112 Source newLibrary1 = _getDartSource('dart:math');
125 Source newLibrary2 = _getDartSource('dart:async'); 113 Source newLibrary2 = _getDartSource('dart:async');
126 _assertAddLibraryImport( 114 _assertAddLibraryImport(<Source>[newLibrary1, newLibrary2], '''
127 <Source>[newLibrary1, newLibrary2],
128 '''
129 library test; 115 library test;
130 116
131 import 'dart:async'; 117 import 'dart:async';
132 import 'dart:math'; 118 import 'dart:math';
133 119
134 class A {} 120 class A {}
135 '''); 121 ''');
136 } 122 }
137 123
138 test_addLibraryImports_dart_noDirectives_hasComment() async { 124 test_addLibraryImports_dart_noDirectives_hasComment() async {
139 await resolveTestUnit(''' 125 await resolveTestUnit('''
140 /// Comment. 126 /// Comment.
141 127
142 class A {} 128 class A {}
143 '''); 129 ''');
144 Source newLibrary1 = _getDartSource('dart:math'); 130 Source newLibrary1 = _getDartSource('dart:math');
145 Source newLibrary2 = _getDartSource('dart:async'); 131 Source newLibrary2 = _getDartSource('dart:async');
146 _assertAddLibraryImport( 132 _assertAddLibraryImport(<Source>[newLibrary1, newLibrary2], '''
147 <Source>[newLibrary1, newLibrary2],
148 '''
149 /// Comment. 133 /// Comment.
150 134
151 import 'dart:async'; 135 import 'dart:async';
152 import 'dart:math'; 136 import 'dart:math';
153 137
154 class A {} 138 class A {}
155 '''); 139 ''');
156 } 140 }
157 141
158 test_addLibraryImports_dart_noDirectives_hasShebang() async { 142 test_addLibraryImports_dart_noDirectives_hasShebang() async {
159 await resolveTestUnit(''' 143 await resolveTestUnit('''
160 #!/bin/dart 144 #!/bin/dart
161 145
162 class A {} 146 class A {}
163 '''); 147 ''');
164 Source newLibrary1 = _getDartSource('dart:math'); 148 Source newLibrary1 = _getDartSource('dart:math');
165 Source newLibrary2 = _getDartSource('dart:async'); 149 Source newLibrary2 = _getDartSource('dart:async');
166 _assertAddLibraryImport( 150 _assertAddLibraryImport(<Source>[newLibrary1, newLibrary2], '''
167 <Source>[newLibrary1, newLibrary2],
168 '''
169 #!/bin/dart 151 #!/bin/dart
170 152
171 import 'dart:async'; 153 import 'dart:async';
172 import 'dart:math'; 154 import 'dart:math';
173 155
174 class A {} 156 class A {}
175 '''); 157 ''');
176 } 158 }
177 159
178 test_addLibraryImports_dart_noDirectives_noShebang() async { 160 test_addLibraryImports_dart_noDirectives_noShebang() async {
179 await resolveTestUnit(''' 161 await resolveTestUnit('''
180 class A {} 162 class A {}
181 '''); 163 ''');
182 Source newLibrary1 = _getDartSource('dart:math'); 164 Source newLibrary1 = _getDartSource('dart:math');
183 Source newLibrary2 = _getDartSource('dart:async'); 165 Source newLibrary2 = _getDartSource('dart:async');
184 _assertAddLibraryImport( 166 _assertAddLibraryImport(<Source>[newLibrary1, newLibrary2], '''
185 <Source>[newLibrary1, newLibrary2],
186 '''
187 import 'dart:async'; 167 import 'dart:async';
188 import 'dart:math'; 168 import 'dart:math';
189 169
190 class A {} 170 class A {}
191 '''); 171 ''');
192 } 172 }
193 173
194 test_addLibraryImports_package_hasDart_hasPackages_insertAfter() async { 174 test_addLibraryImports_package_hasDart_hasPackages_insertAfter() async {
195 addPackageSource('aaa', 'aaa.dart', ''); 175 addPackageSource('aaa', 'aaa.dart', '');
196 await resolveTestUnit(''' 176 await resolveTestUnit('''
197 import 'dart:async'; 177 import 'dart:async';
198 178
199 import 'package:aaa/aaa.dart'; 179 import 'package:aaa/aaa.dart';
200 '''); 180 ''');
201 Source newLibrary = _getSource('/lib/bbb.dart', 'package:bbb/bbb.dart'); 181 Source newLibrary = _getSource('/lib/bbb.dart', 'package:bbb/bbb.dart');
202 _assertAddLibraryImport( 182 _assertAddLibraryImport(<Source>[newLibrary], '''
203 <Source>[newLibrary],
204 '''
205 import 'dart:async'; 183 import 'dart:async';
206 184
207 import 'package:aaa/aaa.dart'; 185 import 'package:aaa/aaa.dart';
208 import 'package:bbb/bbb.dart'; 186 import 'package:bbb/bbb.dart';
209 '''); 187 ''');
210 } 188 }
211 189
212 test_addLibraryImports_package_hasDart_hasPackages_insertBefore() async { 190 test_addLibraryImports_package_hasDart_hasPackages_insertBefore() async {
213 addPackageSource('bbb', 'bbb.dart', ''); 191 addPackageSource('bbb', 'bbb.dart', '');
214 await resolveTestUnit(''' 192 await resolveTestUnit('''
215 import 'dart:async'; 193 import 'dart:async';
216 194
217 import 'package:bbb/bbb.dart'; 195 import 'package:bbb/bbb.dart';
218 '''); 196 ''');
219 Source newLibrary = _getSource('/lib/aaa.dart', 'package:aaa/aaa.dart'); 197 Source newLibrary = _getSource('/lib/aaa.dart', 'package:aaa/aaa.dart');
220 _assertAddLibraryImport( 198 _assertAddLibraryImport(<Source>[newLibrary], '''
221 <Source>[newLibrary],
222 '''
223 import 'dart:async'; 199 import 'dart:async';
224 200
225 import 'package:aaa/aaa.dart'; 201 import 'package:aaa/aaa.dart';
226 import 'package:bbb/bbb.dart'; 202 import 'package:bbb/bbb.dart';
227 '''); 203 ''');
228 } 204 }
229 205
230 test_addLibraryImports_package_hasImports_between() async { 206 test_addLibraryImports_package_hasImports_between() async {
231 addPackageSource('aaa', 'aaa.dart', ''); 207 addPackageSource('aaa', 'aaa.dart', '');
232 addPackageSource('ddd', 'ddd.dart', ''); 208 addPackageSource('ddd', 'ddd.dart', '');
233 await resolveTestUnit(''' 209 await resolveTestUnit('''
234 import 'package:aaa/aaa.dart'; 210 import 'package:aaa/aaa.dart';
235 import 'package:ddd/ddd.dart'; 211 import 'package:ddd/ddd.dart';
236 '''); 212 ''');
237 Source newLibrary1 = _getSource('/lib/bbb.dart', 'package:bbb/bbb.dart'); 213 Source newLibrary1 = _getSource('/lib/bbb.dart', 'package:bbb/bbb.dart');
238 Source newLibrary2 = _getSource('/lib/ccc.dart', 'package:ccc/ccc.dart'); 214 Source newLibrary2 = _getSource('/lib/ccc.dart', 'package:ccc/ccc.dart');
239 _assertAddLibraryImport( 215 _assertAddLibraryImport(<Source>[newLibrary1, newLibrary2], '''
240 <Source>[newLibrary1, newLibrary2],
241 '''
242 import 'package:aaa/aaa.dart'; 216 import 'package:aaa/aaa.dart';
243 import 'package:bbb/bbb.dart'; 217 import 'package:bbb/bbb.dart';
244 import 'package:ccc/ccc.dart'; 218 import 'package:ccc/ccc.dart';
245 import 'package:ddd/ddd.dart'; 219 import 'package:ddd/ddd.dart';
246 '''); 220 ''');
247 } 221 }
248 222
249 void _assertAddLibraryImport(List<Source> newLibraries, String expectedCode) { 223 void _assertAddLibraryImport(List<Source> newLibraries, String expectedCode) {
250 SourceChange change = new SourceChange(''); 224 SourceChange change = new SourceChange('');
251 addLibraryImports(change, testLibraryElement, newLibraries.toSet()); 225 addLibraryImports(change, testLibraryElement, newLibraries.toSet());
(...skipping 17 matching lines...) Expand all
269 @override 243 @override
270 final String fullName; 244 final String fullName;
271 245
272 @override 246 @override
273 final Uri uri; 247 final Uri uri;
274 248
275 _SourceMock(this.fullName, this.uri); 249 _SourceMock(this.fullName, this.uri);
276 250
277 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 251 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
278 } 252 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698