Files
swift-mirror/test/refactoring/ExtractFunction/await.swift
Hamish Knight 8d92241ca9 [Refactoring] Support async for function extraction
Adapt the `ThrowingEntityAnalyzer` to pick up any
`await` keywords and add an `async` to the extracted
function if necessary along with an `await` for its
call.

rdar://72199949
2021-05-26 12:40:35 +01:00

19 lines
992 B
Swift

func longLongLongJourney() async -> Int { 0 }
func longLongLongAwryJourney() async throws -> Int { 0 }
func consumesAsync(_ fn: () async throws -> Void) rethrows {}
func testThrowingClosure() async throws -> Int {
let x = await longLongLongJourney()
let y = try await longLongLongAwryJourney() + 1
try consumesAsync { try await longLongLongAwryJourney() }
return x + y
}
// RUN: %empty-directory(%t.result)
// RUN: %refactor -extract-function -source-filename %s -pos=6:11 -end-pos=6:38 >> %t.result/async1.swift
// RUN: diff -u %S/Outputs/await/async1.swift.expected %t.result/async1.swift
// RUN: %refactor -extract-function -source-filename %s -pos=7:11 -end-pos=7:50 >> %t.result/async2.swift
// RUN: diff -u %S/Outputs/await/async2.swift.expected %t.result/async2.swift
// RUN: %refactor -extract-function -source-filename %s -pos=8:1 -end-pos=8:60 >> %t.result/consumes_async.swift
// RUN: diff -u %S/Outputs/await/consumes_async.swift.expected %t.result/consumes_async.swift