File tree 2 files changed +35
-0
lines changed
2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change 10
10
//
11
11
//===----------------------------------------------------------------------===//
12
12
13
+ extension ClosureCaptureSyntax {
14
+
15
+ /// Creates a `ClosureCaptureSyntax` with a `name`, and automatically adds an `equal` token to it since the name is non-optional.
16
+ ///
17
+ /// - SeeAlso: ``ClosureCaptureSyntax/init(leadingTrivia:_:specifier:_:name:_:equal:_:expression:_:trailingComma:_:trailingTrivia:)``.
18
+ ///
19
+ public init (
20
+ leadingTrivia: Trivia ? = nil ,
21
+ specifier: ClosureCaptureSpecifierSyntax ? = nil ,
22
+ name: TokenSyntax ,
23
+ equal: TokenSyntax = TokenSyntax . equalToken ( ) ,
24
+ expression: some ExprSyntaxProtocol ,
25
+ trailingComma: TokenSyntax ? = nil ,
26
+ trailingTrivia: Trivia ? = nil
27
+ ) {
28
+ self . init (
29
+ leadingTrivia: leadingTrivia,
30
+ specifier: specifier,
31
+ name: name as TokenSyntax ? ,
32
+ equal: equal,
33
+ expression: expression,
34
+ trailingComma: trailingComma,
35
+ trailingTrivia: trailingTrivia
36
+ )
37
+ }
38
+ }
39
+
13
40
extension EnumCaseParameterSyntax {
14
41
15
42
/// Creates an `EnumCaseParameterSyntax` with a `firstName`, and automatically adds a `colon` to it.
Original file line number Diff line number Diff line change @@ -133,4 +133,12 @@ public class SyntaxTests: XCTestCase {
133
133
let node = EnumCaseParameterSyntax ( firstName: " label " , type: TypeSyntax ( " MyType " ) )
134
134
XCTAssertEqual ( node. formatted ( ) . description, " label: MyType " )
135
135
}
136
+
137
+ public func testClosureCaptureSyntaxConvenienceInitWithEqual( ) {
138
+ let noNameClosureCapture = ClosureCaptureSyntax ( expression: ExprSyntax ( " 123 " ) )
139
+ XCTAssertEqual ( noNameClosureCapture. formatted ( ) . description, " 123 " )
140
+
141
+ let node = ClosureCaptureSyntax ( name: " test " , expression: ExprSyntax ( " 123 " ) )
142
+ XCTAssertEqual ( node. formatted ( ) . description, " test = 123 " )
143
+ }
136
144
}
You can’t perform that action at this time.
0 commit comments