Skip to content

Commit 058613d

Browse files
committed
[Refactoring] Add tests for convert to async
Convert to async and add async alternative differ when there is no/an invalid completion handler. In those cases, also check convert to async.
1 parent 6eb133b commit 058613d

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

test/refactoring/ConvertAsync/basic.swift

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -333,26 +333,37 @@ protocol MyProtocol {
333333
// PROTO-MEMBER: func protoMember() async -> String{{$}}
334334
}
335335

336-
// RUN: not %refactor -add-async-alternative -dump-text -source-filename %s -pos=%(line+1):1
336+
// RUN: not %refactor -add-async-alternative -dump-text -source-filename %s -pos=%(line+2):1
337+
// RUN: %refactor -convert-to-async -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=NON-COMPLETION %s
337338
func nonCompletion(a: Int) { }
339+
// NON-COMPLETION: func nonCompletion(a: Int) async { }
338340

339-
// RUN: not %refactor -add-async-alternative -dump-text -source-filename %s -pos=%(line+1):1
341+
// RUN: not %refactor -add-async-alternative -dump-text -source-filename %s -pos=%(line+2):1
342+
// RUN: %refactor -convert-to-async -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=MULTIPLE-RESULTS %s
340343
func multipleResults(completion: (Result<String, Error>, Result<String, Error>) -> Void) { }
344+
// MULTIPLE-RESULTS: func multipleResults(completion: (Result<String, Error>, Result<String, Error>) -> Void) async { }
341345

342-
// RUN: not %refactor -add-async-alternative -dump-text -source-filename %s -pos=%(line+1):1
346+
// RUN: not %refactor -add-async-alternative -dump-text -source-filename %s -pos=%(line+2):1
347+
// RUN: %refactor -convert-to-async -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=NOT-LAST %s
343348
func completionNotLast(completion: (String) -> Void, a: Int) { }
349+
// NOT-LAST: func completionNotLast(completion: (String) -> Void, a: Int) async { }
344350

345-
// RUN: not %refactor -add-async-alternative -dump-text -source-filename %s -pos=%(line+1):1
351+
// RUN: not %refactor -add-async-alternative -dump-text -source-filename %s -pos=%(line+2):1
346352
func nonVoid(completion: (String) -> Void) -> Int { return 0 }
347353

348-
// RUN: not %refactor -add-async-alternative -dump-text -source-filename %s -pos=%(line+1):1
354+
// RUN: not %refactor -add-async-alternative -dump-text -source-filename %s -pos=%(line+2):1
355+
// RUN: %refactor -convert-to-async -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=COMPLETION-NON-VOID %s
349356
func completionNonVoid(completion: (String) -> Int) -> Void { }
357+
// COMPLETION-NON-VOID: func completionNonVoid(completion: (String) -> Int) async -> Void { }
350358

351-
// RUN: not %refactor -add-async-alternative -dump-text -source-filename %s -pos=%(line+1):1
359+
// RUN: not %refactor -add-async-alternative -dump-text -source-filename %s -pos=%(line+2):1
360+
// RUN: %refactor -convert-to-async -dump-text -source-filename %s -pos=%(line+1):1
352361
func alreadyThrows(completion: (String) -> Void) throws { }
353362

354-
// RUN: not %refactor -add-async-alternative -dump-text -source-filename %s -pos=%(line+1):1
363+
// RUN: not %refactor -add-async-alternative -dump-text -source-filename %s -pos=%(line+2):1
364+
// RUN: %refactor -convert-to-async -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=AUTO-CLOSURE %s
355365
func noParamAutoclosure(completion: @autoclosure () -> Void) { }
366+
// AUTO-CLOSURE: func noParamAutoclosure(completion: @autoclosure () -> Void) async { }
356367

357368
// RUN: %refactor-check-compiles -add-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix BLOCK-CONVENTION %s
358369
func blockConvention(completion: @convention(block) () -> Void) { }

0 commit comments

Comments
 (0)