| 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.services.refactoring.extract_method; | 5 library test.services.refactoring.extract_method; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/protocol.dart'; | 9 import 'package:analysis_server/src/protocol.dart'; |
| 10 import 'package:analysis_server/src/services/correction/status.dart'; | 10 import 'package:analysis_server/src/services/correction/status.dart'; |
| (...skipping 1169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1180 return _assertSuccessfulRefactoring(''' | 1180 return _assertSuccessfulRefactoring(''' |
| 1181 dynaFunction() {} | 1181 dynaFunction() {} |
| 1182 main() { | 1182 main() { |
| 1183 var v = res(); // marker | 1183 var v = res(); // marker |
| 1184 } | 1184 } |
| 1185 | 1185 |
| 1186 res() => dynaFunction(); | 1186 res() => dynaFunction(); |
| 1187 '''); | 1187 '''); |
| 1188 } | 1188 } |
| 1189 | 1189 |
| 1190 test_singleExpression_hasAwait() { |
| 1191 indexTestUnit(''' |
| 1192 import 'dart:async'; |
| 1193 Future<int> getValue() => 42; |
| 1194 main() async { |
| 1195 int v = await getValue(); |
| 1196 print(v); |
| 1197 } |
| 1198 '''); |
| 1199 _createRefactoringForString('await getValue()'); |
| 1200 // apply refactoring |
| 1201 return _assertSuccessfulRefactoring(''' |
| 1202 import 'dart:async'; |
| 1203 Future<int> getValue() => 42; |
| 1204 main() async { |
| 1205 int v = await res(); |
| 1206 print(v); |
| 1207 } |
| 1208 |
| 1209 Future<int> res() async => await getValue(); |
| 1210 '''); |
| 1211 } |
| 1212 |
| 1190 test_singleExpression_ignore_assignmentLeftHandSize() { | 1213 test_singleExpression_ignore_assignmentLeftHandSize() { |
| 1191 indexTestUnit(''' | 1214 indexTestUnit(''' |
| 1192 main() { | 1215 main() { |
| 1193 getButton().text = 'txt'; | 1216 getButton().text = 'txt'; |
| 1194 print(getButton().text); // marker | 1217 print(getButton().text); // marker |
| 1195 } | 1218 } |
| 1196 getButton() {} | 1219 getButton() {} |
| 1197 '''); | 1220 '''); |
| 1198 _createRefactoringWithSuffix('getButton().text', '); // marker'); | 1221 _createRefactoringWithSuffix('getButton().text', '); // marker'); |
| 1199 // apply refactoring | 1222 // apply refactoring |
| (...skipping 934 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2134 return; | 2157 return; |
| 2135 } | 2158 } |
| 2136 throw 'boo!'; | 2159 throw 'boo!'; |
| 2137 // end | 2160 // end |
| 2138 } | 2161 } |
| 2139 '''); | 2162 '''); |
| 2140 _createRefactoringForStartEndComments(); | 2163 _createRefactoringForStartEndComments(); |
| 2141 await assertRefactoringConditionsOK(); | 2164 await assertRefactoringConditionsOK(); |
| 2142 } | 2165 } |
| 2143 | 2166 |
| 2167 test_statements_hasAwait_dynamicReturnType() { |
| 2168 indexTestUnit(''' |
| 2169 import 'dart:async'; |
| 2170 Future getValue() => 42; |
| 2171 main() async { |
| 2172 // start |
| 2173 var v = await getValue(); |
| 2174 // end |
| 2175 print(v); |
| 2176 } |
| 2177 '''); |
| 2178 _createRefactoringForStartEndComments(); |
| 2179 // apply refactoring |
| 2180 return _assertSuccessfulRefactoring(''' |
| 2181 import 'dart:async'; |
| 2182 Future getValue() => 42; |
| 2183 main() async { |
| 2184 // start |
| 2185 var v = await res(); |
| 2186 // end |
| 2187 print(v); |
| 2188 } |
| 2189 |
| 2190 Future res() async { |
| 2191 var v = await getValue(); |
| 2192 return v; |
| 2193 } |
| 2194 '''); |
| 2195 } |
| 2196 |
| 2197 test_statements_hasAwait_expression() { |
| 2198 indexTestUnit(''' |
| 2199 import 'dart:async'; |
| 2200 Future<int> getValue() => 42; |
| 2201 main() async { |
| 2202 // start |
| 2203 int v = await getValue(); |
| 2204 v += 2; |
| 2205 // end |
| 2206 print(v); |
| 2207 } |
| 2208 '''); |
| 2209 _createRefactoringForStartEndComments(); |
| 2210 // apply refactoring |
| 2211 return _assertSuccessfulRefactoring(''' |
| 2212 import 'dart:async'; |
| 2213 Future<int> getValue() => 42; |
| 2214 main() async { |
| 2215 // start |
| 2216 int v = await res(); |
| 2217 // end |
| 2218 print(v); |
| 2219 } |
| 2220 |
| 2221 Future<int> res() async { |
| 2222 int v = await getValue(); |
| 2223 v += 2; |
| 2224 return v; |
| 2225 } |
| 2226 '''); |
| 2227 } |
| 2228 |
| 2229 test_statements_hasAwait_forEach() { |
| 2230 indexTestUnit(''' |
| 2231 import 'dart:async'; |
| 2232 Stream<int> getValueStream() => null; |
| 2233 main() async { |
| 2234 // start |
| 2235 int sum = 0; |
| 2236 await for (int v in getValueStream()) { |
| 2237 sum += v; |
| 2238 } |
| 2239 // end |
| 2240 print(sum); |
| 2241 } |
| 2242 '''); |
| 2243 _createRefactoringForStartEndComments(); |
| 2244 // apply refactoring |
| 2245 return _assertSuccessfulRefactoring(''' |
| 2246 import 'dart:async'; |
| 2247 Stream<int> getValueStream() => null; |
| 2248 main() async { |
| 2249 // start |
| 2250 int sum = await res(); |
| 2251 // end |
| 2252 print(sum); |
| 2253 } |
| 2254 |
| 2255 Future<int> res() async { |
| 2256 int sum = 0; |
| 2257 await for (int v in getValueStream()) { |
| 2258 sum += v; |
| 2259 } |
| 2260 return sum; |
| 2261 } |
| 2262 '''); |
| 2263 } |
| 2264 |
| 2265 test_statements_hasAwait_voidReturnType() { |
| 2266 indexTestUnit(''' |
| 2267 import 'dart:async'; |
| 2268 Future<int> getValue() => 42; |
| 2269 main() async { |
| 2270 // start |
| 2271 int v = await getValue(); |
| 2272 print(v); |
| 2273 // end |
| 2274 } |
| 2275 '''); |
| 2276 _createRefactoringForStartEndComments(); |
| 2277 // apply refactoring |
| 2278 return _assertSuccessfulRefactoring(''' |
| 2279 import 'dart:async'; |
| 2280 Future<int> getValue() => 42; |
| 2281 main() async { |
| 2282 // start |
| 2283 await res(); |
| 2284 // end |
| 2285 } |
| 2286 |
| 2287 Future res() async { |
| 2288 int v = await getValue(); |
| 2289 print(v); |
| 2290 } |
| 2291 '''); |
| 2292 } |
| 2293 |
| 2144 test_statements_inSwitchMember() { | 2294 test_statements_inSwitchMember() { |
| 2145 indexTestUnit(''' | 2295 indexTestUnit(''' |
| 2146 class A { | 2296 class A { |
| 2147 foo(int p) { | 2297 foo(int p) { |
| 2148 switch (p) { | 2298 switch (p) { |
| 2149 case 0: | 2299 case 0: |
| 2150 // start | 2300 // start |
| 2151 print(0); | 2301 print(0); |
| 2152 // end | 2302 // end |
| 2153 break; | 2303 break; |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2565 * Returns a deep copy of [refactoring] parameters. | 2715 * Returns a deep copy of [refactoring] parameters. |
| 2566 * There was a bug masked by updating parameter instances shared between the | 2716 * There was a bug masked by updating parameter instances shared between the |
| 2567 * refactoring and the test. | 2717 * refactoring and the test. |
| 2568 */ | 2718 */ |
| 2569 List<RefactoringMethodParameter> _getParametersCopy() { | 2719 List<RefactoringMethodParameter> _getParametersCopy() { |
| 2570 return refactoring.parameters.map((p) { | 2720 return refactoring.parameters.map((p) { |
| 2571 return new RefactoringMethodParameter(p.kind, p.type, p.name, id: p.id); | 2721 return new RefactoringMethodParameter(p.kind, p.type, p.name, id: p.id); |
| 2572 }).toList(); | 2722 }).toList(); |
| 2573 } | 2723 } |
| 2574 } | 2724 } |
| OLD | NEW |