| 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.assists; | 5 library test.edit.assists; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/edit/edit_domain.dart'; | 9 import 'package:analysis_server/src/edit/edit_domain.dart'; |
| 10 import 'package:analysis_server/src/plugin/server_plugin.dart'; | 10 import 'package:analysis_server/src/plugin/server_plugin.dart'; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 @override | 40 @override |
| 41 void setUp() { | 41 void setUp() { |
| 42 super.setUp(); | 42 super.setUp(); |
| 43 createProject(); | 43 createProject(); |
| 44 ExtensionManager manager = new ExtensionManager(); | 44 ExtensionManager manager = new ExtensionManager(); |
| 45 ServerPlugin plugin = new ServerPlugin(); | 45 ServerPlugin plugin = new ServerPlugin(); |
| 46 manager.processPlugins([plugin]); | 46 manager.processPlugins([plugin]); |
| 47 handler = new EditDomainHandler(server, plugin); | 47 handler = new EditDomainHandler(server, plugin); |
| 48 } | 48 } |
| 49 | 49 |
| 50 Future test_removeTypeAnnotation() { | 50 Future test_removeTypeAnnotation() async { |
| 51 addTestFile(''' | 51 addTestFile(''' |
| 52 main() { | 52 main() { |
| 53 int v = 1; | 53 int v = 1; |
| 54 } | 54 } |
| 55 '''); | 55 '''); |
| 56 return waitForTasksFinished().then((_) { | 56 await waitForTasksFinished(); |
| 57 prepareAssists('v ='); | 57 prepareAssists('v ='); |
| 58 _assertHasChange('Remove type annotation', ''' | 58 _assertHasChange('Remove type annotation', ''' |
| 59 main() { | 59 main() { |
| 60 var v = 1; | 60 var v = 1; |
| 61 } | 61 } |
| 62 '''); | 62 '''); |
| 63 }); | |
| 64 } | 63 } |
| 65 | 64 |
| 66 Future test_splitVariableDeclaration() { | 65 Future test_splitVariableDeclaration() async { |
| 67 addTestFile(''' | 66 addTestFile(''' |
| 68 main() { | 67 main() { |
| 69 int v = 1; | 68 int v = 1; |
| 70 } | 69 } |
| 71 '''); | 70 '''); |
| 72 return waitForTasksFinished().then((_) { | 71 await waitForTasksFinished(); |
| 73 prepareAssists('v ='); | 72 prepareAssists('v ='); |
| 74 _assertHasChange('Split variable declaration', ''' | 73 _assertHasChange('Split variable declaration', ''' |
| 75 main() { | 74 main() { |
| 76 int v; | 75 int v; |
| 77 v = 1; | 76 v = 1; |
| 78 } | 77 } |
| 79 '''); | 78 '''); |
| 80 }); | |
| 81 } | 79 } |
| 82 | 80 |
| 83 Future test_surroundWithIf() { | 81 Future test_surroundWithIf() async { |
| 84 addTestFile(''' | 82 addTestFile(''' |
| 85 main() { | 83 main() { |
| 86 print(1); | 84 print(1); |
| 87 print(2); | 85 print(2); |
| 88 } | 86 } |
| 89 '''); | 87 '''); |
| 90 return waitForTasksFinished().then((_) { | 88 await waitForTasksFinished(); |
| 91 int offset = findOffset(' print(1)'); | 89 int offset = findOffset(' print(1)'); |
| 92 int length = findOffset('}') - offset; | 90 int length = findOffset('}') - offset; |
| 93 prepareAssistsAt(offset, length); | 91 prepareAssistsAt(offset, length); |
| 94 _assertHasChange("Surround with 'if'", ''' | 92 _assertHasChange("Surround with 'if'", ''' |
| 95 main() { | 93 main() { |
| 96 if (condition) { | 94 if (condition) { |
| 97 print(1); | 95 print(1); |
| 98 print(2); | 96 print(2); |
| 99 } | 97 } |
| 100 } | 98 } |
| 101 '''); | 99 '''); |
| 102 }); | |
| 103 } | 100 } |
| 104 | 101 |
| 105 void _assertHasChange(String message, String expectedCode) { | 102 void _assertHasChange(String message, String expectedCode) { |
| 106 for (SourceChange change in changes) { | 103 for (SourceChange change in changes) { |
| 107 if (change.message == message) { | 104 if (change.message == message) { |
| 108 String resultCode = | 105 String resultCode = |
| 109 SourceEdit.applySequence(testCode, change.edits[0].edits); | 106 SourceEdit.applySequence(testCode, change.edits[0].edits); |
| 110 expect(resultCode, expectedCode); | 107 expect(resultCode, expectedCode); |
| 111 return; | 108 return; |
| 112 } | 109 } |
| 113 } | 110 } |
| 114 fail("Expected to find |$message| in\n" + changes.join('\n')); | 111 fail("Expected to find |$message| in\n" + changes.join('\n')); |
| 115 } | 112 } |
| 116 } | 113 } |
| OLD | NEW |