Files
SwiftLint/Tests/BuiltInRulesTests/PreferKeyPathRuleTests.swift
Danny Mösch 15b285527a Separate built-in rule tests from framework tests (#5924)
* Short names for test modules
* Lint plugins and `Package.swift` in integration tests
* Simplify and merge file groups in Bazel
* Move common functions to `TestHelpers`
2024-12-30 12:26:46 +01:00

31 lines
1.0 KiB
Swift

@testable import SwiftLintBuiltInRules
import TestHelpers
import XCTest
final class PreferKeyPathRuleTests: SwiftLintTestCase {
private static let extendedMode = ["restrict_to_standard_functions": false]
func testIdentityExpressionInSwift6() throws {
try XCTSkipIf(SwiftVersion.current < .six)
let description = PreferKeyPathRule.description
.with(nonTriggeringExamples: [
Example("f.filter { a in b }"),
Example("f.g { $1 }", configuration: Self.extendedMode),
])
.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)"),
])
verifyRule(description)
}
}