| 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/refactoring/extract_method.dart'; | 10 import 'package:analysis_server/src/services/refactoring/extract_method.dart'; |
| (...skipping 2171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2182 // end | 2182 // end |
| 2183 } | 2183 } |
| 2184 | 2184 |
| 2185 int res() { | 2185 int res() { |
| 2186 int v = 5; | 2186 int v = 5; |
| 2187 return v + 1; | 2187 return v + 1; |
| 2188 } | 2188 } |
| 2189 '''); | 2189 '''); |
| 2190 } | 2190 } |
| 2191 | 2191 |
| 2192 test_statements_return_multiple_ifElse() { |
| 2193 indexTestUnit(''' |
| 2194 num main(bool b) { |
| 2195 // start |
| 2196 if (b) { |
| 2197 return 1; |
| 2198 } else { |
| 2199 return 2.0; |
| 2200 } |
| 2201 // end |
| 2202 } |
| 2203 '''); |
| 2204 _createRefactoringForStartEndComments(); |
| 2205 // apply refactoring |
| 2206 return _assertSuccessfulRefactoring(''' |
| 2207 num main(bool b) { |
| 2208 // start |
| 2209 return res(b); |
| 2210 // end |
| 2211 } |
| 2212 |
| 2213 num res(bool b) { |
| 2214 if (b) { |
| 2215 return 1; |
| 2216 } else { |
| 2217 return 2.0; |
| 2218 } |
| 2219 } |
| 2220 '''); |
| 2221 } |
| 2222 |
| 2223 test_statements_return_multiple_ifThen() { |
| 2224 indexTestUnit(''' |
| 2225 num main(bool b) { |
| 2226 // start |
| 2227 if (b) { |
| 2228 return 1; |
| 2229 } |
| 2230 return 2.0; |
| 2231 // end |
| 2232 } |
| 2233 '''); |
| 2234 _createRefactoringForStartEndComments(); |
| 2235 // apply refactoring |
| 2236 return _assertSuccessfulRefactoring(''' |
| 2237 num main(bool b) { |
| 2238 // start |
| 2239 return res(b); |
| 2240 // end |
| 2241 } |
| 2242 |
| 2243 num res(bool b) { |
| 2244 if (b) { |
| 2245 return 1; |
| 2246 } |
| 2247 return 2.0; |
| 2248 } |
| 2249 '''); |
| 2250 } |
| 2251 |
| 2252 test_statements_return_multiple_ignoreInFunction() { |
| 2253 indexTestUnit(''' |
| 2254 int main() { |
| 2255 // start |
| 2256 localFunction() { |
| 2257 return 'abc'; |
| 2258 } |
| 2259 return 42; |
| 2260 // end |
| 2261 } |
| 2262 '''); |
| 2263 _createRefactoringForStartEndComments(); |
| 2264 // apply refactoring |
| 2265 return _assertSuccessfulRefactoring(''' |
| 2266 int main() { |
| 2267 // start |
| 2268 return res(); |
| 2269 // end |
| 2270 } |
| 2271 |
| 2272 int res() { |
| 2273 localFunction() { |
| 2274 return 'abc'; |
| 2275 } |
| 2276 return 42; |
| 2277 } |
| 2278 '''); |
| 2279 } |
| 2280 |
| 2192 test_statements_return_single() { | 2281 test_statements_return_single() { |
| 2193 indexTestUnit(''' | 2282 indexTestUnit(''' |
| 2194 main() { | 2283 main() { |
| 2195 // start | 2284 // start |
| 2196 return 42; | 2285 return 42; |
| 2197 // end | 2286 // end |
| 2198 } | 2287 } |
| 2199 '''); | 2288 '''); |
| 2200 _createRefactoringForStartEndComments(); | 2289 _createRefactoringForStartEndComments(); |
| 2201 // apply refactoring | 2290 // apply refactoring |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2327 * Returns a deep copy of [refactoring] parameters. | 2416 * Returns a deep copy of [refactoring] parameters. |
| 2328 * There was a bug masked by updating parameter instances shared between the | 2417 * There was a bug masked by updating parameter instances shared between the |
| 2329 * refactoring and the test. | 2418 * refactoring and the test. |
| 2330 */ | 2419 */ |
| 2331 List<RefactoringMethodParameter> _getParametersCopy() { | 2420 List<RefactoringMethodParameter> _getParametersCopy() { |
| 2332 return refactoring.parameters.map((p) { | 2421 return refactoring.parameters.map((p) { |
| 2333 return new RefactoringMethodParameter(p.kind, p.type, p.name, id: p.id); | 2422 return new RefactoringMethodParameter(p.kind, p.type, p.name, id: p.id); |
| 2334 }).toList(); | 2423 }).toList(); |
| 2335 } | 2424 } |
| 2336 } | 2425 } |
| OLD | NEW |