Skip to content

Commit e73b85b

Browse files
authored
Merge pull request #2367 from gmittert/UseWinFSR
[Windows] Added a test for _getFilesystemRepresentation
2 parents 711dade + 12682b5 commit e73b85b

File tree

1 file changed

+56
-1
lines changed

1 file changed

+56
-1
lines changed

Tests/Foundation/Tests/TestFileManager.swift

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1755,6 +1755,55 @@ VIDEOS=StopgapVideos
17551755
}
17561756
#endif
17571757
}
1758+
1759+
func test_windowsPaths() throws {
1760+
let fm = FileManager.default
1761+
let tmpPath = writableTestDirectoryURL.path
1762+
do {
1763+
try fm.createDirectory(atPath: tmpPath, withIntermediateDirectories: true, attributes: nil)
1764+
} catch {
1765+
XCTFail()
1766+
}
1767+
fm.changeCurrentDirectoryPath(tmpPath)
1768+
func checkPath(path: String) throws {
1769+
XCTAssertTrue(fm.createFile(atPath: path, contents: Data(), attributes: nil))
1770+
XCTAssertTrue(fm.fileExists(atPath: path))
1771+
try fm.removeItem(atPath: path)
1772+
XCTAssertFalse(fm.fileExists(atPath: path))
1773+
1774+
let url = URL(fileURLWithPath: path)
1775+
try "hello world".write(to: url, atomically: false, encoding: .utf8)
1776+
try fm.removeItem(atPath: path)
1777+
XCTAssertFalse(fm.fileExists(atPath: path))
1778+
}
1779+
let paths = [
1780+
// Absolute Paths
1781+
"\(tmpPath)\\testfile", // C:/Users/...\testfile
1782+
"\(tmpPath)/testfile", // C:/Users.../testfile
1783+
"\(tmpPath)/testfile", // /Users/user/.../testfile
1784+
"\(tmpPath.first!):testfile", // C:testfile
1785+
1786+
// Relative Paths
1787+
".\\testfile",
1788+
"..\\\(tmpPath.lastPathComponent)\\.\\testfile",
1789+
"testfile",
1790+
"./testfile",
1791+
"../\(tmpPath.lastPathComponent)/./testfile",
1792+
1793+
// UNC Paths
1794+
"\\\\.\\\(tmpPath)\\testfile",
1795+
"\\\\.\\\(tmpPath)/testfile",
1796+
"\\\\?\\\(String(tmpPath.map({ $0 == "/" ? "\\" : $0})))\\testfile",
1797+
1798+
// Unicode characters which require a single WCHAR
1799+
"λf.(λx.f(x x) λx.f(x x))",
1800+
// Unicode characters which require more than a single WCHAR
1801+
"👁️💖🐦",
1802+
]
1803+
for path in paths {
1804+
try checkPath(path: path)
1805+
}
1806+
}
17581807

17591808
// -----
17601809

@@ -1827,7 +1876,13 @@ VIDEOS=StopgapVideos
18271876
("test_fetchXDGPathsFromHelper", test_fetchXDGPathsFromHelper),
18281877
])
18291878
#endif
1830-
1879+
1880+
#if os(Windows)
1881+
tests.append(contentsOf: [
1882+
("test_windowsPaths", test_windowsPaths),
1883+
])
1884+
#endif
1885+
18311886
return tests
18321887
}
18331888
}

0 commit comments

Comments
 (0)