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
54 lines
2.0 KiB
Swift
54 lines
2.0 KiB
Swift
import SwiftLintCore
|
|
import Testing
|
|
|
|
@Suite
|
|
struct StringExtensionTests {
|
|
@Test
|
|
func relativePathExpression() {
|
|
#expect("Folder/Test" == "Root/Folder/Test".path(relativeTo: "Root"))
|
|
#expect("Test" == "Root/Folder/Test".path(relativeTo: "Root/Folder"))
|
|
#expect("" == "Root/Folder/Test".path(relativeTo: "Root/Folder/Test"))
|
|
#expect("../Test" == "Root/Folder/Test".path(relativeTo: "Root/Folder/SubFolder"))
|
|
#expect("../.." == "Root".path(relativeTo: "Root/Folder/SubFolder"))
|
|
#expect("../../OtherFolder/Test" == "Root/OtherFolder/Test".path(relativeTo: "Root/Folder/SubFolder"))
|
|
#expect("../MyFolder123" == "Folder/MyFolder123".path(relativeTo: "Folder/MyFolder"))
|
|
#expect("../MyFolder123" == "Folder/MyFolder123".path(relativeTo: "Folder/MyFolder/"))
|
|
#expect("Test" == "Root////Folder///Test/".path(relativeTo: "Root//Folder////"))
|
|
#expect("Root/Folder/Test" == "Root/Folder/Test/".path(relativeTo: ""))
|
|
}
|
|
|
|
@Test
|
|
func indent() {
|
|
#expect("string".indent(by: 3) == " string")
|
|
#expect(" string".indent(by: 2) == " string")
|
|
#expect(
|
|
"""
|
|
1
|
|
2
|
|
3
|
|
""".indent(by: 2) == """
|
|
1
|
|
2
|
|
3
|
|
"""
|
|
)
|
|
}
|
|
|
|
@Test
|
|
func characterPosition() {
|
|
#expect("string".characterPosition(of: -1) == nil)
|
|
#expect("string".characterPosition(of: 0) == 0)
|
|
#expect("string".characterPosition(of: 1) == 1)
|
|
#expect("string".characterPosition(of: 6) == nil)
|
|
#expect("string".characterPosition(of: 7) == nil)
|
|
|
|
#expect("s🤵🏼♀️s".characterPosition(of: 0) == 0)
|
|
#expect("s🤵🏼♀️s".characterPosition(of: 1) == 1)
|
|
for bytes in 2...17 {
|
|
#expect("s🤵🏼♀️s".characterPosition(of: bytes) == nil)
|
|
}
|
|
#expect("s🤵🏼♀️s".characterPosition(of: 18) == 2)
|
|
#expect("s🤵🏼♀️s".characterPosition(of: 19) == nil)
|
|
}
|
|
}
|