Skip to content

Commit 4dffe09

Browse files
committed
Added test for nested directory.
1 parent 77c6a42 commit 4dffe09

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

Sources/SwiftFormat/Core/IgnoreFile.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ public class IgnoreFile {
6060
/// Returns nil if no ignore file is found.
6161
/// Throws an error if an invalid ignore file is found somewhere
6262
/// in the directory tree.
63+
///
64+
/// Note that we start the search from the given URL's **container**,
65+
/// not the URL itself; the URL passed in is expected to be for a file.
66+
/// If you pass a directory URL, the search will not include the contents
67+
/// of that directory.
6368
public convenience init?(for url: URL) throws {
6469
var containingDirectory = url.absoluteURL.standardized
6570
repeat {

Tests/SwiftFormatTests/Core/IgnoreFileTests.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,35 @@ final class IgnoreFileTests: XCTestCase {
77
let url = Bundle.module.url(forResource: "missing", withExtension: "", subdirectory: "Ignore Files")
88
XCTAssertNotNil(url)
99
XCTAssertNil(try IgnoreFile(forDirectory: url!))
10+
XCTAssertNil(try IgnoreFile(for: url!.appending(path:"file.swift")))
1011
}
1112

1213
func testValidIgnoreFile() throws {
1314
let url = Bundle.module.url(forResource: "valid", withExtension: "", subdirectory: "Ignore Files")
1415
XCTAssertNotNil(url)
1516
XCTAssertNotNil(try IgnoreFile(forDirectory: url!))
17+
XCTAssertNotNil(try IgnoreFile(for: url!.appending(path:"file.swift")))
1618
}
1719

1820
func testInvalidIgnoreFile() throws {
1921
let url = Bundle.module.url(forResource: "invalid", withExtension: "", subdirectory: "Ignore Files")
2022
XCTAssertNotNil(url)
2123
XCTAssertThrowsError(try IgnoreFile(forDirectory: url!))
24+
XCTAssertThrowsError(try IgnoreFile(for: url!.appending(path:"file.swift")))
2225
}
2326

2427
func testEmptyIgnoreFile() throws {
2528
let url = Bundle.module.url(forResource: "empty", withExtension: "", subdirectory: "Ignore Files")
2629
XCTAssertNotNil(url)
2730
XCTAssertThrowsError(try IgnoreFile(forDirectory: url!))
31+
XCTAssertThrowsError(try IgnoreFile(for: url!.appending(path:"file.swift")))
32+
}
33+
34+
func testNestedIgnoreFile() throws {
35+
let url = Bundle.module.url(forResource: "nested", withExtension: "", subdirectory: "Ignore Files")
36+
XCTAssertNotNil(url)
37+
let subdirectory = url!.appendingPathComponent("subdirectory").appending(path: "file.swift")
38+
XCTAssertNotNil(try IgnoreFile(for: subdirectory))
2839
}
2940

3041
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*

0 commit comments

Comments
 (0)