Skip to content

Commit cff2b22

Browse files
committed
Added IgnoreFile unit tests
1 parent 3bc036e commit cff2b22

File tree

5 files changed

+34
-1
lines changed

5 files changed

+34
-1
lines changed

Package.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ var targets: [Target] = [
114114
"SwiftFormat",
115115
"_SwiftFormatTestSupport",
116116
.product(name: "Markdown", package: "swift-markdown"),
117-
] + swiftSyntaxDependencies(["SwiftOperators", "SwiftParser", "SwiftSyntax", "SwiftSyntaxBuilder"])
117+
] + swiftSyntaxDependencies(["SwiftOperators", "SwiftParser", "SwiftSyntax", "SwiftSyntaxBuilder"]),
118+
resources: [.copy("Resources")]
118119
),
119120
]
120121

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import SwiftFormat
2+
import XCTest
3+
4+
final class IgnoreFileTests: XCTestCase {
5+
6+
func testMissingIgnoreFile() throws {
7+
let url = Bundle.module.url(forResource: "missing", withExtension: "", subdirectory: "Ignore Files")
8+
XCTAssertNotNil(url)
9+
XCTAssertNil(try IgnoreFile(forDirectory: url!))
10+
}
11+
12+
func testValidIgnoreFile() throws {
13+
let url = Bundle.module.url(forResource: "valid", withExtension: "", subdirectory: "Ignore Files")
14+
XCTAssertNotNil(url)
15+
XCTAssertNotNil(try IgnoreFile(forDirectory: url!))
16+
}
17+
18+
func testInvalidIgnoreFile() throws {
19+
let url = Bundle.module.url(forResource: "invalid", withExtension: "", subdirectory: "Ignore Files")
20+
XCTAssertNotNil(url)
21+
XCTAssertThrowsError(try IgnoreFile(forDirectory: url!))
22+
}
23+
24+
func testEmptyIgnoreFile() throws {
25+
let url = Bundle.module.url(forResource: "empty", withExtension: "", subdirectory: "Ignore Files")
26+
XCTAssertNotNil(url)
27+
XCTAssertThrowsError(try IgnoreFile(forDirectory: url!))
28+
}
29+
30+
}

Tests/SwiftFormatTests/Resources/Ignore Files/empty/.swift-format-ignore

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
this is an invalid pattern
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*

0 commit comments

Comments
 (0)