mirror of
https://github.com/realm/SwiftLint.git
synced 2026-05-07 20:12:49 +00:00
15b285527a
* Short names for test modules * Lint plugins and `Package.swift` in integration tests * Simplify and merge file groups in Bazel * Move common functions to `TestHelpers`
42 lines
1.4 KiB
Swift
42 lines
1.4 KiB
Swift
import SourceKittenFramework
|
|
@testable import SwiftLintBuiltInRules
|
|
import TestHelpers
|
|
import XCTest
|
|
|
|
private let fixturesDirectory = "\(TestResources.path())/FileNameNoSpaceRuleFixtures"
|
|
|
|
final class FileNameNoSpaceRuleTests: SwiftLintTestCase {
|
|
private func validate(fileName: String, excludedOverride: [String]? = nil) throws -> [StyleViolation] {
|
|
let file = SwiftLintFile(path: fixturesDirectory.stringByAppendingPathComponent(fileName))!
|
|
let rule: FileNameNoSpaceRule
|
|
if let excluded = excludedOverride {
|
|
rule = try FileNameNoSpaceRule(configuration: ["excluded": excluded])
|
|
} else {
|
|
rule = FileNameNoSpaceRule()
|
|
}
|
|
|
|
return rule.validate(file: file)
|
|
}
|
|
|
|
func testFileNameDoesntTrigger() {
|
|
XCTAssert(try validate(fileName: "File.swift").isEmpty)
|
|
}
|
|
|
|
func testFileWithSpaceDoesTrigger() {
|
|
XCTAssertEqual(try validate(fileName: "File Name.swift").count, 1)
|
|
}
|
|
|
|
func testExtensionNameDoesntTrigger() {
|
|
XCTAssert(try validate(fileName: "File+Extension.swift").isEmpty)
|
|
}
|
|
|
|
func testExtensionWithSpaceDoesTrigger() {
|
|
XCTAssertEqual(try validate(fileName: "File+Test Extension.swift").count, 1)
|
|
}
|
|
|
|
func testCustomExcludedList() {
|
|
XCTAssert(try validate(fileName: "File+Test Extension.swift",
|
|
excludedOverride: ["File+Test Extension.swift"]).isEmpty)
|
|
}
|
|
}
|