Skip to content

Commit

Permalink
realm#2353 - Add modifier_oder rule correction tests
Browse files Browse the repository at this point in the history
  • Loading branch information
abdulowork authored and jpsim committed Dec 24, 2018
1 parent 830d0ee commit c8b465f
Show file tree
Hide file tree
Showing 2 changed files with 185 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Tests/LinuxMain.swift
Expand Up @@ -718,6 +718,9 @@ extension ModifierOrderTests {
("testRightOrderedModifierGroups", testRightOrderedModifierGroups),
("testAtPrefixedGroup", testAtPrefixedGroup),
("testNonSpecifiedModifiersDontInterfere", testNonSpecifiedModifiersDontInterfere),
("testCorrectionsAreAppliedCorrectly", testCorrectionsAreAppliedCorrectly),
("testCorrectionsAreNotAppliedToIrrelevantModifier", testCorrectionsAreNotAppliedToIrrelevantModifier),
("testTypeMethodClassCorrection", testTypeMethodClassCorrection),
("testViolationMessage", testViolationMessage)
]
}
Expand Down
182 changes: 182 additions & 0 deletions Tests/SwiftLintFrameworkTests/ModifierOrderTests.swift
@@ -1,6 +1,9 @@
@testable import SwiftLintFramework
import XCTest

// swiftlint:disable file_length
// swiftlint:disable type_body_length

class ModifierOrderTests: XCTestCase {
func testAttributeTypeMethod() {
let descriptionOverride = RuleDescription(
Expand Down Expand Up @@ -201,6 +204,185 @@ class ModifierOrderTests: XCTestCase {
ruleConfiguration: ["preferred_modifier_order": ["final", "override", "acl"]])
}

func testCorrectionsAreAppliedCorrectly() {
let descriptionOverride = RuleDescription(
identifier: "modifier_order",
name: "Modifier Order",
description: "Modifier order should be consistent.",
kind: .style,
minSwiftVersion: .fourDotOne,
nonTriggeringExamples: [],
triggeringExamples: [],
corrections: [
"""
class Foo {
private final override var bar: UIView?
}
""":
"""
class Foo {
final override private var bar: UIView?
}
""",
"""
class Foo {
private final var bar: UIView?
}
""":
"""
class Foo {
final private var bar: UIView?
}
""",
"""
class Foo {
class private final var bar: UIView?
}
""":
"""
class Foo {
final private class var bar: UIView?
}
""",
"""
class Foo {
@objc
private
class
final
override
var bar: UIView?
}
""":
"""
class Foo {
@objc
final
override
private
class
var bar: UIView?
}
""",
"""
private final class Foo {}
""":
"""
final private class Foo {}
"""
]
)

verifyRule(descriptionOverride,
ruleConfiguration: ["preferred_modifier_order": ["final", "override", "acl", "typeMethods"]])
}

func testCorrectionsAreNotAppliedToIrrelevantModifier() {
let descriptionOverride = RuleDescription(
identifier: "modifier_order",
name: "Modifier Order",
description: "Modifier order should be consistent.",
kind: .style,
minSwiftVersion: .fourDotOne,
nonTriggeringExamples: [],
triggeringExamples: [],
corrections: [
"""
class Foo {
weak class final var bar: UIView?
}
""":
"""
class Foo {
weak final class var bar: UIView?
}
""",
"""
class Foo {
static weak final var bar: UIView?
}
""":
"""
class Foo {
final weak static var bar: UIView?
}
""",
"""
class Foo {
class final weak var bar: UIView?
}
""":
"""
class Foo {
final class weak var bar: UIView?
}
""",
"""
class Foo {
@objc
private
private(set)
class
final
var bar: UIView?
}
""":
"""
class Foo {
@objc
final
private(set)
private
class
var bar: UIView?
}
""",
"""
class Foo {
var bar: UIView?
}
""":
"""
class Foo {
var bar: UIView?
}
"""
]
)

verifyRule(descriptionOverride,
ruleConfiguration: ["preferred_modifier_order": ["final", "override", "acl", "typeMethods"]])
}

func testTypeMethodClassCorrection() {
let descriptionOverride = RuleDescription(
identifier: "modifier_order",
name: "Modifier Order",
description: "Modifier order should be consistent.",
kind: .style,
minSwiftVersion: .fourDotOne,
nonTriggeringExamples: [],
triggeringExamples: [],
corrections: [
"""
private final class Foo {}
""":
"""
final private class Foo {}
""",
"""
public protocol Foo: class {}
""":
"""
public protocol Foo: class {}
"""
]
)

verifyRule(descriptionOverride,
ruleConfiguration: ["preferred_modifier_order": ["final", "typeMethods", "acl"]])
}

func testViolationMessage() {
guard SwiftVersion.current >= ModifierOrderRule.description.minSwiftVersion else {
return
Expand Down

0 comments on commit c8b465f

Please sign in to comment.