mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[IDE] Refactoring: Expand a ternary operator into an if statement and vice-versa (#12554)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user