Restructure indentation_width tests

This commit is contained in:
Frederick Pietschmann
2019-05-28 15:16:08 +02:00
parent 1fbb39dd50
commit 35cd789ba1
4 changed files with 43 additions and 39 deletions
-23
View File
@@ -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
]
)
+2 -1
View File
@@ -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,