| 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/plugin/protocol/protocol.dart' hide Element; | 7 import 'package:analysis_server/plugin/protocol/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'; |
| 11 import 'package:test/test.dart'; | 11 import 'package:test/test.dart'; |
| 12 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 12 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 13 | 13 |
| 14 import 'abstract_refactoring.dart'; | 14 import 'abstract_refactoring.dart'; |
| 15 | 15 |
| 16 main() { | 16 main() { |
| 17 defineReflectiveSuite(() { | 17 defineReflectiveSuite(() { |
| 18 defineReflectiveTests(InlineLocalTest); | 18 defineReflectiveTests(InlineLocalTest); |
| 19 }); | 19 }); |
| 20 } | 20 } |
| 21 | 21 |
| 22 @reflectiveTest | 22 @reflectiveTest |
| 23 class InlineLocalTest extends RefactoringTest { | 23 class InlineLocalTest extends RefactoringTest { |
| 24 InlineLocalRefactoringImpl refactoring; | 24 InlineLocalRefactoringImpl refactoring; |
| 25 | 25 |
| 26 test_access() async { | 26 test_access() async { |
| 27 indexTestUnit(''' | 27 await indexTestUnit(''' |
| 28 main() { | 28 main() { |
| 29 int test = 1 + 2; | 29 int test = 1 + 2; |
| 30 print(test); | 30 print(test); |
| 31 print(test); | 31 print(test); |
| 32 } | 32 } |
| 33 '''); | 33 '''); |
| 34 _createRefactoring('test ='); | 34 _createRefactoring('test ='); |
| 35 expect(refactoring.refactoringName, 'Inline Local Variable'); | 35 expect(refactoring.refactoringName, 'Inline Local Variable'); |
| 36 // check initial conditions and access | 36 // check initial conditions and access |
| 37 await refactoring.checkInitialConditions(); | 37 await refactoring.checkInitialConditions(); |
| 38 expect(refactoring.variableName, 'test'); | 38 expect(refactoring.variableName, 'test'); |
| 39 expect(refactoring.referenceCount, 2); | 39 expect(refactoring.referenceCount, 2); |
| 40 } | 40 } |
| 41 | 41 |
| 42 test_bad_selectionMethod() async { | 42 test_bad_selectionMethod() async { |
| 43 indexTestUnit(r''' | 43 await indexTestUnit(r''' |
| 44 main() { | 44 main() { |
| 45 } | 45 } |
| 46 '''); | 46 '''); |
| 47 _createRefactoring('main() {'); | 47 _createRefactoring('main() {'); |
| 48 RefactoringStatus status = await refactoring.checkInitialConditions(); | 48 RefactoringStatus status = await refactoring.checkInitialConditions(); |
| 49 _assert_fatalError_selection(status); | 49 _assert_fatalError_selection(status); |
| 50 } | 50 } |
| 51 | 51 |
| 52 test_bad_selectionParameter() async { | 52 test_bad_selectionParameter() async { |
| 53 indexTestUnit(r''' | 53 await indexTestUnit(r''' |
| 54 main(int test) { | 54 main(int test) { |
| 55 } | 55 } |
| 56 '''); | 56 '''); |
| 57 _createRefactoring('test) {'); | 57 _createRefactoring('test) {'); |
| 58 RefactoringStatus status = await refactoring.checkInitialConditions(); | 58 RefactoringStatus status = await refactoring.checkInitialConditions(); |
| 59 _assert_fatalError_selection(status); | 59 _assert_fatalError_selection(status); |
| 60 } | 60 } |
| 61 | 61 |
| 62 test_bad_selectionVariable_hasAssignments_1() async { | 62 test_bad_selectionVariable_hasAssignments_1() async { |
| 63 indexTestUnit(r''' | 63 await indexTestUnit(r''' |
| 64 main() { | 64 main() { |
| 65 int test = 0; | 65 int test = 0; |
| 66 test = 1; | 66 test = 1; |
| 67 } | 67 } |
| 68 '''); | 68 '''); |
| 69 _createRefactoring('test = 0'); | 69 _createRefactoring('test = 0'); |
| 70 RefactoringStatus status = await refactoring.checkInitialConditions(); | 70 RefactoringStatus status = await refactoring.checkInitialConditions(); |
| 71 assertRefactoringStatus(status, RefactoringProblemSeverity.FATAL, | 71 assertRefactoringStatus(status, RefactoringProblemSeverity.FATAL, |
| 72 expectedContextSearch: 'test = 1'); | 72 expectedContextSearch: 'test = 1'); |
| 73 } | 73 } |
| 74 | 74 |
| 75 test_bad_selectionVariable_hasAssignments_2() async { | 75 test_bad_selectionVariable_hasAssignments_2() async { |
| 76 indexTestUnit(r''' | 76 await indexTestUnit(r''' |
| 77 main() { | 77 main() { |
| 78 int test = 0; | 78 int test = 0; |
| 79 test += 1; | 79 test += 1; |
| 80 } | 80 } |
| 81 '''); | 81 '''); |
| 82 _createRefactoring('test = 0'); | 82 _createRefactoring('test = 0'); |
| 83 RefactoringStatus status = await refactoring.checkInitialConditions(); | 83 RefactoringStatus status = await refactoring.checkInitialConditions(); |
| 84 assertRefactoringStatus(status, RefactoringProblemSeverity.FATAL, | 84 assertRefactoringStatus(status, RefactoringProblemSeverity.FATAL, |
| 85 expectedContextSearch: 'test += 1'); | 85 expectedContextSearch: 'test += 1'); |
| 86 } | 86 } |
| 87 | 87 |
| 88 test_bad_selectionVariable_notInBlock() async { | 88 test_bad_selectionVariable_notInBlock() async { |
| 89 indexTestUnit(r''' | 89 await indexTestUnit(r''' |
| 90 main() { | 90 main() { |
| 91 if (true) | 91 if (true) |
| 92 int test = 0; | 92 int test = 0; |
| 93 } | 93 } |
| 94 '''); | 94 '''); |
| 95 _createRefactoring('test = 0'); | 95 _createRefactoring('test = 0'); |
| 96 RefactoringStatus status = await refactoring.checkInitialConditions(); | 96 RefactoringStatus status = await refactoring.checkInitialConditions(); |
| 97 assertRefactoringStatus(status, RefactoringProblemSeverity.FATAL); | 97 assertRefactoringStatus(status, RefactoringProblemSeverity.FATAL); |
| 98 } | 98 } |
| 99 | 99 |
| 100 test_bad_selectionVariable_notInitialized() async { | 100 test_bad_selectionVariable_notInitialized() async { |
| 101 indexTestUnit(r''' | 101 await indexTestUnit(r''' |
| 102 main() { | 102 main() { |
| 103 int test; | 103 int test; |
| 104 } | 104 } |
| 105 '''); | 105 '''); |
| 106 _createRefactoring('test;'); | 106 _createRefactoring('test;'); |
| 107 RefactoringStatus status = await refactoring.checkInitialConditions(); | 107 RefactoringStatus status = await refactoring.checkInitialConditions(); |
| 108 assertRefactoringStatus(status, RefactoringProblemSeverity.FATAL); | 108 assertRefactoringStatus(status, RefactoringProblemSeverity.FATAL); |
| 109 } | 109 } |
| 110 | 110 |
| 111 test_OK_cascade_intoCascade() { | 111 test_OK_cascade_intoCascade() async { |
| 112 indexTestUnit(r''' | 112 await indexTestUnit(r''' |
| 113 class A { | 113 class A { |
| 114 foo() {} | 114 foo() {} |
| 115 bar() {} | 115 bar() {} |
| 116 } | 116 } |
| 117 main() { | 117 main() { |
| 118 A test = new A()..foo(); | 118 A test = new A()..foo(); |
| 119 test..bar(); | 119 test..bar(); |
| 120 } | 120 } |
| 121 '''); | 121 '''); |
| 122 _createRefactoring('test ='); | 122 _createRefactoring('test ='); |
| 123 // validate change | 123 // validate change |
| 124 return assertSuccessfulRefactoring(r''' | 124 return assertSuccessfulRefactoring(r''' |
| 125 class A { | 125 class A { |
| 126 foo() {} | 126 foo() {} |
| 127 bar() {} | 127 bar() {} |
| 128 } | 128 } |
| 129 main() { | 129 main() { |
| 130 new A()..foo()..bar(); | 130 new A()..foo()..bar(); |
| 131 } | 131 } |
| 132 '''); | 132 '''); |
| 133 } | 133 } |
| 134 | 134 |
| 135 test_OK_cascade_intoNotCascade() { | 135 test_OK_cascade_intoNotCascade() async { |
| 136 indexTestUnit(r''' | 136 await indexTestUnit(r''' |
| 137 class A { | 137 class A { |
| 138 foo() {} | 138 foo() {} |
| 139 bar() {} | 139 bar() {} |
| 140 } | 140 } |
| 141 main() { | 141 main() { |
| 142 A test = new A()..foo(); | 142 A test = new A()..foo(); |
| 143 test.bar(); | 143 test.bar(); |
| 144 } | 144 } |
| 145 '''); | 145 '''); |
| 146 _createRefactoring('test ='); | 146 _createRefactoring('test ='); |
| 147 // validate change | 147 // validate change |
| 148 return assertSuccessfulRefactoring(r''' | 148 return assertSuccessfulRefactoring(r''' |
| 149 class A { | 149 class A { |
| 150 foo() {} | 150 foo() {} |
| 151 bar() {} | 151 bar() {} |
| 152 } | 152 } |
| 153 main() { | 153 main() { |
| 154 (new A()..foo()).bar(); | 154 (new A()..foo()).bar(); |
| 155 } | 155 } |
| 156 '''); | 156 '''); |
| 157 } | 157 } |
| 158 | 158 |
| 159 test_OK_inSwitchCase() { | 159 test_OK_inSwitchCase() async { |
| 160 indexTestUnit(''' | 160 await indexTestUnit(''' |
| 161 main(int p) { | 161 main(int p) { |
| 162 switch (p) { | 162 switch (p) { |
| 163 case 0: | 163 case 0: |
| 164 int test = 42; | 164 int test = 42; |
| 165 print(test); | 165 print(test); |
| 166 break; | 166 break; |
| 167 } | 167 } |
| 168 } | 168 } |
| 169 '''); | 169 '''); |
| 170 _createRefactoring('test ='); | 170 _createRefactoring('test ='); |
| 171 // validate change | 171 // validate change |
| 172 return assertSuccessfulRefactoring(''' | 172 return assertSuccessfulRefactoring(''' |
| 173 main(int p) { | 173 main(int p) { |
| 174 switch (p) { | 174 switch (p) { |
| 175 case 0: | 175 case 0: |
| 176 print(42); | 176 print(42); |
| 177 break; | 177 break; |
| 178 } | 178 } |
| 179 } | 179 } |
| 180 '''); | 180 '''); |
| 181 } | 181 } |
| 182 | 182 |
| 183 test_OK_intoStringInterpolation_binaryExpression() { | 183 test_OK_intoStringInterpolation_binaryExpression() async { |
| 184 indexTestUnit(r''' | 184 await indexTestUnit(r''' |
| 185 main() { | 185 main() { |
| 186 int test = 1 + 2; | 186 int test = 1 + 2; |
| 187 print('test = $test'); | 187 print('test = $test'); |
| 188 print('test = ${test}'); | 188 print('test = ${test}'); |
| 189 print('test = ${process(test)}'); | 189 print('test = ${process(test)}'); |
| 190 } | 190 } |
| 191 process(x) {} | 191 process(x) {} |
| 192 '''); | 192 '''); |
| 193 _createRefactoring('test ='); | 193 _createRefactoring('test ='); |
| 194 // validate change | 194 // validate change |
| 195 return assertSuccessfulRefactoring(r''' | 195 return assertSuccessfulRefactoring(r''' |
| 196 main() { | 196 main() { |
| 197 print('test = ${1 + 2}'); | 197 print('test = ${1 + 2}'); |
| 198 print('test = ${1 + 2}'); | 198 print('test = ${1 + 2}'); |
| 199 print('test = ${process(1 + 2)}'); | 199 print('test = ${process(1 + 2)}'); |
| 200 } | 200 } |
| 201 process(x) {} | 201 process(x) {} |
| 202 '''); | 202 '''); |
| 203 } | 203 } |
| 204 | 204 |
| 205 test_OK_intoStringInterpolation_simpleIdentifier() { | 205 test_OK_intoStringInterpolation_simpleIdentifier() async { |
| 206 indexTestUnit(r''' | 206 await indexTestUnit(r''' |
| 207 main() { | 207 main() { |
| 208 int foo = 1 + 2; | 208 int foo = 1 + 2; |
| 209 int test = foo; | 209 int test = foo; |
| 210 print('test = $test'); | 210 print('test = $test'); |
| 211 print('test = ${test}'); | 211 print('test = ${test}'); |
| 212 print('test = ${process(test)}'); | 212 print('test = ${process(test)}'); |
| 213 } | 213 } |
| 214 process(x) {} | 214 process(x) {} |
| 215 '''); | 215 '''); |
| 216 _createRefactoring('test ='); | 216 _createRefactoring('test ='); |
| 217 // validate change | 217 // validate change |
| 218 return assertSuccessfulRefactoring(r''' | 218 return assertSuccessfulRefactoring(r''' |
| 219 main() { | 219 main() { |
| 220 int foo = 1 + 2; | 220 int foo = 1 + 2; |
| 221 print('test = $foo'); | 221 print('test = $foo'); |
| 222 print('test = ${foo}'); | 222 print('test = ${foo}'); |
| 223 print('test = ${process(foo)}'); | 223 print('test = ${process(foo)}'); |
| 224 } | 224 } |
| 225 process(x) {} | 225 process(x) {} |
| 226 '''); | 226 '''); |
| 227 } | 227 } |
| 228 | 228 |
| 229 test_OK_intoStringInterpolation_string_differentQuotes() { | 229 test_OK_intoStringInterpolation_string_differentQuotes() async { |
| 230 indexTestUnit(r''' | 230 await indexTestUnit(r''' |
| 231 main() { | 231 main() { |
| 232 String a = "aaa"; | 232 String a = "aaa"; |
| 233 String b = '$a bbb'; | 233 String b = '$a bbb'; |
| 234 } | 234 } |
| 235 '''); | 235 '''); |
| 236 _createRefactoring('a ='); | 236 _createRefactoring('a ='); |
| 237 // validate change | 237 // validate change |
| 238 return assertSuccessfulRefactoring(r''' | 238 return assertSuccessfulRefactoring(r''' |
| 239 main() { | 239 main() { |
| 240 String b = '${"aaa"} bbb'; | 240 String b = '${"aaa"} bbb'; |
| 241 } | 241 } |
| 242 '''); | 242 '''); |
| 243 } | 243 } |
| 244 | 244 |
| 245 test_OK_intoStringInterpolation_string_doubleQuotes() { | 245 test_OK_intoStringInterpolation_string_doubleQuotes() async { |
| 246 indexTestUnit(r''' | 246 await indexTestUnit(r''' |
| 247 main() { | 247 main() { |
| 248 String a = "aaa"; | 248 String a = "aaa"; |
| 249 String b = "$a bbb"; | 249 String b = "$a bbb"; |
| 250 } | 250 } |
| 251 '''); | 251 '''); |
| 252 _createRefactoring('a ='); | 252 _createRefactoring('a ='); |
| 253 // validate change | 253 // validate change |
| 254 return assertSuccessfulRefactoring(r''' | 254 return assertSuccessfulRefactoring(r''' |
| 255 main() { | 255 main() { |
| 256 String b = "aaa bbb"; | 256 String b = "aaa bbb"; |
| 257 } | 257 } |
| 258 '''); | 258 '''); |
| 259 } | 259 } |
| 260 | 260 |
| 261 test_OK_intoStringInterpolation_string_multiLineIntoMulti_leadingSpaces() { | 261 test_OK_intoStringInterpolation_string_multiLineIntoMulti_leadingSpaces() asyn
c { |
| 262 indexTestUnit(r""" | 262 await indexTestUnit(r""" |
| 263 main() { | 263 main() { |
| 264 String a = '''\ \ | 264 String a = '''\ \ |
| 265 a | 265 a |
| 266 a'''; | 266 a'''; |
| 267 String b = ''' | 267 String b = ''' |
| 268 $a | 268 $a |
| 269 bbb'''; | 269 bbb'''; |
| 270 } | 270 } |
| 271 """); | 271 """); |
| 272 _createRefactoring('a ='); | 272 _createRefactoring('a ='); |
| 273 // validate change | 273 // validate change |
| 274 return assertSuccessfulRefactoring(r""" | 274 return assertSuccessfulRefactoring(r""" |
| 275 main() { | 275 main() { |
| 276 String b = ''' | 276 String b = ''' |
| 277 a | 277 a |
| 278 a | 278 a |
| 279 bbb'''; | 279 bbb'''; |
| 280 } | 280 } |
| 281 """); | 281 """); |
| 282 } | 282 } |
| 283 | 283 |
| 284 test_OK_intoStringInterpolation_string_multiLineIntoMulti_unixEOL() { | 284 test_OK_intoStringInterpolation_string_multiLineIntoMulti_unixEOL() async { |
| 285 indexTestUnit(r""" | 285 await indexTestUnit(r""" |
| 286 main() { | 286 main() { |
| 287 String a = ''' | 287 String a = ''' |
| 288 a | 288 a |
| 289 a | 289 a |
| 290 a'''; | 290 a'''; |
| 291 String b = ''' | 291 String b = ''' |
| 292 $a | 292 $a |
| 293 bbb'''; | 293 bbb'''; |
| 294 } | 294 } |
| 295 """); | 295 """); |
| 296 _createRefactoring('a ='); | 296 _createRefactoring('a ='); |
| 297 // validate change | 297 // validate change |
| 298 return assertSuccessfulRefactoring(r""" | 298 return assertSuccessfulRefactoring(r""" |
| 299 main() { | 299 main() { |
| 300 String b = ''' | 300 String b = ''' |
| 301 a | 301 a |
| 302 a | 302 a |
| 303 a | 303 a |
| 304 bbb'''; | 304 bbb'''; |
| 305 } | 305 } |
| 306 """); | 306 """); |
| 307 } | 307 } |
| 308 | 308 |
| 309 test_OK_intoStringInterpolation_string_multiLineIntoMulti_windowsEOL() { | 309 test_OK_intoStringInterpolation_string_multiLineIntoMulti_windowsEOL() async { |
| 310 indexTestUnit(r""" | 310 await indexTestUnit(r""" |
| 311 main() { | 311 main() { |
| 312 String a = ''' | 312 String a = ''' |
| 313 a | 313 a |
| 314 a | 314 a |
| 315 a'''; | 315 a'''; |
| 316 String b = ''' | 316 String b = ''' |
| 317 $a | 317 $a |
| 318 bbb'''; | 318 bbb'''; |
| 319 } | 319 } |
| 320 """ | 320 """ |
| 321 .replaceAll('\n', '\r\n')); | 321 .replaceAll('\n', '\r\n')); |
| 322 _createRefactoring('a ='); | 322 _createRefactoring('a ='); |
| 323 // validate change | 323 // validate change |
| 324 return assertSuccessfulRefactoring(r""" | 324 return assertSuccessfulRefactoring(r""" |
| 325 main() { | 325 main() { |
| 326 String b = ''' | 326 String b = ''' |
| 327 a | 327 a |
| 328 a | 328 a |
| 329 a | 329 a |
| 330 bbb'''; | 330 bbb'''; |
| 331 } | 331 } |
| 332 """ | 332 """ |
| 333 .replaceAll('\n', '\r\n')); | 333 .replaceAll('\n', '\r\n')); |
| 334 } | 334 } |
| 335 | 335 |
| 336 test_OK_intoStringInterpolation_string_multiLineIntoSingle() { | 336 test_OK_intoStringInterpolation_string_multiLineIntoSingle() async { |
| 337 indexTestUnit(r''' | 337 await indexTestUnit(r''' |
| 338 main() { | 338 main() { |
| 339 String a = """aaa"""; | 339 String a = """aaa"""; |
| 340 String b = "$a bbb"; | 340 String b = "$a bbb"; |
| 341 } | 341 } |
| 342 '''); | 342 '''); |
| 343 _createRefactoring('a ='); | 343 _createRefactoring('a ='); |
| 344 // validate change | 344 // validate change |
| 345 return assertSuccessfulRefactoring(r''' | 345 return assertSuccessfulRefactoring(r''' |
| 346 main() { | 346 main() { |
| 347 String b = "${"""aaa"""} bbb"; | 347 String b = "${"""aaa"""} bbb"; |
| 348 } | 348 } |
| 349 '''); | 349 '''); |
| 350 } | 350 } |
| 351 | 351 |
| 352 test_OK_intoStringInterpolation_string_raw() { | 352 test_OK_intoStringInterpolation_string_raw() async { |
| 353 indexTestUnit(r''' | 353 await indexTestUnit(r''' |
| 354 main() { | 354 main() { |
| 355 String a = r'an $ignored interpolation'; | 355 String a = r'an $ignored interpolation'; |
| 356 String b = '$a bbb'; | 356 String b = '$a bbb'; |
| 357 } | 357 } |
| 358 '''); | 358 '''); |
| 359 _createRefactoring('a ='); | 359 _createRefactoring('a ='); |
| 360 // we don't unwrap raw strings | 360 // we don't unwrap raw strings |
| 361 return assertSuccessfulRefactoring(r''' | 361 return assertSuccessfulRefactoring(r''' |
| 362 main() { | 362 main() { |
| 363 String b = '${r'an $ignored interpolation'} bbb'; | 363 String b = '${r'an $ignored interpolation'} bbb'; |
| 364 } | 364 } |
| 365 '''); | 365 '''); |
| 366 } | 366 } |
| 367 | 367 |
| 368 test_OK_intoStringInterpolation_string_singleLineIntoMulti_doubleQuotes() { | 368 test_OK_intoStringInterpolation_string_singleLineIntoMulti_doubleQuotes() asyn
c { |
| 369 indexTestUnit(r''' | 369 await indexTestUnit(r''' |
| 370 main() { | 370 main() { |
| 371 String a = "aaa"; | 371 String a = "aaa"; |
| 372 String b = """$a bbb"""; | 372 String b = """$a bbb"""; |
| 373 } | 373 } |
| 374 '''); | 374 '''); |
| 375 _createRefactoring('a ='); | 375 _createRefactoring('a ='); |
| 376 // validate change | 376 // validate change |
| 377 return assertSuccessfulRefactoring(r''' | 377 return assertSuccessfulRefactoring(r''' |
| 378 main() { | 378 main() { |
| 379 String b = """aaa bbb"""; | 379 String b = """aaa bbb"""; |
| 380 } | 380 } |
| 381 '''); | 381 '''); |
| 382 } | 382 } |
| 383 | 383 |
| 384 test_OK_intoStringInterpolation_string_singleLineIntoMulti_singleQuotes() { | 384 test_OK_intoStringInterpolation_string_singleLineIntoMulti_singleQuotes() asyn
c { |
| 385 indexTestUnit(r""" | 385 await indexTestUnit(r""" |
| 386 main() { | 386 main() { |
| 387 String a = 'aaa'; | 387 String a = 'aaa'; |
| 388 String b = '''$a bbb'''; | 388 String b = '''$a bbb'''; |
| 389 } | 389 } |
| 390 """); | 390 """); |
| 391 _createRefactoring('a ='); | 391 _createRefactoring('a ='); |
| 392 // validate change | 392 // validate change |
| 393 return assertSuccessfulRefactoring(r""" | 393 return assertSuccessfulRefactoring(r""" |
| 394 main() { | 394 main() { |
| 395 String b = '''aaa bbb'''; | 395 String b = '''aaa bbb'''; |
| 396 } | 396 } |
| 397 """); | 397 """); |
| 398 } | 398 } |
| 399 | 399 |
| 400 test_OK_intoStringInterpolation_string_singleQuotes() { | 400 test_OK_intoStringInterpolation_string_singleQuotes() async { |
| 401 indexTestUnit(r''' | 401 await indexTestUnit(r''' |
| 402 main() { | 402 main() { |
| 403 String a = 'aaa'; | 403 String a = 'aaa'; |
| 404 String b = '$a bbb'; | 404 String b = '$a bbb'; |
| 405 } | 405 } |
| 406 '''); | 406 '''); |
| 407 _createRefactoring('a ='); | 407 _createRefactoring('a ='); |
| 408 // validate change | 408 // validate change |
| 409 return assertSuccessfulRefactoring(r''' | 409 return assertSuccessfulRefactoring(r''' |
| 410 main() { | 410 main() { |
| 411 String b = 'aaa bbb'; | 411 String b = 'aaa bbb'; |
| 412 } | 412 } |
| 413 '''); | 413 '''); |
| 414 } | 414 } |
| 415 | 415 |
| 416 test_OK_intoStringInterpolation_stringInterpolation() { | 416 test_OK_intoStringInterpolation_stringInterpolation() async { |
| 417 indexTestUnit(r''' | 417 await indexTestUnit(r''' |
| 418 main() { | 418 main() { |
| 419 String a = 'aaa'; | 419 String a = 'aaa'; |
| 420 String b = '$a bbb'; | 420 String b = '$a bbb'; |
| 421 String c = '$b ccc'; | 421 String c = '$b ccc'; |
| 422 } | 422 } |
| 423 '''); | 423 '''); |
| 424 _createRefactoring('b ='); | 424 _createRefactoring('b ='); |
| 425 // validate change | 425 // validate change |
| 426 return assertSuccessfulRefactoring(r''' | 426 return assertSuccessfulRefactoring(r''' |
| 427 main() { | 427 main() { |
| 428 String a = 'aaa'; | 428 String a = 'aaa'; |
| 429 String c = '$a bbb ccc'; | 429 String c = '$a bbb ccc'; |
| 430 } | 430 } |
| 431 '''); | 431 '''); |
| 432 } | 432 } |
| 433 | 433 |
| 434 /** | 434 /** |
| 435 * <p> | 435 * <p> |
| 436 * https://code.google.com/p/dart/issues/detail?id=18587 | 436 * https://code.google.com/p/dart/issues/detail?id=18587 |
| 437 */ | 437 */ |
| 438 test_OK_keepNextCommentedLine() { | 438 test_OK_keepNextCommentedLine() async { |
| 439 indexTestUnit(''' | 439 await indexTestUnit(''' |
| 440 main() { | 440 main() { |
| 441 int test = 1 + 2; | 441 int test = 1 + 2; |
| 442 // foo | 442 // foo |
| 443 print(test); | 443 print(test); |
| 444 // bar | 444 // bar |
| 445 } | 445 } |
| 446 '''); | 446 '''); |
| 447 _createRefactoring('test ='); | 447 _createRefactoring('test ='); |
| 448 // validate change | 448 // validate change |
| 449 return assertSuccessfulRefactoring(''' | 449 return assertSuccessfulRefactoring(''' |
| 450 main() { | 450 main() { |
| 451 // foo | 451 // foo |
| 452 print(1 + 2); | 452 print(1 + 2); |
| 453 // bar | 453 // bar |
| 454 } | 454 } |
| 455 '''); | 455 '''); |
| 456 } | 456 } |
| 457 | 457 |
| 458 test_OK_noUsages_1() { | 458 test_OK_noUsages_1() async { |
| 459 indexTestUnit(''' | 459 await indexTestUnit(''' |
| 460 main() { | 460 main() { |
| 461 int test = 1 + 2; | 461 int test = 1 + 2; |
| 462 print(0); | 462 print(0); |
| 463 } | 463 } |
| 464 '''); | 464 '''); |
| 465 _createRefactoring('test ='); | 465 _createRefactoring('test ='); |
| 466 // validate change | 466 // validate change |
| 467 return assertSuccessfulRefactoring(''' | 467 return assertSuccessfulRefactoring(''' |
| 468 main() { | 468 main() { |
| 469 print(0); | 469 print(0); |
| 470 } | 470 } |
| 471 '''); | 471 '''); |
| 472 } | 472 } |
| 473 | 473 |
| 474 test_OK_noUsages_2() { | 474 test_OK_noUsages_2() async { |
| 475 indexTestUnit(''' | 475 await indexTestUnit(''' |
| 476 main() { | 476 main() { |
| 477 int test = 1 + 2; | 477 int test = 1 + 2; |
| 478 } | 478 } |
| 479 '''); | 479 '''); |
| 480 _createRefactoring('test ='); | 480 _createRefactoring('test ='); |
| 481 // validate change | 481 // validate change |
| 482 return assertSuccessfulRefactoring(''' | 482 return assertSuccessfulRefactoring(''' |
| 483 main() { | 483 main() { |
| 484 } | 484 } |
| 485 '''); | 485 '''); |
| 486 } | 486 } |
| 487 | 487 |
| 488 test_OK_oneUsage() { | 488 test_OK_oneUsage() async { |
| 489 indexTestUnit(''' | 489 await indexTestUnit(''' |
| 490 main() { | 490 main() { |
| 491 int test = 1 + 2; | 491 int test = 1 + 2; |
| 492 print(test); | 492 print(test); |
| 493 } | 493 } |
| 494 '''); | 494 '''); |
| 495 _createRefactoring('test ='); | 495 _createRefactoring('test ='); |
| 496 // validate change | 496 // validate change |
| 497 return assertSuccessfulRefactoring(''' | 497 return assertSuccessfulRefactoring(''' |
| 498 main() { | 498 main() { |
| 499 print(1 + 2); | 499 print(1 + 2); |
| 500 } | 500 } |
| 501 '''); | 501 '''); |
| 502 } | 502 } |
| 503 | 503 |
| 504 test_OK_parenthesis_decrement_intoNegate() { | 504 test_OK_parenthesis_decrement_intoNegate() async { |
| 505 indexTestUnit(''' | 505 await indexTestUnit(''' |
| 506 main() { | 506 main() { |
| 507 var a = 1; | 507 var a = 1; |
| 508 var test = --a; | 508 var test = --a; |
| 509 var b = -test; | 509 var b = -test; |
| 510 } | 510 } |
| 511 '''); | 511 '''); |
| 512 _createRefactoring('test ='); | 512 _createRefactoring('test ='); |
| 513 // validate change | 513 // validate change |
| 514 return assertSuccessfulRefactoring(''' | 514 return assertSuccessfulRefactoring(''' |
| 515 main() { | 515 main() { |
| 516 var a = 1; | 516 var a = 1; |
| 517 var b = -(--a); | 517 var b = -(--a); |
| 518 } | 518 } |
| 519 '''); | 519 '''); |
| 520 } | 520 } |
| 521 | 521 |
| 522 test_OK_parenthesis_instanceCreation_intoList() { | 522 test_OK_parenthesis_instanceCreation_intoList() async { |
| 523 indexTestUnit(''' | 523 await indexTestUnit(''' |
| 524 class A {} | 524 class A {} |
| 525 main() { | 525 main() { |
| 526 var test = new A(); | 526 var test = new A(); |
| 527 var list = [test]; | 527 var list = [test]; |
| 528 } | 528 } |
| 529 '''); | 529 '''); |
| 530 _createRefactoring('test ='); | 530 _createRefactoring('test ='); |
| 531 // validate change | 531 // validate change |
| 532 return assertSuccessfulRefactoring(''' | 532 return assertSuccessfulRefactoring(''' |
| 533 class A {} | 533 class A {} |
| 534 main() { | 534 main() { |
| 535 var list = [new A()]; | 535 var list = [new A()]; |
| 536 } | 536 } |
| 537 '''); | 537 '''); |
| 538 } | 538 } |
| 539 | 539 |
| 540 test_OK_parenthesis_intoIndexExpression_index() { | 540 test_OK_parenthesis_intoIndexExpression_index() async { |
| 541 indexTestUnit(''' | 541 await indexTestUnit(''' |
| 542 main() { | 542 main() { |
| 543 var items = []; | 543 var items = []; |
| 544 var test = 1 + 2; | 544 var test = 1 + 2; |
| 545 items[test] * 5; | 545 items[test] * 5; |
| 546 } | 546 } |
| 547 '''); | 547 '''); |
| 548 _createRefactoring('test ='); | 548 _createRefactoring('test ='); |
| 549 // validate change | 549 // validate change |
| 550 return assertSuccessfulRefactoring(''' | 550 return assertSuccessfulRefactoring(''' |
| 551 main() { | 551 main() { |
| 552 var items = []; | 552 var items = []; |
| 553 items[1 + 2] * 5; | 553 items[1 + 2] * 5; |
| 554 } | 554 } |
| 555 '''); | 555 '''); |
| 556 } | 556 } |
| 557 | 557 |
| 558 test_OK_parenthesis_intoParenthesizedExpression() { | 558 test_OK_parenthesis_intoParenthesizedExpression() async { |
| 559 indexTestUnit(''' | 559 await indexTestUnit(''' |
| 560 f(m, x, y) { | 560 f(m, x, y) { |
| 561 int test = x as int; | 561 int test = x as int; |
| 562 m[test] = y; | 562 m[test] = y; |
| 563 return m[test]; | 563 return m[test]; |
| 564 } | 564 } |
| 565 '''); | 565 '''); |
| 566 _createRefactoring('test ='); | 566 _createRefactoring('test ='); |
| 567 // validate change | 567 // validate change |
| 568 return assertSuccessfulRefactoring(''' | 568 return assertSuccessfulRefactoring(''' |
| 569 f(m, x, y) { | 569 f(m, x, y) { |
| 570 m[x as int] = y; | 570 m[x as int] = y; |
| 571 return m[x as int]; | 571 return m[x as int]; |
| 572 } | 572 } |
| 573 '''); | 573 '''); |
| 574 } | 574 } |
| 575 | 575 |
| 576 test_OK_parenthesis_negate_intoNegate() { | 576 test_OK_parenthesis_negate_intoNegate() async { |
| 577 indexTestUnit(''' | 577 await indexTestUnit(''' |
| 578 main() { | 578 main() { |
| 579 var a = 1; | 579 var a = 1; |
| 580 var test = -a; | 580 var test = -a; |
| 581 var b = -test; | 581 var b = -test; |
| 582 } | 582 } |
| 583 '''); | 583 '''); |
| 584 _createRefactoring('test ='); | 584 _createRefactoring('test ='); |
| 585 // validate change | 585 // validate change |
| 586 return assertSuccessfulRefactoring(''' | 586 return assertSuccessfulRefactoring(''' |
| 587 main() { | 587 main() { |
| 588 var a = 1; | 588 var a = 1; |
| 589 var b = -(-a); | 589 var b = -(-a); |
| 590 } | 590 } |
| 591 '''); | 591 '''); |
| 592 } | 592 } |
| 593 | 593 |
| 594 test_OK_parenthesis_plus_intoMultiply() { | 594 test_OK_parenthesis_plus_intoMultiply() async { |
| 595 indexTestUnit(''' | 595 await indexTestUnit(''' |
| 596 main() { | 596 main() { |
| 597 var test = 1 + 2; | 597 var test = 1 + 2; |
| 598 print(test * 3); | 598 print(test * 3); |
| 599 } | 599 } |
| 600 '''); | 600 '''); |
| 601 _createRefactoring('test ='); | 601 _createRefactoring('test ='); |
| 602 // validate change | 602 // validate change |
| 603 return assertSuccessfulRefactoring(''' | 603 return assertSuccessfulRefactoring(''' |
| 604 main() { | 604 main() { |
| 605 print((1 + 2) * 3); | 605 print((1 + 2) * 3); |
| 606 } | 606 } |
| 607 '''); | 607 '''); |
| 608 } | 608 } |
| 609 | 609 |
| 610 test_OK_twoUsages() { | 610 test_OK_twoUsages() async { |
| 611 indexTestUnit(''' | 611 await indexTestUnit(''' |
| 612 main() { | 612 main() { |
| 613 int test = 1 + 2; | 613 int test = 1 + 2; |
| 614 print(test); | 614 print(test); |
| 615 print(test); | 615 print(test); |
| 616 } | 616 } |
| 617 '''); | 617 '''); |
| 618 _createRefactoring('test ='); | 618 _createRefactoring('test ='); |
| 619 // validate change | 619 // validate change |
| 620 return assertSuccessfulRefactoring(''' | 620 return assertSuccessfulRefactoring(''' |
| 621 main() { | 621 main() { |
| 622 print(1 + 2); | 622 print(1 + 2); |
| 623 print(1 + 2); | 623 print(1 + 2); |
| 624 } | 624 } |
| 625 '''); | 625 '''); |
| 626 } | 626 } |
| 627 | 627 |
| 628 void _assert_fatalError_selection(RefactoringStatus status) { | 628 void _assert_fatalError_selection(RefactoringStatus status) { |
| 629 expect(refactoring.variableName, isNull); | 629 expect(refactoring.variableName, isNull); |
| 630 expect(refactoring.referenceCount, 0); | 630 expect(refactoring.referenceCount, 0); |
| 631 assertRefactoringStatus(status, RefactoringProblemSeverity.FATAL, | 631 assertRefactoringStatus(status, RefactoringProblemSeverity.FATAL, |
| 632 expectedMessage: 'Local variable declaration or reference must be ' | 632 expectedMessage: 'Local variable declaration or reference must be ' |
| 633 'selected to activate this refactoring.'); | 633 'selected to activate this refactoring.'); |
| 634 } | 634 } |
| 635 | 635 |
| 636 void _createRefactoring(String search) { | 636 void _createRefactoring(String search) { |
| 637 int offset = findOffset(search); | 637 int offset = findOffset(search); |
| 638 refactoring = new InlineLocalRefactoring(searchEngine, testUnit, offset); | 638 refactoring = new InlineLocalRefactoring(searchEngine, testUnit, offset); |
| 639 } | 639 } |
| 640 } | 640 } |
| OLD | NEW |