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
168 lines
4.2 KiB
Swift
168 lines
4.2 KiB
Swift
import SwiftLintCore
|
|
import SwiftParser
|
|
import SwiftSyntax
|
|
import Testing
|
|
|
|
@Suite
|
|
struct CodeIndentingRewriterTests {
|
|
@Test
|
|
func indentDefaultStyle() {
|
|
assertIndent(
|
|
source: """
|
|
if c {
|
|
// comment
|
|
return 1
|
|
// another comment
|
|
}
|
|
""",
|
|
indentedSource: """
|
|
if c {
|
|
// comment
|
|
return 1
|
|
// another comment
|
|
}
|
|
""",
|
|
style: .indentSpaces(4)
|
|
)
|
|
}
|
|
|
|
@Test
|
|
func indentThreeSpaces() {
|
|
assertIndent(
|
|
source: """
|
|
if c {
|
|
// comment
|
|
return 1
|
|
// another comment
|
|
}
|
|
""",
|
|
indentedSource: """
|
|
if c {
|
|
// comment
|
|
return 1
|
|
// another comment
|
|
}
|
|
""",
|
|
style: .indentSpaces(3)
|
|
)
|
|
}
|
|
|
|
@Test
|
|
func indentTabs() {
|
|
assertIndent(
|
|
source: """
|
|
if c {
|
|
// comment
|
|
return 1
|
|
// another comment
|
|
}
|
|
""",
|
|
indentedSource: """
|
|
\tif c {
|
|
\t // comment
|
|
\t return 1
|
|
\t // another comment
|
|
\t}
|
|
""",
|
|
style: .indentTabs(1)
|
|
)
|
|
}
|
|
|
|
@Test
|
|
func indentCodeBlock() {
|
|
assertIndent(
|
|
source: """
|
|
// initial comment
|
|
{
|
|
if c {
|
|
// comment
|
|
return 1
|
|
// another comment
|
|
}
|
|
// yet another comment
|
|
}
|
|
""",
|
|
indentedSource: """
|
|
// initial comment
|
|
{
|
|
if c {
|
|
// comment
|
|
return 1
|
|
// another comment
|
|
}
|
|
// yet another comment
|
|
}
|
|
""",
|
|
style: .indentSpaces(4)
|
|
)
|
|
}
|
|
|
|
@Test
|
|
func unindentDefaultStyle() {
|
|
assertIndent(
|
|
source: """
|
|
if c {
|
|
// comment
|
|
return 1
|
|
// another comment
|
|
}
|
|
""",
|
|
indentedSource: """
|
|
if c {
|
|
// comment
|
|
return 1
|
|
// another comment
|
|
}
|
|
""",
|
|
style: .unindentSpaces(4)
|
|
)
|
|
}
|
|
|
|
@Test
|
|
func unindentTwoSpaces() {
|
|
assertIndent(
|
|
source: """
|
|
if c {
|
|
// comment
|
|
return 1
|
|
// another comment
|
|
}
|
|
""",
|
|
indentedSource: """
|
|
if c {
|
|
// comment
|
|
return 1
|
|
// another comment
|
|
}
|
|
""",
|
|
style: .unindentSpaces(2)
|
|
)
|
|
}
|
|
|
|
@Test
|
|
func unindentTabs() {
|
|
assertIndent(
|
|
source: """
|
|
\tif c {
|
|
\t\t // comment
|
|
\t\treturn 1
|
|
\t\t\t// another comment
|
|
\t}
|
|
""",
|
|
indentedSource: """
|
|
if c {
|
|
\t // comment
|
|
\treturn 1
|
|
\t\t// another comment
|
|
}
|
|
""",
|
|
style: .unindentTabs(1)
|
|
)
|
|
}
|
|
|
|
private func assertIndent(source: String, indentedSource: String, style: CodeIndentingRewriter.IndentationStyle) {
|
|
let rewritten = CodeIndentingRewriter(style: style).rewrite(Parser.parse(source: source))
|
|
#expect(rewritten.description == indentedSource)
|
|
}
|
|
}
|