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.
59 lines
2.2 KiB
Swift
59 lines
2.2 KiB
Swift
import SwiftLintFramework
|
|
import XCTest
|
|
|
|
class IdentifierNameRuleTests: XCTestCase {
|
|
|
|
func testIdentifierName() {
|
|
verifyRule(IdentifierNameRule.description)
|
|
}
|
|
|
|
func testIdentifierNameWithAllowedSymbols() {
|
|
let baseDescription = IdentifierNameRule.description
|
|
let nonTriggeringExamples = baseDescription.nonTriggeringExamples + [
|
|
"let myLet$ = 0",
|
|
"let myLet% = 0",
|
|
"let myLet$% = 0"
|
|
]
|
|
|
|
let description = baseDescription.with(nonTriggeringExamples: nonTriggeringExamples)
|
|
verifyRule(description, ruleConfiguration: ["allowed_symbols": ["$", "%"]])
|
|
}
|
|
|
|
func testIdentifierNameWithAllowedSymbolsAndViolation() {
|
|
let baseDescription = IdentifierNameRule.description
|
|
let triggeringExamples = [
|
|
"↓let my_Let$ = 0"
|
|
]
|
|
|
|
let description = baseDescription.with(triggeringExamples: triggeringExamples)
|
|
verifyRule(description, ruleConfiguration: ["allowed_symbols": ["$", "%"]])
|
|
}
|
|
|
|
func testIdentifierNameWithIgnoreStartWithLowercase() {
|
|
let baseDescription = IdentifierNameRule.description
|
|
let triggeringExamplesToRemove = [
|
|
"↓let MyLet = 0",
|
|
"enum Foo { case ↓MyEnum }"
|
|
]
|
|
let nonTriggeringExamples = baseDescription.nonTriggeringExamples +
|
|
triggeringExamplesToRemove.map { $0.replacingOccurrences(of: "↓", with: "") }
|
|
let triggeringExamples = baseDescription.triggeringExamples
|
|
.filter { !triggeringExamplesToRemove.contains($0) }
|
|
|
|
let description = baseDescription.with(nonTriggeringExamples: nonTriggeringExamples)
|
|
.with(triggeringExamples: triggeringExamples)
|
|
|
|
verifyRule(description, ruleConfiguration: ["validates_start_with_lowercase": false])
|
|
}
|
|
|
|
func testLinuxCrashOnEmojiNames() {
|
|
let baseDescription = IdentifierNameRule.description
|
|
let triggeringExamples = [
|
|
"let 👦🏼 = \"👦🏼\""
|
|
]
|
|
|
|
let description = baseDescription.with(triggeringExamples: triggeringExamples)
|
|
verifyRule(description, ruleConfiguration: ["allowed_symbols": ["$", "%"]])
|
|
}
|
|
}
|