|
| 1 | +import Foundation |
| 2 | +import SwiftSyntax |
| 3 | +import XCTest |
| 4 | + |
| 5 | +@testable import Rules |
| 6 | + |
| 7 | +public class BeginDocumentationCommentWithOneLineSummaryTests: DiagnosingTestCase { |
| 8 | + public func testDocLineCommentsWithoutOneSentenceSummary() { |
| 9 | + let input = |
| 10 | + """ |
| 11 | + /// Returns a bottle of Dr. Pepper from the vending machine. |
| 12 | + public func drPepper(from vendingMachine: VendingMachine) -> Soda {} |
| 13 | +
|
| 14 | + /// Contains a comment as description that needs a sentece |
| 15 | + /// of two lines of code. |
| 16 | + public var twoLinesForOneSentence = "test" |
| 17 | +
|
| 18 | + /// The background color of the view. |
| 19 | + var backgroundColor: UIColor |
| 20 | +
|
| 21 | + /// Returns the sum of the numbers. |
| 22 | + /// |
| 23 | + /// - Parameter numbers: The numbers to sum. |
| 24 | + /// - Returns: The sum of the numbers. |
| 25 | + func sum(_ numbers: [Int]) -> Int { |
| 26 | + // ... |
| 27 | + } |
| 28 | +
|
| 29 | + /// This docline should not succeed. |
| 30 | + /// There are two sentences without a blank line between them. |
| 31 | + struct Test {} |
| 32 | +
|
| 33 | + /// This docline should not succeed. There are two sentences. |
| 34 | + public enum Token { case comma, semicolon, identifier } |
| 35 | + """ |
| 36 | + performLint(BeginDocumentationCommentWithOneLineSummary.self, input: input) |
| 37 | + XCTAssertDiagnosed(.docCommentRequiresOneSentenceSummary("This docline should not succeed.")) |
| 38 | + XCTAssertDiagnosed(.docCommentRequiresOneSentenceSummary("This docline should not succeed.")) |
| 39 | + |
| 40 | + XCTAssertNotDiagnosed(.docCommentRequiresOneSentenceSummary( |
| 41 | + "Returns a bottle of Dr. Pepper from the vending machine.")) |
| 42 | + XCTAssertNotDiagnosed(.docCommentRequiresOneSentenceSummary( |
| 43 | + "Contains a comment as description that needs a sentece of two lines of code.")) |
| 44 | + XCTAssertNotDiagnosed(.docCommentRequiresOneSentenceSummary("The background color of the view.")) |
| 45 | + XCTAssertNotDiagnosed(.docCommentRequiresOneSentenceSummary("Returns the sum of the numbers.")) |
| 46 | + } |
| 47 | + |
| 48 | + public func testBlockLineCommentsWithoutOneSentenceSummary() { |
| 49 | + let input = |
| 50 | + """ |
| 51 | + /** |
| 52 | + * Returns the numeric value. |
| 53 | + * |
| 54 | + * - Parameters: |
| 55 | + * - digit: The Unicode scalar whose numeric value should be returned. |
| 56 | + * - radix: The radix, between 2 and 36, used to compute the numeric value. |
| 57 | + * - Returns: The numeric value of the scalar.*/ |
| 58 | + func numericValue(of digit: UnicodeScalar, radix: Int = 10) -> Int {} |
| 59 | +
|
| 60 | + /** |
| 61 | + * This block comment contains a sentence summary |
| 62 | + * of two lines of code. |
| 63 | + */ |
| 64 | + public var twoLinesForOneSentence = "test" |
| 65 | + |
| 66 | + /** |
| 67 | + * This block comment should not succeed, struct. |
| 68 | + * There are two sentences without a blank line between them. |
| 69 | + */ |
| 70 | + struct TestStruct {} |
| 71 | +
|
| 72 | + /** |
| 73 | + This block comment should not succeed, class. |
| 74 | + Add a blank comment after the first line. |
| 75 | + */ |
| 76 | + public class TestClass {} |
| 77 | + /** This block comment should not succeed, enum. There are two sentences. */ |
| 78 | + public enum testEnum {} |
| 79 | + """ |
| 80 | + performLint(BeginDocumentationCommentWithOneLineSummary.self, input: input) |
| 81 | + XCTAssertDiagnosed(.docCommentRequiresOneSentenceSummary("This block comment should not succeed, struct.")) |
| 82 | + XCTAssertDiagnosed(.docCommentRequiresOneSentenceSummary("This block comment should not succeed, class.")) |
| 83 | + XCTAssertDiagnosed(.docCommentRequiresOneSentenceSummary("This block comment should not succeed, enum.")) |
| 84 | + |
| 85 | + XCTAssertNotDiagnosed(.docCommentRequiresOneSentenceSummary("Returns the numeric value.")) |
| 86 | + XCTAssertNotDiagnosed(.docCommentRequiresOneSentenceSummary( |
| 87 | + "This block comment contains a sentence summary of two lines of code.")) |
| 88 | + } |
| 89 | + |
| 90 | + #if !os(macOS) |
| 91 | + static let allTests = [ |
| 92 | + BeginDocumentationCommentWithOneLineSummaryTests.testDocLineCommentsWithoutOneSentenceSummary, |
| 93 | + BeginDocumentationCommentWithOneLineSummaryTests.testBlockLineCommentsWithoutOneSentenceSummary |
| 94 | + ] |
| 95 | + #endif |
| 96 | +} |
0 commit comments