mirror of
https://github.com/realm/SwiftLint.git
synced 2026-06-06 20:18:40 +00:00
fcf848608e
* Add Example wrapper in order to display test failures inline when running in Xcode. * Stop using Swift 5.1-only features so we can compile on Xcode 10.2. * Wrap strings in Example. * Add Changelog entry. * Wrap all examples in Example struct. * Better and more complete capturing of line numbers. * Fix broken test. * Better test traceability. * Address or disable linting warnings. * Add documentation comments. * Disable linter for a few cases. * Limit mutability and add copy-and-mutate utility functions. * Limit scope of mutability.
51 lines
1.8 KiB
Swift
51 lines
1.8 KiB
Swift
import SwiftLintFramework
|
|
import XCTest
|
|
|
|
private func funcWithParameters(_ parameters: String,
|
|
violates: Bool = false,
|
|
file: StaticString = #file,
|
|
line: UInt = #line) -> Example {
|
|
let marker = violates ? "↓" : ""
|
|
|
|
return Example("func \(marker)abc(\(parameters)) {}\n", file: file, line: line)
|
|
}
|
|
|
|
class FunctionParameterCountRuleTests: XCTestCase {
|
|
func testWithDefaultConfiguration() {
|
|
verifyRule(FunctionParameterCountRule.description)
|
|
}
|
|
|
|
func testFunctionParameterCount() {
|
|
let baseDescription = FunctionParameterCountRule.description
|
|
let nonTriggeringExamples = [
|
|
funcWithParameters(repeatElement("x: Int, ", count: 3).joined() + "x: Int")
|
|
]
|
|
|
|
let triggeringExamples = [
|
|
funcWithParameters(repeatElement("x: Int, ", count: 5).joined() + "x: Int")
|
|
]
|
|
|
|
let description = baseDescription.with(nonTriggeringExamples: nonTriggeringExamples)
|
|
.with(triggeringExamples: triggeringExamples)
|
|
|
|
verifyRule(description)
|
|
}
|
|
|
|
func testDefaultFunctionParameterCount() {
|
|
let baseDescription = FunctionParameterCountRule.description
|
|
let nonTriggeringExamples = [
|
|
funcWithParameters(repeatElement("x: Int, ", count: 3).joined() + "x: Int")
|
|
]
|
|
|
|
let defaultParams = repeatElement("x: Int = 0, ", count: 2).joined() + "x: Int = 0"
|
|
let triggeringExamples = [
|
|
funcWithParameters(repeatElement("x: Int, ", count: 3).joined() + defaultParams)
|
|
]
|
|
|
|
let description = baseDescription.with(nonTriggeringExamples: nonTriggeringExamples)
|
|
.with(triggeringExamples: triggeringExamples)
|
|
|
|
verifyRule(description, ruleConfiguration: ["ignores_default_parameters": false])
|
|
}
|
|
}
|