| 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.inline_local; | 5 library test.services.refactoring.inline_local; |
| 6 | 6 |
| 7 import 'package:analysis_server/src/protocol.dart' hide Element; | 7 import 'package:analysis_server/src/protocol.dart' hide Element; |
| 8 import 'package:analysis_server/src/services/correction/status.dart'; | 8 import 'package:analysis_server/src/services/correction/status.dart'; |
| 9 import 'package:analysis_server/src/services/refactoring/inline_local.dart'; | 9 import 'package:analysis_server/src/services/refactoring/inline_local.dart'; |
| 10 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; | 10 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 class A { | 65 class A { |
| 66 foo() {} | 66 foo() {} |
| 67 bar() {} | 67 bar() {} |
| 68 } | 68 } |
| 69 main() { | 69 main() { |
| 70 (new A()..foo()).bar(); | 70 (new A()..foo()).bar(); |
| 71 } | 71 } |
| 72 '''); | 72 '''); |
| 73 } | 73 } |
| 74 | 74 |
| 75 test_OK_intoStringInterpolation() { | 75 test_OK_intoStringInterpolation_binaryExpression() { |
| 76 indexTestUnit(r''' | 76 indexTestUnit(r''' |
| 77 main() { | 77 main() { |
| 78 int test = 1 + 2; | 78 int test = 1 + 2; |
| 79 print('test = $test'); | 79 print('test = $test'); |
| 80 print('test = ${test}'); | 80 print('test = ${test}'); |
| 81 print('test = ${process(test)}'); | 81 print('test = ${process(test)}'); |
| 82 } | 82 } |
| 83 process(x) {} | 83 process(x) {} |
| 84 '''); | 84 '''); |
| 85 _createRefactoring('test ='); | 85 _createRefactoring('test ='); |
| 86 // validate change | 86 // validate change |
| 87 return assertSuccessfulRefactoring(r''' | 87 return assertSuccessfulRefactoring(r''' |
| 88 main() { | 88 main() { |
| 89 print('test = ${1 + 2}'); | 89 print('test = ${1 + 2}'); |
| 90 print('test = ${1 + 2}'); | 90 print('test = ${1 + 2}'); |
| 91 print('test = ${process(1 + 2)}'); | 91 print('test = ${process(1 + 2)}'); |
| 92 } | 92 } |
| 93 process(x) {} | 93 process(x) {} |
| 94 '''); | 94 '''); |
| 95 } | 95 } |
| 96 | 96 |
| 97 test_OK_intoStringInterpolation_simpleIdentifier() { |
| 98 indexTestUnit(r''' |
| 99 main() { |
| 100 int foo = 1 + 2; |
| 101 int test = foo; |
| 102 print('test = $test'); |
| 103 print('test = ${test}'); |
| 104 print('test = ${process(test)}'); |
| 105 } |
| 106 process(x) {} |
| 107 '''); |
| 108 _createRefactoring('test ='); |
| 109 // validate change |
| 110 return assertSuccessfulRefactoring(r''' |
| 111 main() { |
| 112 int foo = 1 + 2; |
| 113 print('test = $foo'); |
| 114 print('test = ${foo}'); |
| 115 print('test = ${process(foo)}'); |
| 116 } |
| 117 process(x) {} |
| 118 '''); |
| 119 } |
| 120 |
| 121 test_OK_intoStringInterpolation_string() { |
| 122 indexTestUnit(r''' |
| 123 main() { |
| 124 String a = 'aaa'; |
| 125 String b = '$a bbb'; |
| 126 } |
| 127 '''); |
| 128 _createRefactoring('a ='); |
| 129 // validate change |
| 130 return assertSuccessfulRefactoring(r''' |
| 131 main() { |
| 132 String b = 'aaa bbb'; |
| 133 } |
| 134 '''); |
| 135 } |
| 136 |
| 137 test_OK_intoStringInterpolation_stringInterpolation() { |
| 138 indexTestUnit(r''' |
| 139 main() { |
| 140 String a = 'aaa'; |
| 141 String b = '$a bbb'; |
| 142 String c = '$b ccc'; |
| 143 } |
| 144 '''); |
| 145 _createRefactoring('b ='); |
| 146 // validate change |
| 147 return assertSuccessfulRefactoring(r''' |
| 148 main() { |
| 149 String a = 'aaa'; |
| 150 String c = '$a bbb ccc'; |
| 151 } |
| 152 '''); |
| 153 } |
| 154 |
| 155 test_OK_intoStringInterpolation_string_differentQuotes() { |
| 156 indexTestUnit(r''' |
| 157 main() { |
| 158 String a = "aaa"; |
| 159 String b = '$a bbb'; |
| 160 } |
| 161 '''); |
| 162 _createRefactoring('a ='); |
| 163 // validate change |
| 164 return assertSuccessfulRefactoring(r''' |
| 165 main() { |
| 166 String b = '${"aaa"} bbb'; |
| 167 } |
| 168 '''); |
| 169 } |
| 170 |
| 171 test_OK_intoStringInterpolation_string_multiLineIntoMulti_unixEOL() { |
| 172 indexTestUnit(r""" |
| 173 main() { |
| 174 String a = ''' |
| 175 a |
| 176 a |
| 177 a'''; |
| 178 String b = ''' |
| 179 $a |
| 180 bbb'''; |
| 181 } |
| 182 """); |
| 183 _createRefactoring('a ='); |
| 184 // validate change |
| 185 return assertSuccessfulRefactoring(r""" |
| 186 main() { |
| 187 String b = ''' |
| 188 a |
| 189 a |
| 190 a |
| 191 bbb'''; |
| 192 } |
| 193 """); |
| 194 } |
| 195 |
| 196 test_OK_intoStringInterpolation_string_multiLineIntoMulti_windowsEOL() { |
| 197 indexTestUnit(r""" |
| 198 main() { |
| 199 String a = ''' |
| 200 a |
| 201 a |
| 202 a'''; |
| 203 String b = ''' |
| 204 $a |
| 205 bbb'''; |
| 206 } |
| 207 """.replaceAll('\n', '\r\n')); |
| 208 _createRefactoring('a ='); |
| 209 // validate change |
| 210 return assertSuccessfulRefactoring(r""" |
| 211 main() { |
| 212 String b = ''' |
| 213 a |
| 214 a |
| 215 a |
| 216 bbb'''; |
| 217 } |
| 218 """.replaceAll('\n', '\r\n')); |
| 219 } |
| 220 |
| 221 test_OK_intoStringInterpolation_string_multiLineIntoSingle() { |
| 222 indexTestUnit(r''' |
| 223 main() { |
| 224 String a = """aaa"""; |
| 225 String b = "$a bbb"; |
| 226 } |
| 227 '''); |
| 228 _createRefactoring('a ='); |
| 229 // validate change |
| 230 return assertSuccessfulRefactoring(r''' |
| 231 main() { |
| 232 String b = "${"""aaa"""} bbb"; |
| 233 } |
| 234 '''); |
| 235 } |
| 236 |
| 237 test_OK_intoStringInterpolation_string_raw() { |
| 238 indexTestUnit(r''' |
| 239 main() { |
| 240 String a = r'an $ignored interpolation'; |
| 241 String b = '$a bbb'; |
| 242 } |
| 243 '''); |
| 244 _createRefactoring('a ='); |
| 245 // we don't unwrap raw strings |
| 246 return assertSuccessfulRefactoring(r''' |
| 247 main() { |
| 248 String b = '${r'an $ignored interpolation'} bbb'; |
| 249 } |
| 250 '''); |
| 251 } |
| 252 |
| 253 test_OK_intoStringInterpolation_string_singleLineIntoMulti_double() { |
| 254 indexTestUnit(r''' |
| 255 main() { |
| 256 String a = "aaa"; |
| 257 String b = """$a bbb"""; |
| 258 } |
| 259 '''); |
| 260 _createRefactoring('a ='); |
| 261 // validate change |
| 262 return assertSuccessfulRefactoring(r''' |
| 263 main() { |
| 264 String b = """aaa bbb"""; |
| 265 } |
| 266 '''); |
| 267 } |
| 268 |
| 269 test_OK_intoStringInterpolation_string_singleLineIntoMulti_single() { |
| 270 indexTestUnit(r""" |
| 271 main() { |
| 272 String a = 'aaa'; |
| 273 String b = '''$a bbb'''; |
| 274 } |
| 275 """); |
| 276 _createRefactoring('a ='); |
| 277 // validate change |
| 278 return assertSuccessfulRefactoring(r""" |
| 279 main() { |
| 280 String b = '''aaa bbb'''; |
| 281 } |
| 282 """); |
| 283 } |
| 284 |
| 97 /** | 285 /** |
| 98 * <p> | 286 * <p> |
| 99 * https://code.google.com/p/dart/issues/detail?id=18587 | 287 * https://code.google.com/p/dart/issues/detail?id=18587 |
| 100 */ | 288 */ |
| 101 test_OK_keepNextCommentedLine() { | 289 test_OK_keepNextCommentedLine() { |
| 102 indexTestUnit(''' | 290 indexTestUnit(''' |
| 103 main() { | 291 main() { |
| 104 int test = 1 + 2; | 292 int test = 1 + 2; |
| 105 // foo | 293 // foo |
| 106 print(test); | 294 print(test); |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 RefactoringProblemSeverity.FATAL, | 508 RefactoringProblemSeverity.FATAL, |
| 321 expectedMessage: 'Local variable declaration or reference must be ' | 509 expectedMessage: 'Local variable declaration or reference must be ' |
| 322 'selected to activate this refactoring.'); | 510 'selected to activate this refactoring.'); |
| 323 } | 511 } |
| 324 | 512 |
| 325 void _createRefactoring(String search) { | 513 void _createRefactoring(String search) { |
| 326 int offset = findOffset(search); | 514 int offset = findOffset(search); |
| 327 refactoring = new InlineLocalRefactoring(searchEngine, testUnit, offset); | 515 refactoring = new InlineLocalRefactoring(searchEngine, testUnit, offset); |
| 328 } | 516 } |
| 329 } | 517 } |
| OLD | NEW |