Files
SwiftLint/Tests/BuiltInRulesTests/ImplicitGetterRuleTests.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

40 lines
1.2 KiB
Swift

@testable import SwiftLintBuiltInRules
import TestHelpers
import XCTest
final class ImplicitGetterRuleTests: SwiftLintTestCase {
func testPropertyReason() throws {
let config = try XCTUnwrap(makeConfig(nil, ImplicitGetterRule.identifier))
let example = Example("""
class Foo {
var foo: Int {
↓get {
return 20
}
}
}
""")
let violations = violations(example, config: config)
XCTAssertEqual(violations.count, 1)
XCTAssertEqual(violations.first?.reason, "Computed read-only properties should avoid using the get keyword")
}
func testSubscriptReason() throws {
let config = try XCTUnwrap(makeConfig(nil, ImplicitGetterRule.identifier))
let example = Example("""
class Foo {
subscript(i: Int) -> Int {
↓get {
return 20
}
}
}
""")
let violations = violations(example, config: config)
XCTAssertEqual(violations.count, 1)
XCTAssertEqual(violations.first?.reason, "Computed read-only subscripts should avoid using the get keyword")
}
}