Files
SwiftLint/Tests/SwiftLintFrameworkTests/FileLengthRuleTests.swift
T
Steven Grosmark 300bf77967 Improve file_length warnings when excluding comments (#3654)
* Improve `file_length` warnings when excluding comments

* Update changelog

* Update Source/SwiftLintFramework/Rules/Metrics/FileLengthRule.swift

Co-authored-by: Yegor Chsherbatykh <ego1309@yandex.ru>

Co-authored-by: Steven Grosmark <steven.grosmark@ww.com>
Co-authored-by: Yegor Chsherbatykh <ego1309@yandex.ru>
2021-06-17 11:11:17 -07:00

28 lines
1.1 KiB
Swift

import SwiftLintFramework
import XCTest
class FileLengthRuleTests: XCTestCase {
func testFileLengthWithDefaultConfiguration() {
verifyRule(FileLengthRule.description, commentDoesntViolate: false,
testMultiByteOffsets: false, testShebang: false)
}
func testFileLengthIgnoringLinesWithOnlyComments() {
let triggeringExamples = [
Example(repeatElement("print(\"swiftlint\")\n", count: 401).joined())
]
let nonTriggeringExamples = [
Example((repeatElement("print(\"swiftlint\")\n", count: 400) + ["//\n"]).joined()),
Example(repeatElement("print(\"swiftlint\")\n", count: 400).joined()),
Example(repeatElement("print(\"swiftlint\")\n\n", count: 201).joined())
]
let description = FileLengthRule.description
.with(nonTriggeringExamples: nonTriggeringExamples)
.with(triggeringExamples: triggeringExamples)
verifyRule(description, ruleConfiguration: ["ignore_comment_only_lines": true],
testMultiByteOffsets: false, testShebang: false)
}
}