[IDE] Refactoring: Expand a ternary operator into an if statement and vice-versa (#12554)

This commit is contained in:
Roman Roibu
2017-12-21 22:40:30 +02:00
committed by Xi Ge
parent 2c7ccd08a1
commit b2d122c4a7
14 changed files with 714 additions and 0 deletions

View File

@@ -224,6 +224,24 @@ func testSwitchExpand() {
let account: AccountType = .savings
switch account { }
}
func testExpandTernaryExpr() {
let a = 3
let b = 5
let x = a < 5 ? a : b
}
func testConvertToTernaryExpr() {
let a = 3
let b = 5
let x: Int
if a < 5 {
x = a
} else {
x = b
}
}
// 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
@@ -311,6 +329,9 @@ func testSwitchExpand() {
// RUN: %refactor -source-filename %s -pos=225:3 | %FileCheck %s -check-prefix=CHECK-EXPAND-SWITCH
// RUN: %refactor -source-filename %s -pos=231:3 -end-pos=231:24 | %FileCheck %s -check-prefix=CHECK-EXPAND-TERNARY-EXPRESSEXPRESSION
// RUN: %refactor -source-filename %s -pos=237:3 -end-pos=242:4 | %FileCheck %s -check-prefix=CHECK-CONVERT-TO-TERNARY-EXPRESSEXPRESSION
// CHECK1: Action begins
// CHECK1-NEXT: Extract Method
@@ -354,3 +375,7 @@ func testSwitchExpand() {
// CHECK-TRY-CATCH: Convert To Do/Catch
// CHECK-EXPAND-SWITCH: Expand Switch Cases
// CHECK-EXPAND-TERNARY-EXPRESSEXPRESSION: Expand Ternary Expression
// CHECK-CONVERT-TO-TERNARY-EXPRESSEXPRESSION: Convert To Ternary Expression