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

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

Issue 806933002: Issue 21883. Add checks if type parameters can be used. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years 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 | Annotate | Revision Log
OLDNEW
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.services.correction.assist; 5 library test.services.correction.assist;
6 6
7 import 'package:analysis_server/src/protocol.dart'; 7 import 'package:analysis_server/src/protocol.dart';
8 import 'package:analysis_server/src/services/correction/assist.dart'; 8 import 'package:analysis_server/src/services/correction/assist.dart';
9 import 'package:analysis_server/src/services/index/index.dart'; 9 import 'package:analysis_server/src/services/index/index.dart';
10 import 'package:analysis_server/src/services/index/local_memory_index.dart'; 10 import 'package:analysis_server/src/services/index/local_memory_index.dart';
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 verifyNoTestUnitErrors = false; 159 verifyNoTestUnitErrors = false;
160 _indexTestUnit(''' 160 _indexTestUnit('''
161 main() { 161 main() {
162 for (var item in unknownList) { 162 for (var item in unknownList) {
163 } 163 }
164 } 164 }
165 '''); 165 ''');
166 assertNoAssistAt('item in', AssistKind.ADD_TYPE_ANNOTATION); 166 assertNoAssistAt('item in', AssistKind.ADD_TYPE_ANNOTATION);
167 } 167 }
168 168
169 void test_addTypeAnnotation_declaredIdentifier_generic_OK() {
170 _indexTestUnit('''
171 class A<T> {
172 main(List<List<T>> items) {
173 for (var item in items) {
174 }
175 }
176 }
177 ''');
178 assertHasAssistAt('item in', AssistKind.ADD_TYPE_ANNOTATION, '''
179 class A<T> {
180 main(List<List<T>> items) {
181 for (List<T> item in items) {
182 }
183 }
184 }
185 ''');
186 }
187
169 void test_addTypeAnnotation_declaredIdentifier_OK() { 188 void test_addTypeAnnotation_declaredIdentifier_OK() {
170 _indexTestUnit(''' 189 _indexTestUnit('''
171 main(List<String> items) { 190 main(List<String> items) {
172 for (var item in items) { 191 for (var item in items) {
173 } 192 }
174 } 193 }
175 '''); 194 ''');
176 // on identifier 195 // on identifier
177 assertHasAssistAt('item in', AssistKind.ADD_TYPE_ANNOTATION, ''' 196 assertHasAssistAt('item in', AssistKind.ADD_TYPE_ANNOTATION, '''
178 main(List<String> items) { 197 main(List<String> items) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 } 238 }
220 '''); 239 ''');
221 assertHasAssistAt('item in', AssistKind.ADD_TYPE_ANNOTATION, ''' 240 assertHasAssistAt('item in', AssistKind.ADD_TYPE_ANNOTATION, '''
222 main(List<String> items) { 241 main(List<String> items) {
223 for (final String item in items) { 242 for (final String item in items) {
224 } 243 }
225 } 244 }
226 '''); 245 ''');
227 } 246 }
228 247
248 void test_addTypeAnnotation_local_generic_OK_literal() {
249 _indexTestUnit('''
250 class A {
251 main(List<int> items) {
252 var v = items;
253 }
254 }
255 ''');
256 assertHasAssistAt('v =', AssistKind.ADD_TYPE_ANNOTATION, '''
257 class A {
258 main(List<int> items) {
259 List<int> v = items;
260 }
261 }
262 ''');
263 }
264
265 void test_addTypeAnnotation_local_generic_OK_local() {
266 _indexTestUnit('''
267 class A<T> {
268 main(List<T> items) {
269 var v = items;
270 }
271 }
272 ''');
273 assertHasAssistAt('v =', AssistKind.ADD_TYPE_ANNOTATION, '''
274 class A<T> {
275 main(List<T> items) {
276 List<T> v = items;
277 }
278 }
279 ''');
280 }
281
229 void test_addTypeAnnotation_local_OK_addImport_dartUri() { 282 void test_addTypeAnnotation_local_OK_addImport_dartUri() {
230 addSource('/my_lib.dart', r''' 283 addSource('/my_lib.dart', r'''
231 import 'dart:async'; 284 import 'dart:async';
232 Future<int> getFutureInt() => null; 285 Future<int> getFutureInt() => null;
233 '''); 286 ''');
234 _indexTestUnit(''' 287 _indexTestUnit('''
235 import 'my_lib.dart'; 288 import 'my_lib.dart';
236 main() { 289 main() {
237 var v = getFutureInt(); 290 var v = getFutureInt();
238 } 291 }
(...skipping 2008 matching lines...) Expand 10 before | Expand all | Expand 10 after
2247 '''); 2300 ''');
2248 // not binary expression 2301 // not binary expression
2249 assertNoAssistAt('main() {', AssistKind.SPLIT_AND_CONDITION); 2302 assertNoAssistAt('main() {', AssistKind.SPLIT_AND_CONDITION);
2250 // selection is not empty and includes more than just operator 2303 // selection is not empty and includes more than just operator
2251 { 2304 {
2252 length = 5; 2305 length = 5;
2253 assertNoAssistAt('&& 2 == 2', AssistKind.SPLIT_AND_CONDITION); 2306 assertNoAssistAt('&& 2 == 2', AssistKind.SPLIT_AND_CONDITION);
2254 } 2307 }
2255 } 2308 }
2256 2309
2257 void test_splitAndCondition_wrong_notAnd() {
2258 _indexTestUnit('''
2259 main() {
2260 if (1 == 1 || 2 == 2) {
2261 print(0);
2262 }
2263 }
2264 ''');
2265 assertNoAssistAt('|| 2', AssistKind.SPLIT_AND_CONDITION);
2266 }
2267
2268 void test_splitAndCondition_wrong_hasElse() { 2310 void test_splitAndCondition_wrong_hasElse() {
2269 _indexTestUnit(''' 2311 _indexTestUnit('''
2270 main() { 2312 main() {
2271 if (1 == 1 && 2 == 2) { 2313 if (1 == 1 && 2 == 2) {
2272 print(1); 2314 print(1);
2273 } else { 2315 } else {
2274 print(2); 2316 print(2);
2275 } 2317 }
2276 } 2318 }
2277 '''); 2319 ''');
2278 assertNoAssistAt('&& 2', AssistKind.SPLIT_AND_CONDITION); 2320 assertNoAssistAt('&& 2', AssistKind.SPLIT_AND_CONDITION);
2279 } 2321 }
2280 2322
2323 void test_splitAndCondition_wrong_notAnd() {
2324 _indexTestUnit('''
2325 main() {
2326 if (1 == 1 || 2 == 2) {
2327 print(0);
2328 }
2329 }
2330 ''');
2331 assertNoAssistAt('|| 2', AssistKind.SPLIT_AND_CONDITION);
2332 }
2333
2281 void test_splitAndCondition_wrong_notPartOfIf() { 2334 void test_splitAndCondition_wrong_notPartOfIf() {
2282 _indexTestUnit(''' 2335 _indexTestUnit('''
2283 main() { 2336 main() {
2284 print(1 == 1 && 2 == 2); 2337 print(1 == 1 && 2 == 2);
2285 } 2338 }
2286 '''); 2339 ''');
2287 assertNoAssistAt('&& 2', AssistKind.SPLIT_AND_CONDITION); 2340 assertNoAssistAt('&& 2', AssistKind.SPLIT_AND_CONDITION);
2288 } 2341 }
2289 2342
2290 void test_splitAndCondition_wrong_notTopLevelAnd() { 2343 void test_splitAndCondition_wrong_notTopLevelAnd() {
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
2568 void _indexTestUnit(String code) { 2621 void _indexTestUnit(String code) {
2569 resolveTestUnit(code); 2622 resolveTestUnit(code);
2570 index.indexUnit(context, testUnit); 2623 index.indexUnit(context, testUnit);
2571 } 2624 }
2572 2625
2573 void _setStartEndSelection() { 2626 void _setStartEndSelection() {
2574 offset = findOffset('// start\n') + '// start\n'.length; 2627 offset = findOffset('// start\n') + '// start\n'.length;
2575 length = findOffset('// end') - offset; 2628 length = findOffset('// end') - offset;
2576 } 2629 }
2577 } 2630 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698