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.
49 lines
1.5 KiB
Swift
49 lines
1.5 KiB
Swift
import SwiftLintFramework
|
|
import XCTest
|
|
|
|
class DiscouragedDirectInitRuleTests: XCTestCase {
|
|
let baseDescription = DiscouragedDirectInitRule.description
|
|
|
|
func testDiscouragedDirectInitWithDefaultConfiguration() {
|
|
verifyRule(baseDescription)
|
|
}
|
|
|
|
func testDiscouragedDirectInitWithConfiguredSeverity() {
|
|
verifyRule(baseDescription, ruleConfiguration: ["severity": "error"])
|
|
}
|
|
|
|
func testDiscouragedDirectInitWithNewIncludedTypes() {
|
|
let triggeringExamples = [
|
|
Example("let foo = ↓Foo()"),
|
|
Example("let bar = ↓Bar()")
|
|
]
|
|
|
|
let nonTriggeringExamples = [
|
|
Example("let foo = Foo(arg: toto)"),
|
|
Example("let bar = Bar(arg: \"toto\")")
|
|
]
|
|
|
|
let description = baseDescription
|
|
.with(triggeringExamples: triggeringExamples)
|
|
.with(nonTriggeringExamples: nonTriggeringExamples)
|
|
|
|
verifyRule(description, ruleConfiguration: ["types": ["Foo", "Bar"]])
|
|
}
|
|
|
|
func testDiscouragedDirectInitWithReplacedTypes() {
|
|
let triggeringExamples = [
|
|
Example("let bundle = ↓Bundle()")
|
|
]
|
|
|
|
let nonTriggeringExamples = [
|
|
Example("let device = UIDevice()")
|
|
]
|
|
|
|
let description = baseDescription
|
|
.with(triggeringExamples: triggeringExamples)
|
|
.with(nonTriggeringExamples: nonTriggeringExamples)
|
|
|
|
verifyRule(description, ruleConfiguration: ["types": ["Bundle"]])
|
|
}
|
|
}
|