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
101 lines
3.2 KiB
Swift
101 lines
3.2 KiB
Swift
import TestHelpers
|
|
import Testing
|
|
|
|
@testable import SwiftLintBuiltInRules
|
|
|
|
@Suite(.rulesRegistered)
|
|
struct TypeBodyLengthConfigurationTests {
|
|
@Test
|
|
func defaultConfiguration() {
|
|
let config = TypeBodyLengthConfiguration()
|
|
#expect(config.severityConfiguration.warning == 250)
|
|
#expect(config.severityConfiguration.error == 350)
|
|
#expect(config.excludedTypes == [.extension, .protocol])
|
|
}
|
|
|
|
@Test
|
|
func applyingCustomConfiguration() throws {
|
|
var config = TypeBodyLengthConfiguration()
|
|
try config.apply(
|
|
configuration: [
|
|
"warning": 150,
|
|
"error": 200,
|
|
"excluded_types": ["struct", "class"],
|
|
] as [String: any Sendable]
|
|
)
|
|
#expect(config.severityConfiguration.warning == 150)
|
|
#expect(config.severityConfiguration.error == 200)
|
|
#expect(config.excludedTypes == Set([.struct, .class]))
|
|
}
|
|
|
|
@Test
|
|
func applyingOnlyExcludedTypesConfiguration() throws {
|
|
var config = TypeBodyLengthConfiguration()
|
|
try config.apply(
|
|
configuration: [
|
|
"excluded_types": ["actor", "enum"]
|
|
] as [String: any Sendable]
|
|
)
|
|
|
|
// Severity should remain default
|
|
#expect(config.severityConfiguration.warning == 250)
|
|
#expect(config.severityConfiguration.error == 350)
|
|
|
|
// Excluded types should be updated
|
|
#expect(config.excludedTypes == Set([.actor, .enum]))
|
|
}
|
|
|
|
@Test
|
|
func applyingAllTypesAsExcludedConfiguration() throws {
|
|
var config = TypeBodyLengthConfiguration()
|
|
try config.apply(
|
|
configuration: [
|
|
"excluded_types": ["struct", "class", "actor", "enum", "extension", "protocol"]
|
|
] as [String: any Sendable]
|
|
)
|
|
#expect(config.excludedTypes == Set(TypeBodyLengthCheckType.allCases))
|
|
}
|
|
|
|
@Test
|
|
func applyingEmptyExcludedTypesConfiguration() throws {
|
|
var config = TypeBodyLengthConfiguration()
|
|
try config.apply(
|
|
configuration: [
|
|
"excluded_types": [] as [String]
|
|
] as [String: any Sendable]
|
|
)
|
|
#expect(config.excludedTypes.isEmpty)
|
|
}
|
|
|
|
@Test
|
|
func applyingSingleExcludedTypeConfiguration() throws {
|
|
var config = TypeBodyLengthConfiguration()
|
|
try config.apply(
|
|
configuration: [
|
|
"excluded_types": ["extension"]
|
|
] as [String: any Sendable]
|
|
)
|
|
#expect(config.excludedTypes == Set([.extension]))
|
|
}
|
|
|
|
@Test
|
|
func invalidExcludedTypeConfiguration() {
|
|
var config = TypeBodyLengthConfiguration()
|
|
checkError(Issue.invalidConfiguration(ruleID: TypeBodyLengthRule.identifier)) {
|
|
try config.apply(
|
|
configuration: [
|
|
"excluded_types": ["invalid_type"]
|
|
] as [String: any Sendable]
|
|
)
|
|
}
|
|
#expect(config.excludedTypes == Set([.extension, .protocol]))
|
|
}
|
|
|
|
@Test
|
|
func typeEnumComparability() {
|
|
#expect(
|
|
TypeBodyLengthCheckType.allCases.sorted() == [.actor, .class, .enum, .extension, .protocol, .struct]
|
|
)
|
|
}
|
|
}
|