Files
SwiftLint/Tests/BuiltInRulesTests/PreferKeyPathRuleTests.swift
Danny Mösch ac2eda6732 Adopt Swift Testing
# 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
2026-06-06 11:07:04 +02:00

43 lines
1.7 KiB
Swift

import TestHelpers
import Testing
@testable import SwiftLintBuiltInRules
@Suite(.rulesRegistered)
struct PreferKeyPathRuleTests {
private static let extendedMode = ["restrict_to_standard_functions": false]
private static let ignoreIdentity = ["ignore_identity_closures": true]
private static let extendedModeAndIgnoreIdentity = [
"restrict_to_standard_functions": false,
"ignore_identity_closures": true,
]
@Test(.disabled(if: SwiftVersion.current < .six))
func identityExpressionInSwift6() {
let description = PreferKeyPathRule.description
.with(nonTriggeringExamples: [
Example("f.filter { a in b }"),
Example("f.g { $1 }", configuration: Self.extendedMode),
Example("f { $0 }", configuration: Self.extendedModeAndIgnoreIdentity),
Example("f.map { $0 }", configuration: Self.ignoreIdentity),
])
.with(triggeringExamples: [
Example("f.compactMap ↓{ $0 }"),
Example("f.map ↓{ a in a }"),
Example("f.g { $0 }", configuration: Self.extendedMode),
])
.with(corrections: [
Example("f.map ↓{ $0 }"):
Example("f.map(\\.self)"),
Example("f.g { $0 }", configuration: Self.extendedMode):
Example("f.g(\\.self)"),
Example("f { $0 }", configuration: Self.extendedModeAndIgnoreIdentity): // no change with option enabled
Example("f { $0 }"),
Example("f.map { $0 }", configuration: Self.ignoreIdentity): // no change with option enabled
Example("f.map { $0 }"),
])
verifyRule(description)
}
}