Files
SwiftLint/Tests/SwiftLintFrameworkTests/MultilineArgumentsRuleTests.swift
Zev Eisenberg fcf848608e Add Inline test failure messages (#3040)
* 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.
2020-02-02 10:35:37 +02:00

104 lines
3.2 KiB
Swift

import SwiftLintFramework
import XCTest
class MultilineArgumentsRuleTests: XCTestCase {
func testMultilineArgumentsWithDefaultConfiguration() {
verifyRule(MultilineArgumentsRule.description)
}
func testMultilineArgumentsWithWithNextLine() {
let nonTriggeringExamples = [
Example("foo()"),
Example("foo(0)"),
Example("foo(1, bar: baz) { }"),
Example("foo(2, bar: baz) {\n}"),
Example("foo(\n" +
" 3,\n" +
" bar: baz) { }"),
Example("foo(\n" +
" 4, bar: baz) { }")
]
let triggeringExamples = [
Example("foo(↓1,\n" +
" bar: baz) { }")
]
let description = MultilineArgumentsRule.description
.with(triggeringExamples: triggeringExamples)
.with(nonTriggeringExamples: nonTriggeringExamples)
verifyRule(description, ruleConfiguration: ["first_argument_location": "next_line"])
}
func testMultilineArgumentsWithWithSameLine() {
let nonTriggeringExamples = [
Example("foo()"),
Example("foo(0)"),
Example("foo(1, bar: 1) { }"),
Example("foo(2, bar: 2) {\n" +
" bar()\n" +
"}"),
Example("foo(3,\n" +
" bar: 3) { }")
]
let triggeringExamples = [
Example("foo(\n" +
" ↓1, ↓bar: baz) { }"),
Example("foo(\n" +
" ↓2,\n" +
" bar: baz) { }")
]
let description = MultilineArgumentsRule.description
.with(triggeringExamples: triggeringExamples)
.with(nonTriggeringExamples: nonTriggeringExamples)
verifyRule(description, ruleConfiguration: ["first_argument_location": "same_line"])
}
func testMultilineArgumentsWithOnlyEnforceAfterFirstClosureOnFirstLine() {
let nonTriggeringExamples: [Example] = [
Example("foo()"),
Example("foo(0)"),
Example("foo(1, bar: 1) { }"),
Example("foo(\n" +
" 4, bar: baz) { }"),
Example("foo(a: a, b: {\n" +
"}, c: {\n" +
"})"),
Example("foo(\n" +
" a: a, b: {\n" +
" }, c: {\n" +
"})"),
Example("foo(a: a, b: b, c: {\n" +
"}, d: {\n" +
"})"),
Example("foo(\n" +
" a: a, b: b, c: {\n" +
" }, d: {\n" +
"})"),
Example("foo(a: a, b: { [weak self] in\n" +
"}, c: { flag in\n" +
"})")
]
let triggeringExamples = [
Example("foo(a: a,\n" +
" b: b, c: {\n" +
"})"),
Example("foo(a: a, b: b,\n" +
" c: c, d: {\n" +
" }, d: {\n" +
"})")
]
let description = MultilineArgumentsRule.description
.with(triggeringExamples: triggeringExamples)
.with(nonTriggeringExamples: nonTriggeringExamples)
verifyRule(description, ruleConfiguration: ["only_enforce_after_first_closure_on_first_line": true])
}
}