SR-5744 Refactoring action to convert if-let to guard-let and vice versa

This commit is contained in:
Власов Антон Вячеславович
2019-04-17 13:24:40 +03:00
parent 749a9726ef
commit 8acd794935
13 changed files with 522 additions and 0 deletions

View File

@@ -262,6 +262,20 @@ func testConvertToTernaryExpr() {
}
}
func testConvertToGuardExpr(idxOpt: Int?) {
if let idx = idxOpt {
print(idx)
}
}
func testConvertToIfLetExpr(idxOpt: Int?) {
guard let idx = idxOpt else {
return
}
print(idx)
}
// RUN: %refactor -source-filename %s -pos=2:1 -end-pos=5:13 | %FileCheck %s -check-prefix=CHECK1
// RUN: %refactor -source-filename %s -pos=3:1 -end-pos=5:13 | %FileCheck %s -check-prefix=CHECK1
// RUN: %refactor -source-filename %s -pos=4:1 -end-pos=5:13 | %FileCheck %s -check-prefix=CHECK1
@@ -355,6 +369,10 @@ func testConvertToTernaryExpr() {
// RUN: %refactor -source-filename %s -pos=257:3 -end-pos=262:4 | %FileCheck %s -check-prefix=CHECK-CONVERT-TO-TERNARY-EXPRESSEXPRESSION
// RUN: %refactor -source-filename %s -pos=266:3 -end-pos=268:4 | %FileCheck %s -check-prefix=CHECK-CONVERT-TO-GUARD-EXPRESSION
// RUN: %refactor -source-filename %s -pos=272:3 -end-pos=275:13 | %FileCheck %s -check-prefix=CHECK-CONVERT-TO-IFLET-EXPRESSION
// CHECK1: Action begins
// CHECK1-NEXT: Extract Method
// CHECK1-NEXT: Action ends
@@ -401,3 +419,7 @@ func testConvertToTernaryExpr() {
// CHECK-EXPAND-TERNARY-EXPRESSEXPRESSION: Expand Ternary Expression
// CHECK-CONVERT-TO-TERNARY-EXPRESSEXPRESSION: Convert To Ternary Expression
// CHECK-CONVERT-TO-GUARD-EXPRESSION: Convert To Guard Expression
// CHECK-CONVERT-TO-IFLET-EXPRESSION: Convert To IfLet Expression