mirror of
https://github.com/realm/SwiftLint.git
synced 2026-06-06 20:18:40 +00:00
# Conflicts: # Tests/BuiltInRulesTests/FileHeaderRuleTests.swift # Tests/BuiltInRulesTests/FileNameNoSpaceRuleTests.swift # Tests/BuiltInRulesTests/IndentationWidthRuleTests.swift # Tests/CoreTests/RegexConfigurationTests.swift # Tests/CoreTests/SwiftLintFileTests.swift # Tests/FileSystemAccessTests/BaselineTests.swift # Tests/FileSystemAccessTests/ConfigurationTests+Mock.swift # Tests/FileSystemAccessTests/ConfigurationTests.swift # Tests/FileSystemAccessTests/GlobTests.swift # Tests/FileSystemAccessTests/MultipleConfigurationsTests.swift # Tests/FileSystemAccessTests/ReporterTests.swift # Tests/FileSystemAccessTests/SourceKitCrashTests.swift # Tests/FrameworkTests/CustomRulesTests.swift # Tests/FrameworkTests/LinterCacheTests.swift # Tests/FrameworkTests/RuleConfigurationTests.swift # Tests/FrameworkTests/SwiftVersionTests.swift # Tests/GeneratedTests/GeneratedTests_02.swift # Tests/GeneratedTests/GeneratedTests_03.swift # Tests/GeneratedTests/GeneratedTests_04.swift # Tests/GeneratedTests/GeneratedTests_05.swift # Tests/GeneratedTests/GeneratedTests_06.swift # Tests/GeneratedTests/GeneratedTests_07.swift # Tests/GeneratedTests/GeneratedTests_08.swift # Tests/GeneratedTests/GeneratedTests_09.swift # Tests/GeneratedTests/GeneratedTests_10.swift # Tests/IntegrationTests/ConfigPathResolutionTests.swift # Tests/IntegrationTests/IntegrationTests.swift # Tests/TestHelpers/TestHelpers.swift
141 lines
8.1 KiB
Swift
141 lines
8.1 KiB
Swift
import TestHelpers
|
|
import Testing
|
|
|
|
@testable import SwiftLintBuiltInRules
|
|
|
|
@Suite(.rulesRegistered)
|
|
struct ColonRuleTests {
|
|
@Test
|
|
func colonWithFlexibleRightSpace() {
|
|
// Verify Colon rule with test values for when flexible_right_spacing
|
|
// is true.
|
|
let nonTriggeringExamples = ColonRule.description.nonTriggeringExamples + [
|
|
Example("let abc: Void\n"),
|
|
Example("let abc: (Void, String, Int)\n"),
|
|
Example("let abc: ([Void], String, Int)\n"),
|
|
Example("let abc: [([Void], String, Int)]\n"),
|
|
Example("func abc(def: Void) {}\n"),
|
|
Example("let abc = [Void: Void]()\n"),
|
|
]
|
|
let triggeringExamples: [Example] = [
|
|
Example("let abc↓:Void\n"),
|
|
Example("let abc↓ :Void\n"),
|
|
Example("let abc↓ : Void\n"),
|
|
Example("let abc↓ : [Void: Void]\n"),
|
|
Example("let abc↓ : (Void, String, Int)\n"),
|
|
Example("let abc↓ : ([Void], String, Int)\n"),
|
|
Example("let abc↓ : [([Void], String, Int)]\n"),
|
|
Example("let abc↓ :String=\"def\"\n"),
|
|
Example("let abc↓ :Int=0\n"),
|
|
Example("let abc↓ :Int = 0\n"),
|
|
Example("let abc↓:Int=0\n"),
|
|
Example("let abc↓:Int = 0\n"),
|
|
Example("let abc↓:Enum=Enum.Value\n"),
|
|
Example("func abc(def↓:Void) {}\n"),
|
|
Example("func abc(def↓ :Void) {}\n"),
|
|
Example("func abc(def↓ : Void) {}\n"),
|
|
Example("func abc(def: Void, ghi↓ :Void) {}\n"),
|
|
Example("let abc = [Void↓:Void]()\n"),
|
|
Example("let abc = [Void↓ : Void]()\n"),
|
|
Example("let abc = [Void↓ : Void]()\n"),
|
|
Example("let abc = [1: [3↓ : 2], 3: 4]\n"),
|
|
Example("let abc = [1: [3↓ : 2], 3: 4]\n"),
|
|
]
|
|
let corrections: [Example: Example] = [
|
|
Example("let abc↓:Void\n"): Example("let abc: Void\n"),
|
|
Example("let abc↓ :Void\n"): Example("let abc: Void\n"),
|
|
Example("let abc↓ : Void\n"): Example("let abc: Void\n"),
|
|
Example("let abc↓ : [Void: Void]\n"): Example("let abc: [Void: Void]\n"),
|
|
Example("let abc↓ : (Void, String, Int)\n"): Example("let abc: (Void, String, Int)\n"),
|
|
Example("let abc↓ : ([Void], String, Int)\n"): Example("let abc: ([Void], String, Int)\n"),
|
|
Example("let abc↓ : [([Void], String, Int)]\n"): Example("let abc: [([Void], String, Int)]\n"),
|
|
Example("let abc↓ :String=\"def\"\n"): Example("let abc: String=\"def\"\n"),
|
|
Example("let abc↓ :Int=0\n"): Example("let abc: Int=0\n"),
|
|
Example("let abc↓ :Int = 0\n"): Example("let abc: Int = 0\n"),
|
|
Example("let abc↓:Int=0\n"): Example("let abc: Int=0\n"),
|
|
Example("let abc↓:Int = 0\n"): Example("let abc: Int = 0\n"),
|
|
Example("let abc↓:Enum=Enum.Value\n"): Example("let abc: Enum=Enum.Value\n"),
|
|
Example("func abc(def↓:Void) {}\n"): Example("func abc(def: Void) {}\n"),
|
|
Example("func abc(def↓ :Void) {}\n"): Example("func abc(def: Void) {}\n"),
|
|
Example("func abc(def↓ : Void) {}\n"): Example("func abc(def: Void) {}\n"),
|
|
Example("func abc(def: Void, ghi↓ :Void) {}\n"): Example("func abc(def: Void, ghi: Void) {}\n"),
|
|
Example("let abc = [Void↓:Void]()\n"): Example("let abc = [Void: Void]()\n"),
|
|
Example("let abc = [Void↓ : Void]()\n"): Example("let abc = [Void: Void]()\n"),
|
|
Example("let abc = [Void↓ : Void]()\n"): Example("let abc = [Void: Void]()\n"),
|
|
Example("let abc = [1: [3↓ : 2], 3: 4]\n"): Example("let abc = [1: [3: 2], 3: 4]\n"),
|
|
Example("let abc = [1: [3↓ : 2], 3: 4]\n"): Example("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])
|
|
}
|
|
|
|
@Test
|
|
func colonWithoutApplyToDictionaries() {
|
|
let nonTriggeringExamples = ColonRule.description.nonTriggeringExamples + [
|
|
Example("let abc = [Void:Void]()\n"),
|
|
Example("let abc = [Void : Void]()\n"),
|
|
Example("let abc = [Void: Void]()\n"),
|
|
Example("let abc = [Void : Void]()\n"),
|
|
Example("let abc = [1: [3 : 2], 3: 4]\n"),
|
|
Example("let abc = [1: [3 : 2], 3: 4]\n"),
|
|
]
|
|
let triggeringExamples: [Example] = [
|
|
Example("let abc↓:Void\n"),
|
|
Example("let abc↓: Void\n"),
|
|
Example("let abc↓ :Void\n"),
|
|
Example("let abc↓ : Void\n"),
|
|
Example("let abc↓ : [Void: Void]\n"),
|
|
Example("let abc↓ : (Void, String, Int)\n"),
|
|
Example("let abc↓ : ([Void], String, Int)\n"),
|
|
Example("let abc↓ : [([Void], String, Int)]\n"),
|
|
Example("let abc↓: (Void, String, Int)\n"),
|
|
Example("let abc↓: ([Void], String, Int)\n"),
|
|
Example("let abc↓: [([Void], String, Int)]\n"),
|
|
Example("let abc↓ :String=\"def\"\n"),
|
|
Example("let abc↓ :Int=0\n"),
|
|
Example("let abc↓ :Int = 0\n"),
|
|
Example("let abc↓:Int=0\n"),
|
|
Example("let abc↓:Int = 0\n"),
|
|
Example("let abc↓:Enum=Enum.Value\n"),
|
|
Example("func abc(def↓:Void) {}\n"),
|
|
Example("func abc(def↓: Void) {}\n"),
|
|
Example("func abc(def↓ :Void) {}\n"),
|
|
Example("func abc(def↓ : Void) {}\n"),
|
|
Example("func abc(def: Void, ghi↓ :Void) {}\n"),
|
|
]
|
|
let corrections: [Example: Example] = [
|
|
Example("let abc↓:Void\n"): Example("let abc: Void\n"),
|
|
Example("let abc↓: Void\n"): Example("let abc: Void\n"),
|
|
Example("let abc↓ :Void\n"): Example("let abc: Void\n"),
|
|
Example("let abc↓ : Void\n"): Example("let abc: Void\n"),
|
|
Example("let abc↓ : [Void: Void]\n"): Example("let abc: [Void: Void]\n"),
|
|
Example("let abc↓ : (Void, String, Int)\n"): Example("let abc: (Void, String, Int)\n"),
|
|
Example("let abc↓ : ([Void], String, Int)\n"): Example("let abc: ([Void], String, Int)\n"),
|
|
Example("let abc↓ : [([Void], String, Int)]\n"): Example("let abc: [([Void], String, Int)]\n"),
|
|
Example("let abc↓: (Void, String, Int)\n"): Example("let abc: (Void, String, Int)\n"),
|
|
Example("let abc↓: ([Void], String, Int)\n"): Example("let abc: ([Void], String, Int)\n"),
|
|
Example("let abc↓: [([Void], String, Int)]\n"): Example("let abc: [([Void], String, Int)]\n"),
|
|
Example("let abc↓ :String=\"def\"\n"): Example("let abc: String=\"def\"\n"),
|
|
Example("let abc↓ :Int=0\n"): Example("let abc: Int=0\n"),
|
|
Example("let abc↓ :Int = 0\n"): Example("let abc: Int = 0\n"),
|
|
Example("let abc↓:Int=0\n"): Example("let abc: Int=0\n"),
|
|
Example("let abc↓:Int = 0\n"): Example("let abc: Int = 0\n"),
|
|
Example("let abc↓:Enum=Enum.Value\n"): Example("let abc: Enum=Enum.Value\n"),
|
|
Example("func abc(def↓:Void) {}\n"): Example("func abc(def: Void) {}\n"),
|
|
Example("func abc(def↓: Void) {}\n"): Example("func abc(def: Void) {}\n"),
|
|
Example("func abc(def↓ :Void) {}\n"): Example("func abc(def: Void) {}\n"),
|
|
Example("func abc(def↓ : Void) {}\n"): Example("func abc(def: Void) {}\n"),
|
|
Example("func abc(def: Void, ghi↓ :Void) {}\n"): Example("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])
|
|
}
|
|
}
|