mirror of
https://github.com/realm/SwiftLint.git
synced 2026-06-06 20:18:40 +00:00
* 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.
36 lines
1.4 KiB
Swift
36 lines
1.4 KiB
Swift
@testable import SwiftLintFramework
|
|
import XCTest
|
|
|
|
class ConditionalReturnsOnNewlineRuleTests: XCTestCase {
|
|
func testConditionalReturnsOnNewlineWithDefaultConfiguration() {
|
|
// Test with default parameters
|
|
verifyRule(ConditionalReturnsOnNewlineRule.description)
|
|
}
|
|
|
|
func testConditionalReturnsOnNewlineWithIfOnly() {
|
|
// Test with `if_only` set to true
|
|
let nonTriggeringExamples = [
|
|
Example("guard true else {\n return true\n}"),
|
|
Example("guard true,\n let x = true else {\n return true\n}"),
|
|
Example("if true else {\n return true\n}"),
|
|
Example("if true,\n let x = true else {\n return true\n}"),
|
|
Example("if textField.returnKeyType == .Next {"),
|
|
Example("if true { // return }"),
|
|
Example("/*if true { */ return }"),
|
|
Example("guard true else { return }")
|
|
]
|
|
let triggeringExamples = [
|
|
Example("↓if true { return }"),
|
|
Example("↓if true { break } else { return }"),
|
|
Example("↓if true { break } else { return }"),
|
|
Example("↓if true { return \"YES\" } else { return \"NO\" }")
|
|
]
|
|
|
|
let description = ConditionalReturnsOnNewlineRule.description
|
|
.with(triggeringExamples: triggeringExamples)
|
|
.with(nonTriggeringExamples: nonTriggeringExamples)
|
|
|
|
verifyRule(description, ruleConfiguration: ["if_only": true])
|
|
}
|
|
}
|