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 import 'dart:async'; | 5 import 'dart:async'; |
6 | 6 |
7 import 'package:analysis_server/protocol/protocol.dart'; | 7 import 'package:analysis_server/protocol/protocol.dart'; |
8 import 'package:analysis_server/protocol/protocol_generated.dart'; | 8 import 'package:analysis_server/protocol/protocol_generated.dart'; |
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/plugin_manager.dart'; | 10 import 'package:analysis_server/src/plugin/plugin_manager.dart'; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 } | 72 } |
73 | 73 |
74 test_removeTypeAnnotation() async { | 74 test_removeTypeAnnotation() async { |
75 addTestFile(''' | 75 addTestFile(''' |
76 main() { | 76 main() { |
77 int v = 1; | 77 int v = 1; |
78 } | 78 } |
79 '''); | 79 '''); |
80 await waitForTasksFinished(); | 80 await waitForTasksFinished(); |
81 await prepareAssists('v ='); | 81 await prepareAssists('v ='); |
82 _assertHasChange( | 82 _assertHasChange('Remove type annotation', ''' |
83 'Remove type annotation', | |
84 ''' | |
85 main() { | 83 main() { |
86 var v = 1; | 84 var v = 1; |
87 } | 85 } |
88 '''); | 86 '''); |
89 } | 87 } |
90 | 88 |
91 test_splitVariableDeclaration() async { | 89 test_splitVariableDeclaration() async { |
92 addTestFile(''' | 90 addTestFile(''' |
93 main() { | 91 main() { |
94 int v = 1; | 92 int v = 1; |
95 } | 93 } |
96 '''); | 94 '''); |
97 await waitForTasksFinished(); | 95 await waitForTasksFinished(); |
98 await prepareAssists('v ='); | 96 await prepareAssists('v ='); |
99 _assertHasChange( | 97 _assertHasChange('Split variable declaration', ''' |
100 'Split variable declaration', | |
101 ''' | |
102 main() { | 98 main() { |
103 int v; | 99 int v; |
104 v = 1; | 100 v = 1; |
105 } | 101 } |
106 '''); | 102 '''); |
107 } | 103 } |
108 | 104 |
109 test_surroundWithIf() async { | 105 test_surroundWithIf() async { |
110 addTestFile(''' | 106 addTestFile(''' |
111 main() { | 107 main() { |
112 print(1); | 108 print(1); |
113 print(2); | 109 print(2); |
114 } | 110 } |
115 '''); | 111 '''); |
116 await waitForTasksFinished(); | 112 await waitForTasksFinished(); |
117 int offset = findOffset(' print(1)'); | 113 int offset = findOffset(' print(1)'); |
118 int length = findOffset('}') - offset; | 114 int length = findOffset('}') - offset; |
119 await prepareAssistsAt(offset, length); | 115 await prepareAssistsAt(offset, length); |
120 _assertHasChange( | 116 _assertHasChange("Surround with 'if'", ''' |
121 "Surround with 'if'", | |
122 ''' | |
123 main() { | 117 main() { |
124 if (condition) { | 118 if (condition) { |
125 print(1); | 119 print(1); |
126 print(2); | 120 print(2); |
127 } | 121 } |
128 } | 122 } |
129 '''); | 123 '''); |
130 } | 124 } |
131 | 125 |
132 void _assertHasChange(String message, String expectedCode) { | 126 void _assertHasChange(String message, String expectedCode) { |
133 for (SourceChange change in changes) { | 127 for (SourceChange change in changes) { |
134 if (change.message == message) { | 128 if (change.message == message) { |
135 String resultCode = | 129 String resultCode = |
136 SourceEdit.applySequence(testCode, change.edits[0].edits); | 130 SourceEdit.applySequence(testCode, change.edits[0].edits); |
137 expect(resultCode, expectedCode); | 131 expect(resultCode, expectedCode); |
138 return; | 132 return; |
139 } | 133 } |
140 } | 134 } |
141 fail("Expected to find |$message| in\n" + changes.join('\n')); | 135 fail("Expected to find |$message| in\n" + changes.join('\n')); |
142 } | 136 } |
143 } | 137 } |
OLD | NEW |