OLD | NEW |
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.edit.refactoring; | |
6 | |
7 import 'dart:async'; | 5 import 'dart:async'; |
8 | 6 |
9 import 'package:analysis_server/protocol/protocol.dart'; | 7 import 'package:analysis_server/protocol/protocol.dart'; |
10 import 'package:analysis_server/protocol/protocol_generated.dart'; | 8 import 'package:analysis_server/protocol/protocol_generated.dart'; |
11 import 'package:analysis_server/src/edit/edit_domain.dart'; | 9 import 'package:analysis_server/src/edit/edit_domain.dart'; |
12 import 'package:analysis_server/src/services/index/index.dart'; | 10 import 'package:analysis_server/src/services/index/index.dart'; |
13 import 'package:analyzer/task/dart.dart'; | 11 import 'package:analyzer/task/dart.dart'; |
| 12 import 'package:analyzer_plugin/protocol/protocol_common.dart'; |
14 import 'package:plugin/manager.dart'; | 13 import 'package:plugin/manager.dart'; |
15 import 'package:test/test.dart'; | 14 import 'package:test/test.dart'; |
16 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 15 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
17 | 16 |
18 import '../analysis_abstract.dart'; | 17 import '../analysis_abstract.dart'; |
19 import '../mocks.dart'; | 18 import '../mocks.dart'; |
20 | 19 |
21 main() { | 20 main() { |
22 defineReflectiveSuite(() { | 21 defineReflectiveSuite(() { |
23 defineReflectiveTests(ConvertGetterMethodToMethodTest); | 22 defineReflectiveTests(ConvertGetterMethodToMethodTest); |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 }, | 354 }, |
356 ''' | 355 ''' |
357 main() { | 356 main() { |
358 print(1 + 2); | 357 print(1 + 2); |
359 var res = 1 + 2; | 358 var res = 1 + 2; |
360 print(res); // marker | 359 print(res); // marker |
361 } | 360 } |
362 '''); | 361 '''); |
363 } | 362 } |
364 | 363 |
365 test_names() { | 364 test_names() async { |
366 addTestFile(''' | 365 addTestFile(''' |
367 class TreeItem {} | 366 class TreeItem {} |
368 TreeItem getSelectedItem() => null; | 367 TreeItem getSelectedItem() => null; |
369 main() { | 368 main() { |
370 var a = getSelectedItem(); | 369 var a = getSelectedItem(); |
371 } | 370 } |
372 '''); | 371 '''); |
373 return getRefactoringResult(() { | 372 EditGetRefactoringResult result = await getRefactoringResult(() { |
374 return sendStringSuffixRequest('getSelectedItem()', ';', null, true); | 373 return sendStringSuffixRequest('getSelectedItem()', ';', null, true); |
375 }).then((result) { | |
376 ExtractLocalVariableFeedback feedback = result.feedback; | |
377 expect(feedback.names, | |
378 unorderedEquals(['treeItem', 'item', 'selectedItem'])); | |
379 expect(result.change, isNull); | |
380 }); | 374 }); |
| 375 ExtractLocalVariableFeedback feedback = result.feedback; |
| 376 expect( |
| 377 feedback.names, unorderedEquals(['treeItem', 'item', 'selectedItem'])); |
| 378 expect(result.change, isNull); |
381 } | 379 } |
382 | 380 |
383 test_nameWarning() { | 381 test_nameWarning() async { |
384 addTestFile(''' | 382 addTestFile(''' |
385 main() { | 383 main() { |
386 print(1 + 2); | 384 print(1 + 2); |
387 } | 385 } |
388 '''); | 386 '''); |
389 return getRefactoringResult(() { | 387 EditGetRefactoringResult result = await getRefactoringResult(() { |
390 return sendStringRequest('1 + 2', 'Name', true); | 388 return sendStringRequest('1 + 2', 'Name', true); |
391 }).then((result) { | 389 }); |
392 assertResultProblemsWarning(result.optionsProblems, | 390 assertResultProblemsWarning(result.optionsProblems, |
393 'Variable name should start with a lowercase letter.'); | 391 'Variable name should start with a lowercase letter.'); |
394 // ...but there is still a change | 392 // ...but there is still a change |
395 assertTestRefactoringResult( | 393 assertTestRefactoringResult( |
396 result, | 394 result, |
397 ''' | 395 ''' |
398 main() { | 396 main() { |
399 var Name = 1 + 2; | 397 var Name = 1 + 2; |
400 print(Name); | 398 print(Name); |
401 } | 399 } |
402 '''); | 400 '''); |
403 }); | |
404 } | 401 } |
405 | 402 |
406 test_offsetsLengths() { | 403 test_offsetsLengths() { |
407 addTestFile(''' | 404 addTestFile(''' |
408 main() { | 405 main() { |
409 print(1 + 2); | 406 print(1 + 2); |
410 print(1 + 2); | 407 print(1 + 2); |
411 } | 408 } |
412 '''); | 409 '''); |
413 return getRefactoringResult(() { | 410 return getRefactoringResult(() { |
(...skipping 1623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2037 @override | 2034 @override |
2038 void setUp() { | 2035 void setUp() { |
2039 super.setUp(); | 2036 super.setUp(); |
2040 createProject(); | 2037 createProject(); |
2041 ExtensionManager manager = new ExtensionManager(); | 2038 ExtensionManager manager = new ExtensionManager(); |
2042 manager.processPlugins([server.serverPlugin]); | 2039 manager.processPlugins([server.serverPlugin]); |
2043 handler = new EditDomainHandler(server); | 2040 handler = new EditDomainHandler(server); |
2044 server.handlers = [handler]; | 2041 server.handlers = [handler]; |
2045 } | 2042 } |
2046 } | 2043 } |
OLD | NEW |