|
3 | 3 | enum E : Error { case e }
|
4 | 4 |
|
5 | 5 | func anyCompletion(_ completion: (Any?, Error?) -> Void) {}
|
| 6 | +func anyResultCompletion(_ completion: (Result<Any?, Error>) -> Void) {} |
6 | 7 |
|
7 | 8 | // RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=TEST-UNHANDLED %s
|
8 | 9 | anyCompletion { val, err in
|
@@ -43,3 +44,77 @@ anyCompletion { val, err in
|
43 | 44 | // TEST-UNHANDLED-NEXT: if case let "" as String = <#x#> {
|
44 | 45 | // TEST-UNHANDLED-NEXT: print("g")
|
45 | 46 | // TEST-UNHANDLED-NEXT: }
|
| 47 | + |
| 48 | +// RUN: not %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 |
| 49 | +anyResultCompletion { res in |
| 50 | + switch res { |
| 51 | + case .success(let unwrapped?): |
| 52 | + print(unwrapped) |
| 53 | + case .success(let x): |
| 54 | + print(x) |
| 55 | + case .failure: |
| 56 | + print("oh no") |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +// RUN: not %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 |
| 61 | +anyResultCompletion { res in |
| 62 | + switch res { |
| 63 | + case .success(let str as String): |
| 64 | + print(str) |
| 65 | + case .success(let x): |
| 66 | + print(x) |
| 67 | + case .failure: |
| 68 | + print("oh no") |
| 69 | + } |
| 70 | +} |
| 71 | + |
| 72 | +// RUN: not %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 |
| 73 | +anyResultCompletion { res in |
| 74 | + switch res { |
| 75 | + case .success(E.e?): |
| 76 | + print("ee") |
| 77 | + case .success(let x): |
| 78 | + print(x) |
| 79 | + case .failure: |
| 80 | + print("oh no") |
| 81 | + } |
| 82 | +} |
| 83 | + |
| 84 | +// RUN: not %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 |
| 85 | +anyResultCompletion { res in |
| 86 | + switch res { |
| 87 | + case .success("" as String): |
| 88 | + print("empty string") |
| 89 | + case .success(let x): |
| 90 | + print(x) |
| 91 | + case .failure: |
| 92 | + print("oh no") |
| 93 | + } |
| 94 | +} |
| 95 | + |
| 96 | +// FIXME: This should ideally be turned into a 'catch let e as E'. |
| 97 | +// RUN: not %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 |
| 98 | +anyResultCompletion { res in |
| 99 | + switch res { |
| 100 | + case .success(let a): |
| 101 | + print(a) |
| 102 | + case .failure(let e as E): |
| 103 | + print("oh no e") |
| 104 | + case .failure: |
| 105 | + print("oh no") |
| 106 | + } |
| 107 | +} |
| 108 | + |
| 109 | +// FIXME: This should ideally be turned into a 'catch E.e'. |
| 110 | +// RUN: not %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 |
| 111 | +anyResultCompletion { res in |
| 112 | + switch res { |
| 113 | + case .success(let a): |
| 114 | + print(a) |
| 115 | + case .failure(E.e): |
| 116 | + print("oh no ee") |
| 117 | + case .failure: |
| 118 | + print("oh no") |
| 119 | + } |
| 120 | +} |
0 commit comments