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
93 lines
3.3 KiB
Swift
93 lines
3.3 KiB
Swift
import SwiftLintCore
|
|
import TestHelpers
|
|
import Testing
|
|
|
|
@Suite
|
|
struct RegexConfigurationTests {
|
|
@Test
|
|
func shouldValidateIsTrueByDefault() {
|
|
let config = RegexConfiguration<MockRule>(identifier: "example")
|
|
#expect(config.shouldValidate(filePath: "App/file.swift".url()))
|
|
}
|
|
|
|
@Test
|
|
func shouldValidateWithSingleExluded() throws {
|
|
var config = RegexConfiguration<MockRule>(identifier: "example")
|
|
try config.apply(configuration: [
|
|
"regex": "try!",
|
|
"excluded": "ExcludedFolder/.*\\.swift",
|
|
])
|
|
|
|
#expect(!config.shouldValidate(filePath: "ExcludedFolder/file.swift".url()))
|
|
#expect(config.shouldValidate(filePath: "App/file.swift".url()))
|
|
}
|
|
|
|
@Test
|
|
func shouldValidateWithArrayExluded() throws {
|
|
var config = RegexConfiguration<MockRule>(identifier: "example")
|
|
try config.apply(configuration: [
|
|
"regex": "try!",
|
|
"excluded": [
|
|
"ExcludedFolder/.*\\.swift",
|
|
"MyFramework/ExcludedFolder/.*\\.swift",
|
|
] as Any,
|
|
])
|
|
|
|
#expect(!config.shouldValidate(filePath: "ExcludedFolder/file.swift".url()))
|
|
#expect(!config.shouldValidate(filePath: "MyFramework/ExcludedFolder/file.swift".url()))
|
|
#expect(config.shouldValidate(filePath: "App/file.swift".url()))
|
|
}
|
|
|
|
@Test
|
|
func shouldValidateWithSingleIncluded() throws {
|
|
var config = RegexConfiguration<MockRule>(identifier: "example")
|
|
try config.apply(configuration: [
|
|
"regex": "try!",
|
|
"included": "App/.*\\.swift",
|
|
])
|
|
|
|
#expect(!config.shouldValidate(filePath: "Tests/file.swift".url()))
|
|
#expect(!config.shouldValidate(filePath: "MyFramework/Tests/file.swift".url()))
|
|
#expect(config.shouldValidate(filePath: "App/file.swift".url()))
|
|
}
|
|
|
|
@Test
|
|
func shouldValidateWithArrayIncluded() throws {
|
|
var config = RegexConfiguration<MockRule>(identifier: "example")
|
|
try config.apply(configuration: [
|
|
"regex": "try!",
|
|
"included": [
|
|
"App/.*\\.swift",
|
|
"MyFramework/.*\\.swift",
|
|
] as Any,
|
|
])
|
|
|
|
#expect(!config.shouldValidate(filePath: "Tests/file.swift".url()))
|
|
#expect(config.shouldValidate(filePath: "App/file.swift".url()))
|
|
#expect(config.shouldValidate(filePath: "MyFramework/file.swift".url()))
|
|
}
|
|
|
|
@Test
|
|
func shouldValidateWithIncludedAndExcluded() throws {
|
|
var config = RegexConfiguration<MockRule>(identifier: "example")
|
|
try config.apply(configuration: [
|
|
"regex": "try!",
|
|
"included": [
|
|
"App/.*\\.swift",
|
|
"MyFramework/.*\\.swift",
|
|
] as Any,
|
|
"excluded": [
|
|
"ExcludedFolder/.*\\.swift",
|
|
"App/Fixtures/.*\\.swift",
|
|
] as Any,
|
|
])
|
|
|
|
#expect(config.shouldValidate(filePath: "App/file.swift".url()))
|
|
#expect(config.shouldValidate(filePath: "MyFramework/file.swift".url()))
|
|
|
|
#expect(!config.shouldValidate(filePath: "App/Fixtures/file.swift".url()))
|
|
#expect(!config.shouldValidate(filePath: "ExcludedFolder/file.swift".url()))
|
|
#expect(!config.shouldValidate(filePath: "MyFramework/ExcludedFolder/file.swift".url()))
|
|
}
|
|
}
|