mirror of
https://github.com/realm/SwiftLint.git
synced 2026-06-06 20:18:40 +00:00
e320b2e363
Now that the Configuration struct is creating a list of rules based on optional yaml, this list duplicates the same behavior. By removing it you no longer have to maintain duplicate lists of rules.
53 lines
2.1 KiB
Swift
53 lines
2.1 KiB
Swift
//
|
|
// ConfigurationTests.swift
|
|
// SwiftLint
|
|
//
|
|
// Created by JP Simard on 8/23/15.
|
|
// Copyright © 2015 Realm. All rights reserved.
|
|
//
|
|
|
|
import SwiftLintFramework
|
|
import XCTest
|
|
|
|
class ConfigurationTests: XCTestCase {
|
|
func testInit() {
|
|
XCTAssert(Configuration(yaml: "") != nil,
|
|
"initializing Configuration with empty YAML string should succeed")
|
|
XCTAssert(Configuration(yaml: "a: 1\nb: 2") != nil,
|
|
"initializing Configuration with valid YAML string should succeed")
|
|
XCTAssert(Configuration(yaml: "|\na") == nil,
|
|
"initializing Configuration with invalid YAML string should fail")
|
|
}
|
|
|
|
func testEmptyConfiguration() {
|
|
guard let config = Configuration(yaml: "") else {
|
|
XCTFail("empty YAML string should yield non-nil Configuration")
|
|
return
|
|
}
|
|
XCTAssertEqual(config.disabledRules, [])
|
|
XCTAssertEqual(config.included, [])
|
|
XCTAssertEqual(config.excluded, [])
|
|
XCTAssertEqual(config.reporter, "xcode")
|
|
XCTAssertEqual(config.reporterFromString.identifier, "xcode")
|
|
}
|
|
|
|
func testDisabledRules() {
|
|
XCTAssert(Configuration(yaml: "disabled_rules:\n - a") == nil,
|
|
"initializing Configuration with invalid rules in YAML string should fail")
|
|
let disabledConfig = Configuration(yaml: "disabled_rules:\n - nesting\n - todo")!
|
|
XCTAssertEqual(disabledConfig.disabledRules,
|
|
["nesting", "todo"],
|
|
"initializing Configuration with valid rules in YAML string should succeed")
|
|
let expectedIdentifiers = Configuration.rulesFromYAML(nil)
|
|
.map({ $0.identifier })
|
|
.filter({ !["nesting", "todo"].contains($0) })
|
|
let configuredIdentifiers = disabledConfig.rules.map({ $0.identifier })
|
|
XCTAssertEqual(expectedIdentifiers, configuredIdentifiers)
|
|
|
|
// Duplicate
|
|
let duplicateConfig = Configuration( yaml: "disabled_rules:\n - todo\n - todo")
|
|
XCTAssert(duplicateConfig == nil, "initializing Configuration with duplicate rules in " +
|
|
" YAML string should fail")
|
|
}
|
|
}
|