mirror of
https://github.com/realm/SwiftLint.git
synced 2026-05-07 20:12:49 +00:00
Restructure indentation_width tests
This commit is contained in:
@@ -10662,11 +10662,6 @@ firstLine
|
||||
secondLine
|
||||
```
|
||||
|
||||
```swift
|
||||
firstLine
|
||||
secondLine
|
||||
```
|
||||
|
||||
```swift
|
||||
firstLine
|
||||
secondLine
|
||||
@@ -10675,14 +10670,6 @@ firstLine
|
||||
fourthLine
|
||||
```
|
||||
|
||||
```swift
|
||||
firstLine
|
||||
secondLine
|
||||
thirdLine
|
||||
|
||||
fourthLine
|
||||
```
|
||||
|
||||
```swift
|
||||
firstLine
|
||||
secondLine
|
||||
@@ -10702,11 +10689,6 @@ fourthLine
|
||||
<details>
|
||||
<summary>Triggering Examples</summary>
|
||||
|
||||
```swift
|
||||
firstLine
|
||||
secondLine
|
||||
```
|
||||
|
||||
```swift
|
||||
firstLine
|
||||
```
|
||||
@@ -10716,11 +10698,6 @@ firstLine
|
||||
secondLine
|
||||
```
|
||||
|
||||
```swift
|
||||
firstLine
|
||||
secondLine
|
||||
```
|
||||
|
||||
```swift
|
||||
firstLine
|
||||
secondLine
|
||||
|
||||
@@ -28,24 +28,17 @@ public struct IndentationWidthRule: ConfigurationProviderRule, OptInRule {
|
||||
"unindent to match previous indentations. Don't indent the first line.",
|
||||
kind: .style,
|
||||
nonTriggeringExamples: [
|
||||
"firstLine\nsecondLine", // It's okay to keep the same indentation
|
||||
"firstLine\n secondLine", // It's okay to indent using the specified indentationWidth
|
||||
"firstLine\n\tsecondLine", // It's okay to indent using a tab
|
||||
"firstLine\n\tsecondLine\n\t\tthirdLine\n\n\t\tfourthLine", // It's okay to have empty lines between
|
||||
"firstLine\n\tsecondLine\n\t\tthirdLine\n \n\t\tfourthLine", // It's okay to have empty lines between
|
||||
"firstLine\n\tsecondLine\n\t\tthirdLine\n//test\n\t\tfourthLine", // It's okay to have comment lines between
|
||||
"firstLine\nsecondLine",
|
||||
"firstLine\n secondLine",
|
||||
"firstLine\n\tsecondLine\n\t\tthirdLine\n\n\t\tfourthLine",
|
||||
"firstLine\n\tsecondLine\n\t\tthirdLine\n//test\n\t\tfourthLine",
|
||||
"firstLine\n secondLine\n thirdLine\nfourthLine"
|
||||
// It's okay to unindent indentationWidth * (1, 2, 3, ...)
|
||||
],
|
||||
triggeringExamples: [
|
||||
"firstLine\n\t secondLine", // It's not okay to indent using both tabs and spaces in one line
|
||||
" firstLine", // It's not okay to have the first line indented
|
||||
"firstLine\n secondLine", // It's not okay to indent using neither one tab or indentationWidth spaces
|
||||
"firstLine\n\t\tsecondLine", // It's not okay to indent using multiple tabs
|
||||
" firstLine",
|
||||
"firstLine\n secondLine",
|
||||
"firstLine\n\tsecondLine\n\n\t\t\tfourthLine",
|
||||
// It's okay to have empty lines between, but then, the following indentation must obey the rules
|
||||
"firstLine\n secondLine\n thirdLine\n fourthLine"
|
||||
// It's not okay to unindent indentationWidth * (1, 2, 3, ...) - 3
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
@@ -692,7 +692,8 @@ extension ImplicitlyUnwrappedOptionalRuleTests {
|
||||
|
||||
extension IndentationWidthRuleTests {
|
||||
static var allTests: [(String, (IndentationWidthRuleTests) -> () throws -> Void)] = [
|
||||
("testWithDefaultConfiguration", testWithDefaultConfiguration)
|
||||
("testTriggeringExamples", testTriggeringExamples),
|
||||
("testNonTriggeringExamples", testNonTriggeringExamples)
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@@ -3,10 +3,43 @@ import Foundation
|
||||
import XCTest
|
||||
|
||||
class IndentationWidthRuleTests: XCTestCase {
|
||||
func testWithDefaultConfiguration() {
|
||||
func testTriggeringExamples() {
|
||||
let triggeringExamples = [
|
||||
"firstLine\n\t secondLine", // It's not okay to indent using both tabs and spaces in one line
|
||||
" firstLine", // It's not okay to have the first line indented
|
||||
"firstLine\n secondLine", // It's not okay to indent using neither one tab or indentationWidth spaces
|
||||
"firstLine\n\t\tsecondLine", // It's not okay to indent using multiple tabs
|
||||
"firstLine\n\tsecondLine\n\n\t\t\tfourthLine",
|
||||
// It's okay to have empty lines between, but then, the following indentation must obey the rules
|
||||
"firstLine\n secondLine\n thirdLine\n fourthLine"
|
||||
// It's not okay to unindent indentationWidth * (1, 2, 3, ...) - 3
|
||||
]
|
||||
|
||||
// Don't do crazy testing as this triggers invalid warnings
|
||||
verifyRule(
|
||||
IndentationWidthRule.description,
|
||||
IndentationWidthRule.description.with(nonTriggeringExamples: [], triggeringExamples: triggeringExamples),
|
||||
skipCommentTests: true,
|
||||
skipDisableCommandTests: true,
|
||||
testMultiByteOffsets: false,
|
||||
testShebang: false
|
||||
)
|
||||
}
|
||||
|
||||
func testNonTriggeringExamples() {
|
||||
let nonTriggeringExamples = [
|
||||
"firstLine\nsecondLine", // It's okay to keep the same indentation
|
||||
"firstLine\n secondLine", // It's okay to indent using the specified indentationWidth
|
||||
"firstLine\n\tsecondLine", // It's okay to indent using a tab
|
||||
"firstLine\n\tsecondLine\n\t\tthirdLine\n\n\t\tfourthLine", // It's okay to have empty lines between
|
||||
"firstLine\n\tsecondLine\n\t\tthirdLine\n \n\t\tfourthLine", // It's okay to have empty lines between
|
||||
// "firstLine\n\tsecondLine\n\t\tthirdLine\n//test\n\t\tfourthLine", // It's okay to have comment lines between
|
||||
"firstLine\n secondLine\n thirdLine\nfourthLine"
|
||||
// It's okay to unindent indentationWidth * (1, 2, 3, ...)
|
||||
]
|
||||
|
||||
// Don't do crazy testing as this triggers invalid warnings
|
||||
verifyRule(
|
||||
IndentationWidthRule.description.with(nonTriggeringExamples: nonTriggeringExamples, triggeringExamples: []),
|
||||
skipCommentTests: true,
|
||||
skipDisableCommandTests: true,
|
||||
testMultiByteOffsets: false,
|
||||
|
||||
Reference in New Issue
Block a user