Skip to content

Commit bbc9ec6

Browse files
authored
Transform assertCustomInline() to assertCustomInline { ... } (pointfreeco#788)
Right now we preserve the `()`, which leads to atypical Swift code, like: ```swift assertCustomInline() { """ ... """ } ```
1 parent b4c58d7 commit bbc9ec6

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

Sources/InlineSnapshotTesting/AssertInlineSnapshot.swift

+12
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,18 @@ private final class SnapshotRewriter: SyntaxRewriter {
504504
fatalError()
505505
}
506506
}
507+
508+
if
509+
functionCallExpr.arguments.isEmpty,
510+
functionCallExpr.trailingClosure != nil,
511+
functionCallExpr.leftParen != nil,
512+
functionCallExpr.rightParen != nil
513+
{
514+
functionCallExpr.leftParen = nil
515+
functionCallExpr.rightParen = nil
516+
functionCallExpr.calledExpression.trailingTrivia = .space
517+
}
518+
507519
return ExprSyntax(functionCallExpr)
508520
}
509521
}

Tests/InlineSnapshotTestingTests/InlineSnapshotTestingTests.swift

+31
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,37 @@ final class InlineSnapshotTestingTests: XCTestCase {
103103
)
104104
}
105105

106+
func testArgumentlessInlineSnapshot() {
107+
func assertArgumentlessInlineSnapshot(
108+
expected: (() -> String)? = nil,
109+
file: StaticString = #filePath,
110+
function: StaticString = #function,
111+
line: UInt = #line,
112+
column: UInt = #column
113+
) {
114+
assertInlineSnapshot(
115+
of: "Hello",
116+
as: .dump,
117+
syntaxDescriptor: InlineSnapshotSyntaxDescriptor(
118+
trailingClosureLabel: "is",
119+
trailingClosureOffset: 1
120+
),
121+
matches: expected,
122+
file: file,
123+
function: function,
124+
line: line,
125+
column: column
126+
)
127+
}
128+
129+
assertArgumentlessInlineSnapshot {
130+
"""
131+
- "Hello"
132+
133+
"""
134+
}
135+
}
136+
106137
func testMultipleInlineSnapshots() {
107138
func assertResponse(
108139
of url: () -> String,

0 commit comments

Comments
 (0)