1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
|
import _SwiftFormatTestSupport
@_spi(Rules) import SwiftFormat
final class UseTripleSlashForDocumentationCommentsTests: LintOrFormatRuleTestCase {
func testRemoveDocBlockComments() {
assertFormatting(
UseTripleSlashForDocumentationComments.self,
input: """
/**
* This comment should not be converted.
*/
1️⃣/**
* Returns a docLineComment.
*
* - Parameters:
* - withOutStar: Indicates if the comment start with a star.
* - Returns: docLineComment.
*/
func foo(withOutStar: Bool) {}
""",
expected: """
/**
* This comment should not be converted.
*/
/// Returns a docLineComment.
///
/// - Parameters:
/// - withOutStar: Indicates if the comment start with a star.
/// - Returns: docLineComment.
func foo(withOutStar: Bool) {}
""",
findings: [
FindingSpec("1️⃣", message: "replace documentation block comments with documentation line comments")
]
)
}
func testRemoveDocBlockCommentsWithoutStars() {
assertFormatting(
UseTripleSlashForDocumentationComments.self,
input: """
1️⃣/**
Returns a docLineComment.
- Parameters:
- withStar: Indicates if the comment start with a star.
- Returns: docLineComment.
*/
public var test = 1
""",
expected: """
/// Returns a docLineComment.
///
/// - Parameters:
/// - withStar: Indicates if the comment start with a star.
/// - Returns: docLineComment.
public var test = 1
""",
findings: [
FindingSpec("1️⃣", message: "replace documentation block comments with documentation line comments")
]
)
}
func testMultipleTypesOfDocComments() {
assertFormatting(
UseTripleSlashForDocumentationComments.self,
input: """
/**
* This is my preamble. It could be important.
* This comment stays as-is.
*/
/// This decl has a comment.
/// The comment is multiple lines long.
public class AClazz {
}
""",
expected: """
/**
* This is my preamble. It could be important.
* This comment stays as-is.
*/
/// This decl has a comment.
/// The comment is multiple lines long.
public class AClazz {
}
""",
findings: []
)
}
func testMultipleDocLineComments() {
assertFormatting(
UseTripleSlashForDocumentationComments.self,
input: """
/// This is my preamble. It could be important.
/// This comment stays as-is.
///
/// This decl has a comment.
/// The comment is multiple lines long.
public class AClazz {
}
""",
expected: """
/// This is my preamble. It could be important.
/// This comment stays as-is.
///
/// This decl has a comment.
/// The comment is multiple lines long.
public class AClazz {
}
""",
findings: []
)
}
func testManyDocComments() {
// Note that this retains the trailing space at the end of a single-line doc block comment
// (i.e., the space in `name. */`). It's fine to leave it here; the pretty printer will remove
// it later.
assertFormatting(
UseTripleSlashForDocumentationComments.self,
input: """
/**
* This is my preamble. It could be important.
* This comment stays as-is.
*/
/// This is a doc-line comment!
/** This is a fairly short doc-block comment. */
/// Why are there so many comments?
/// Who knows! But there are loads.
1️⃣/** AClazz is a class with good name. */
public class AClazz {
}
""",
expected: """
/**
* This is my preamble. It could be important.
* This comment stays as-is.
*/
/// This is a doc-line comment!
/** This is a fairly short doc-block comment. */
/// Why are there so many comments?
/// Who knows! But there are loads.
/// AClazz is a class with good name.\u{0020}
public class AClazz {
}
""",
findings: [
FindingSpec("1️⃣", message: "replace documentation block comments with documentation line comments")
]
)
}
func testDocLineCommentsAreNotNormalized() {
assertFormatting(
UseTripleSlashForDocumentationComments.self,
input: """
///
/// Normally that initial blank line and these leading spaces
/// would be removed by DocumentationCommentText. But we don't
/// touch the comment if it's already a doc line comment.
///
public class AClazz {
}
""",
expected: """
///
/// Normally that initial blank line and these leading spaces
/// would be removed by DocumentationCommentText. But we don't
/// touch the comment if it's already a doc line comment.
///
public class AClazz {
}
""",
findings: []
)
}
}
|