Skip to content

Commit 59aceb2

Browse files
kimdvCippoX
authored andcommitted
Add test cases for #1551
1 parent 94d840c commit 59aceb2

File tree

4 files changed

+103
-0
lines changed

4 files changed

+103
-0
lines changed

Tests/SwiftSyntaxBuilderTest/ClosureExprTests.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,27 @@ final class ClosureExprTests: XCTestCase {
3434
"""
3535
)
3636
}
37+
func testClosureExprWithAsync() {
38+
let buildable = ClosureExprSyntax(
39+
signature: ClosureSignatureSyntax(
40+
input: .simpleInput(
41+
ClosureParamListSyntax {
42+
ClosureParamSyntax(name: .identifier("area"))
43+
}
44+
),
45+
effectSpecifiers: TypeEffectSpecifiersSyntax(
46+
asyncSpecifier: .keyword(.async),
47+
throwsSpecifier: .keyword(.throws)
48+
)
49+
)
50+
) {}
51+
52+
assertBuildResult(
53+
buildable,
54+
"""
55+
{area async throws in
56+
}
57+
"""
58+
)
59+
}
3760
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
import XCTest
14+
import SwiftSyntax
15+
import SwiftSyntaxBuilder
16+
17+
final class FunctionSignatureSyntaxTests: XCTestCase {
18+
func testFunctionEffectSpecifiersSyntax() throws {
19+
let functionEffects = FunctionEffectSpecifiersSyntax(asyncSpecifier: .keyword(.async), throwsSpecifier: .keyword(.rethrows))
20+
let buildable = FunctionSignatureSyntax(input: .init(parameterList: []), effectSpecifiers: functionEffects, output: .init(returnType: TypeSyntax("String")))
21+
22+
assertBuildResult(
23+
buildable,
24+
"""
25+
() async rethrows -> String
26+
"""
27+
)
28+
}
29+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
import XCTest
14+
import SwiftSyntax
15+
import SwiftSyntaxBuilder
16+
17+
final class FunctionTypeSyntaxTests: XCTestCase {
18+
func testFunctionEffectSpecifiersSyntax() throws {
19+
let typeEffects = TypeEffectSpecifiersSyntax(asyncSpecifier: .keyword(.async), throwsSpecifier: .keyword(.throws))
20+
let buildable = FunctionTypeSyntax(arguments: [], effectSpecifiers: typeEffects, output: .init(returnType: TypeSyntax("String")))
21+
22+
assertBuildResult(
23+
buildable,
24+
"""
25+
() async throws -> String
26+
"""
27+
)
28+
}
29+
}

Tests/SwiftSyntaxBuilderTest/VariableTests.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,28 @@ final class VariableTests: XCTestCase {
293293
)
294294
}
295295

296+
func testAccessorWithEffectSpecifier() throws {
297+
let buildable = try VariableDeclSyntax("var test: Int") {
298+
AccessorDeclSyntax(
299+
accessorKind: .keyword(.get),
300+
effectSpecifiers: AccessorEffectSpecifiersSyntax(
301+
asyncSpecifier: .keyword(.async),
302+
throwsSpecifier: .keyword(.throws)
303+
)
304+
) {}
305+
}
306+
307+
assertBuildResult(
308+
buildable,
309+
"""
310+
var test: Int {
311+
get async throws {
312+
}
313+
}
314+
"""
315+
)
316+
}
317+
296318
func testAttributedVariables() throws {
297319
let testCases: [UInt: (VariableDeclSyntax, String)] = try [
298320
#line: (

0 commit comments

Comments
 (0)