mirror of
https://github.com/realm/SwiftLint.git
synced 2026-06-06 20:18:40 +00:00
fcf848608e
* 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.
50 lines
1.5 KiB
Swift
50 lines
1.5 KiB
Swift
import SwiftLintFramework
|
|
import XCTest
|
|
|
|
class ExampleTests: XCTestCase {
|
|
func testEquatableDoesNotLookAtFile() {
|
|
let first = Example("foo", file: "a", line: 1)
|
|
let second = Example("foo", file: "b", line: 1)
|
|
XCTAssertEqual(first, second)
|
|
}
|
|
|
|
func testEquatableDoesNotLookAtLine() {
|
|
let first = Example("foo", file: "a", line: 1)
|
|
let second = Example("foo", file: "a", line: 2)
|
|
XCTAssertEqual(first, second)
|
|
}
|
|
|
|
func testEquatableLooksAtCode() {
|
|
let first = Example("a", file: "a", line: 1)
|
|
let second = Example("a", file: "x", line: 2)
|
|
let third = Example("c", file: "y", line: 2)
|
|
XCTAssertEqual(first, second)
|
|
XCTAssertNotEqual(first, third)
|
|
}
|
|
|
|
func testRemovingViolationMarkers() {
|
|
let example = Example("↓T↓E↓S↓T")
|
|
XCTAssertEqual(example.removingViolationMarkers(), Example("TEST"))
|
|
}
|
|
|
|
func testComparable() {
|
|
XCTAssertLessThan(Example("a"), Example("b"))
|
|
}
|
|
|
|
func testWithCode() {
|
|
let original = Example("original code")
|
|
XCTAssertNotNil(original.file)
|
|
XCTAssertNotNil(original.line)
|
|
|
|
let new = original.with(code: "new code")
|
|
XCTAssertEqual(new.code, "new code")
|
|
XCTAssertNotNil(new.file)
|
|
XCTAssertNotNil(new.line)
|
|
|
|
// When modifying the code, it's important that the file and line
|
|
// numbers remain intact
|
|
XCTAssertEqual(new.file.description, original.file.description)
|
|
XCTAssertEqual(new.line, original.line)
|
|
}
|
|
}
|