Files
SwiftLint/Tests/SwiftLintFrameworkTests/VerticalWhitespaceRuleTests.swift
T
JP Simard b83e0991b9 Remove all file headers
The MIT license doesn't require that all files be prepended with this
licensing or copyright information. Realm confirmed that they're ok with this
change. This will enable some companies to contribute to SwiftLint and the
date & authorship information will remain accessible via git source control.
2018-05-04 13:42:02 -07:00

62 lines
2.5 KiB
Swift

@testable import SwiftLintFramework
import XCTest
class VerticalWhitespaceRuleTests: XCTestCase {
private let ruleID = VerticalWhitespaceRule.description.identifier
func testVerticalWhitespaceWithDefaultConfiguration() {
// Test with default parameters
verifyRule(VerticalWhitespaceRule.description)
}
func testAttributesWithMaxEmptyLines() {
// Test with custom `max_empty_lines`
let maxEmptyLinesDescription = VerticalWhitespaceRule.description
.with(nonTriggeringExamples: ["let aaaa = 0\n\n\n"])
.with(triggeringExamples: ["struct AAAA {}\n\n\n\n"])
.with(corrections: [:])
verifyRule(maxEmptyLinesDescription,
ruleConfiguration: ["max_empty_lines": 2])
}
func testAutoCorrectionWithMaxEmptyLines() {
let maxEmptyLinesDescription = VerticalWhitespaceRule.description
.with(nonTriggeringExamples: [])
.with(triggeringExamples: [])
.with(corrections: [
"let b = 0\n\n\n\n\n\nclass AAA {}\n": "let b = 0\n\n\nclass AAA {}\n",
"let b = 0\n\n\nclass AAA {}\n": "let b = 0\n\n\nclass AAA {}\n"
])
verifyRule(maxEmptyLinesDescription,
ruleConfiguration: ["max_empty_lines": 2])
}
func testViolationMessageWithMaxEmptyLines() {
guard let config = makeConfig(["max_empty_lines": 2], ruleID) else {
XCTFail("Failed to create configuration")
return
}
let allViolations = violations("let aaaa = 0\n\n\n\nlet bbb = 2\n", config: config)
let verticalWhiteSpaceViolation = allViolations.first { $0.ruleDescription.identifier == ruleID }
if let violation = verticalWhiteSpaceViolation {
XCTAssertEqual(violation.reason, "Limit vertical whitespace to maximum 2 empty lines. Currently 3.")
} else {
XCTFail("A vertical whitespace violation should have been triggered!")
}
}
func testViolationMessageWithDefaultConfiguration() {
let allViolations = violations("let aaaa = 0\n\n\n\nlet bbb = 2\n")
let verticalWhiteSpaceViolation = allViolations.first(where: { $0.ruleDescription.identifier == ruleID })
if let violation = verticalWhiteSpaceViolation {
XCTAssertEqual(violation.reason, "Limit vertical whitespace to a single empty line. Currently 3.")
} else {
XCTFail("A vertical whitespace violation should have been triggered!")
}
}
}