mirror of
https://github.com/realm/SwiftLint.git
synced 2026-06-06 20:18:40 +00:00
b83e0991b9
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.
145 lines
7.0 KiB
Swift
145 lines
7.0 KiB
Swift
import SwiftLintFramework
|
|
import XCTest
|
|
|
|
class ColonRuleTests: XCTestCase {
|
|
|
|
func testColonWithDefaultConfiguration() {
|
|
// Verify Colon rule with test values for when flexible_right_spacing
|
|
// is false (default).
|
|
verifyRule(ColonRule.description)
|
|
}
|
|
|
|
// swiftlint:disable:next function_body_length
|
|
func testColonWithFlexibleRightSpace() {
|
|
// Verify Colon rule with test values for when flexible_right_spacing
|
|
// is true.
|
|
let nonTriggeringExamples = ColonRule.description.nonTriggeringExamples + [
|
|
"let abc: Void\n",
|
|
"let abc: (Void, String, Int)\n",
|
|
"let abc: ([Void], String, Int)\n",
|
|
"let abc: [([Void], String, Int)]\n",
|
|
"func abc(def: Void) {}\n",
|
|
"let abc = [Void: Void]()\n"
|
|
]
|
|
let triggeringExamples = [
|
|
"let ↓abc:Void\n",
|
|
"let ↓abc :Void\n",
|
|
"let ↓abc : Void\n",
|
|
"let ↓abc : [Void: Void]\n",
|
|
"let ↓abc : (Void, String, Int)\n",
|
|
"let ↓abc : ([Void], String, Int)\n",
|
|
"let ↓abc : [([Void], String, Int)]\n",
|
|
"let ↓abc :String=\"def\"\n",
|
|
"let ↓abc :Int=0\n",
|
|
"let ↓abc :Int = 0\n",
|
|
"let ↓abc:Int=0\n",
|
|
"let ↓abc:Int = 0\n",
|
|
"let ↓abc:Enum=Enum.Value\n",
|
|
"func abc(↓def:Void) {}\n",
|
|
"func abc(↓def :Void) {}\n",
|
|
"func abc(↓def : Void) {}\n",
|
|
"func abc(def: Void, ↓ghi :Void) {}\n",
|
|
"let abc = [Void↓:Void]()\n",
|
|
"let abc = [Void↓ : Void]()\n",
|
|
"let abc = [Void↓ : Void]()\n",
|
|
"let abc = [1: [3↓ : 2], 3: 4]\n",
|
|
"let abc = [1: [3↓ : 2], 3: 4]\n"
|
|
]
|
|
let corrections = [
|
|
"let ↓abc:Void\n": "let abc: Void\n",
|
|
"let ↓abc :Void\n": "let abc: Void\n",
|
|
"let ↓abc : Void\n": "let abc: Void\n",
|
|
"let ↓abc : [Void: Void]\n": "let abc: [Void: Void]\n",
|
|
"let ↓abc : (Void, String, Int)\n": "let abc: (Void, String, Int)\n",
|
|
"let ↓abc : ([Void], String, Int)\n": "let abc: ([Void], String, Int)\n",
|
|
"let ↓abc : [([Void], String, Int)]\n": "let abc: [([Void], String, Int)]\n",
|
|
"let ↓abc :String=\"def\"\n": "let abc: String=\"def\"\n",
|
|
"let ↓abc :Int=0\n": "let abc: Int=0\n",
|
|
"let ↓abc :Int = 0\n": "let abc: Int = 0\n",
|
|
"let ↓abc:Int=0\n": "let abc: Int=0\n",
|
|
"let ↓abc:Int = 0\n": "let abc: Int = 0\n",
|
|
"let ↓abc:Enum=Enum.Value\n": "let abc: Enum=Enum.Value\n",
|
|
"func abc(↓def:Void) {}\n": "func abc(def: Void) {}\n",
|
|
"func abc(↓def :Void) {}\n": "func abc(def: Void) {}\n",
|
|
"func abc(↓def : Void) {}\n": "func abc(def: Void) {}\n",
|
|
"func abc(def: Void, ↓ghi :Void) {}\n": "func abc(def: Void, ghi: Void) {}\n",
|
|
"let abc = [Void↓:Void]()\n": "let abc = [Void: Void]()\n",
|
|
"let abc = [Void↓ : Void]()\n": "let abc = [Void: Void]()\n",
|
|
"let abc = [Void↓ : Void]()\n": "let abc = [Void: Void]()\n",
|
|
"let abc = [1: [3↓ : 2], 3: 4]\n": "let abc = [1: [3: 2], 3: 4]\n",
|
|
"let abc = [1: [3↓ : 2], 3: 4]\n": "let abc = [1: [3: 2], 3: 4]\n"
|
|
]
|
|
let description = ColonRule.description.with(triggeringExamples: triggeringExamples)
|
|
.with(nonTriggeringExamples: nonTriggeringExamples)
|
|
.with(corrections: corrections)
|
|
|
|
verifyRule(description, ruleConfiguration: ["flexible_right_spacing": true])
|
|
}
|
|
|
|
// swiftlint:disable:next function_body_length
|
|
func testColonWithoutApplyToDictionaries() {
|
|
let nonTriggeringExamples = ColonRule.description.nonTriggeringExamples + [
|
|
"let abc = [Void:Void]()\n",
|
|
"let abc = [Void : Void]()\n",
|
|
"let abc = [Void: Void]()\n",
|
|
"let abc = [Void : Void]()\n",
|
|
"let abc = [1: [3 : 2], 3: 4]\n",
|
|
"let abc = [1: [3 : 2], 3: 4]\n"
|
|
]
|
|
let triggeringExamples = [
|
|
"let ↓abc:Void\n",
|
|
"let ↓abc: Void\n",
|
|
"let ↓abc :Void\n",
|
|
"let ↓abc : Void\n",
|
|
"let ↓abc : [Void: Void]\n",
|
|
"let ↓abc : (Void, String, Int)\n",
|
|
"let ↓abc : ([Void], String, Int)\n",
|
|
"let ↓abc : [([Void], String, Int)]\n",
|
|
"let ↓abc: (Void, String, Int)\n",
|
|
"let ↓abc: ([Void], String, Int)\n",
|
|
"let ↓abc: [([Void], String, Int)]\n",
|
|
"let ↓abc :String=\"def\"\n",
|
|
"let ↓abc :Int=0\n",
|
|
"let ↓abc :Int = 0\n",
|
|
"let ↓abc:Int=0\n",
|
|
"let ↓abc:Int = 0\n",
|
|
"let ↓abc:Enum=Enum.Value\n",
|
|
"func abc(↓def:Void) {}\n",
|
|
"func abc(↓def: Void) {}\n",
|
|
"func abc(↓def :Void) {}\n",
|
|
"func abc(↓def : Void) {}\n",
|
|
"func abc(def: Void, ↓ghi :Void) {}\n"
|
|
]
|
|
let corrections = [
|
|
"let ↓abc:Void\n": "let abc: Void\n",
|
|
"let ↓abc: Void\n": "let abc: Void\n",
|
|
"let ↓abc :Void\n": "let abc: Void\n",
|
|
"let ↓abc : Void\n": "let abc: Void\n",
|
|
"let ↓abc : [Void: Void]\n": "let abc: [Void: Void]\n",
|
|
"let ↓abc : (Void, String, Int)\n": "let abc: (Void, String, Int)\n",
|
|
"let ↓abc : ([Void], String, Int)\n": "let abc: ([Void], String, Int)\n",
|
|
"let ↓abc : [([Void], String, Int)]\n": "let abc: [([Void], String, Int)]\n",
|
|
"let ↓abc: (Void, String, Int)\n": "let abc: (Void, String, Int)\n",
|
|
"let ↓abc: ([Void], String, Int)\n": "let abc: ([Void], String, Int)\n",
|
|
"let ↓abc: [([Void], String, Int)]\n": "let abc: [([Void], String, Int)]\n",
|
|
"let ↓abc :String=\"def\"\n": "let abc: String=\"def\"\n",
|
|
"let ↓abc :Int=0\n": "let abc: Int=0\n",
|
|
"let ↓abc :Int = 0\n": "let abc: Int = 0\n",
|
|
"let ↓abc:Int=0\n": "let abc: Int=0\n",
|
|
"let ↓abc:Int = 0\n": "let abc: Int = 0\n",
|
|
"let ↓abc:Enum=Enum.Value\n": "let abc: Enum=Enum.Value\n",
|
|
"func abc(↓def:Void) {}\n": "func abc(def: Void) {}\n",
|
|
"func abc(↓def: Void) {}\n": "func abc(def: Void) {}\n",
|
|
"func abc(↓def :Void) {}\n": "func abc(def: Void) {}\n",
|
|
"func abc(↓def : Void) {}\n": "func abc(def: Void) {}\n",
|
|
"func abc(def: Void, ↓ghi :Void) {}\n": "func abc(def: Void, ghi: Void) {}\n"
|
|
]
|
|
|
|
let description = ColonRule.description.with(triggeringExamples: triggeringExamples)
|
|
.with(nonTriggeringExamples: nonTriggeringExamples)
|
|
.with(corrections: corrections)
|
|
|
|
verifyRule(description, ruleConfiguration: ["apply_to_dictionaries": false])
|
|
}
|
|
}
|