File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change 1010//
1111//===----------------------------------------------------------------------===//
1212
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+
1340extension EnumCaseParameterSyntax {
1441
1542 /// 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 {
133133 let node = EnumCaseParameterSyntax ( firstName: " label " , type: TypeSyntax ( " MyType " ) )
134134 XCTAssertEqual ( node. formatted ( ) . description, " label: MyType " )
135135 }
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+ }
136144}
You can’t perform that action at this time.
0 commit comments