-
Notifications
You must be signed in to change notification settings - Fork 10.5k
/
Copy pathbasic.swift
42 lines (34 loc) · 1.16 KB
/
basic.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
func foo(idxOpt: Int?) {
if let idx = idxOpt {
print(idx)
}
}
func bar(fooOpt: Int?) {
if let foo = fooOpt {
let incrementedFoo = foo + 1
print(incrementedFoo)
}
}
func fooBar(fooOpt: Int?) {
if let foo = fooOpt {
let incrementedFoo = foo + 1
print(incrementedFoo)
print(foo)
}
}
func barFoo(idxOpt: Int?) {
if let idx = idxOpt {
print(idx)
} else {
print("nil")
}
}
// RUN: rm -rf %t.result && mkdir -p %t.result
// RUN: %refactor -convert-to-guard -source-filename %s -pos=2:3 -end-pos=4:4 > %t.result/L2-3.swift
// RUN: diff -u %S/Outputs/basic/L2-3.swift.expected %t.result/L2-3.swift
// RUN: %refactor -convert-to-guard -source-filename %s -pos=8:3 -end-pos=11:4 > %t.result/L8-3.swift
// RUN: diff -u %S/Outputs/basic/L8-3.swift.expected %t.result/L8-3.swift
// RUN: %refactor -convert-to-guard -source-filename %s -pos=15:3 -end-pos=19:4 > %t.result/L15-3.swift
// RUN: diff -u %S/Outputs/basic/L15-3.swift.expected %t.result/L15-3.swift
// RUN: %refactor -convert-to-guard -source-filename %s -pos=23:3 -end-pos=27:4 > %t.result/L23-3.swift
// RUN: diff -u %S/Outputs/basic/L23-3.swift.expected %t.result/L23-3.swift