Skip to content

Commit bd09469

Browse files
authored
Merge pull request #3362 from nenadvulic/fix-3236-preserve-comment
2 parents 913ff9d + 264f904 commit bd09469

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

Tests/SwiftRefactorTest/ConvertZeroParameterFunctionToComputedPropertyTests.swift

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,55 @@ final class ConvertZeroParameterFunctionToComputedPropertyTests: XCTestCase {
2929
try assertRefactorConvert(baseline, expected: expected)
3030
}
3131

32+
func testRefactoringFunctionToComputedPropertyPreservesLeadingComment() throws {
33+
try assertRefactorConvert(
34+
"""
35+
/// Some comment
36+
func asJSON() -> String { "" }
37+
""",
38+
expected: """
39+
/// Some comment
40+
var asJSON: String { "" }
41+
"""
42+
)
43+
44+
// With a modifier (comment is leading trivia of the modifier).
45+
try assertRefactorConvert(
46+
"""
47+
/// Some comment
48+
public func asJSON() -> String { "" }
49+
""",
50+
expected: """
51+
/// Some comment
52+
public var asJSON: String { "" }
53+
"""
54+
)
55+
56+
// With an attribute (comment is leading trivia of the attribute).
57+
try assertRefactorConvert(
58+
"""
59+
/// Some comment
60+
@inlinable func asJSON() -> String { "" }
61+
""",
62+
expected: """
63+
/// Some comment
64+
@inlinable var asJSON: String { "" }
65+
"""
66+
)
67+
68+
// Block doc comment.
69+
try assertRefactorConvert(
70+
"""
71+
/** Some comment */
72+
func asJSON() -> String { "" }
73+
""",
74+
expected: """
75+
/** Some comment */
76+
var asJSON: String { "" }
77+
"""
78+
)
79+
}
80+
3281
func testRefactoringFunctionToComputedPropertyWithVoidType() throws {
3382
let baseline: DeclSyntax = """
3483
func asJSON() { () }

0 commit comments

Comments
 (0)