@@ -27,6 +27,16 @@ let kCFURLCreateAbsoluteURLWithBytesCreator = "CFURLCreateAbsoluteURLWithBytes"
2727let kNullURLString = " <null url> "
2828let kNullString = " <null> "
2929
30+ func XCTAssertEqualFileSystemPaths( _ lhs: String ? , _ rhs: String ? , _ message: @autoclosure ( ) -> String = " " , file: StaticString = #filePath, line: UInt = #line) {
31+ #if os(Windows)
32+ let mappedLHS = lhs? . replacingOccurrences ( of: " \\ " , with: " / " )
33+ let mappedRHS = rhs? . replacingOccurrences ( of: " \\ " , with: " / " )
34+ XCTAssertEqual ( mappedLHS, mappedRHS, message ( ) , file: file, line: line)
35+ #else
36+ XCTAssertEqual ( lhs, rhs, message ( ) , file: file, line: line)
37+ #endif
38+ }
39+
3040/// Reads the test data plist file and returns the list of objects
3141private func getTestData( ) -> [ Any ] ? {
3242 let testFilePath = testBundle ( ) . url ( forResource: " NSURLTestData " , withExtension: " plist " )
@@ -54,17 +64,6 @@ class TestURL : XCTestCase {
5464 let u1 = URL ( fileURLWithPath: " S: \\ b \\ u1/ " )
5565 XCTAssertEqual ( u1. absoluteString, " file:///S:/b/u1/ " )
5666
57- // ensure that trailing slashes are compressed
58- // e.g. NOT file:///S:/b/u2%2F%2F%2F%/
59- let u2 = URL ( fileURLWithPath: " S: \\ b \\ u2///// " )
60- XCTAssertEqual ( u2. absoluteString, " file:///S:/b/u2/ " )
61-
62- // ensure that the trailing slashes are compressed even when mixed
63- // e.g. NOT file:///S:/b/u3%2F%/%2F%2/
64- let u3 = URL ( fileURLWithPath: " S: \\ b \\ u3// \\ // " )
65- XCTAssertEqual ( u3. absoluteString, " file:///S:/b/u3/ " )
66- XCTAssertEqual ( u3. path, " S:/b/u3 " )
67-
6867 // ensure that the regular conversion works
6968 let u4 = URL ( fileURLWithPath: " S: \\ b \\ u4 " )
7069 XCTAssertEqual ( u4. absoluteString, " file:///S:/b/u4 " )
@@ -103,9 +102,6 @@ class TestURL : XCTestCase {
103102 let u3 = URL ( fileURLWithPath: " \\ " , isDirectory: false )
104103 XCTAssertEqual ( u3. absoluteString, " file:/// " )
105104
106- let u4 = URL ( fileURLWithPath: " S: \\ b \\ u3// \\ // " )
107- XCTAssertEqual ( u4. absoluteString, " file:///S:/b/u3/ " )
108-
109105 // ensure leading slash doesn't break everything
110106 let u5 = URL ( fileURLWithPath: " \\ abs \\ path " )
111107 XCTAssertEqual ( u5. absoluteString, " file:///abs/path " )
@@ -124,7 +120,7 @@ class TestURL : XCTestCase {
124120 func test_fileURLWithPath_relativeTo( ) {
125121 let homeDirectory = NSHomeDirectory ( )
126122 let homeURL = URL ( fileURLWithPath: homeDirectory, isDirectory: true )
127- XCTAssertEqual ( homeDirectory, homeURL. path )
123+ XCTAssertEqualFileSystemPaths ( homeDirectory, homeURL. withUnsafeFileSystemRepresentation { String ( cString : $0! ) } )
128124
129125 #if os(macOS)
130126 let baseURL = URL ( fileURLWithPath: homeDirectory, isDirectory: true )
@@ -411,25 +407,25 @@ class TestURL : XCTestCase {
411407 var path = TestURL . gFileExistsPath
412408 var url = NSURL ( fileURLWithPath: path)
413409 XCTAssertFalse ( url. hasDirectoryPath, " did not expect URL with directory path: \( url) " )
414- XCTAssertEqual ( path, url. path, " path from file path URL is wrong " )
410+ XCTAssertEqualFileSystemPaths ( path, url. path, " path from file path URL is wrong " )
415411
416412 // test with file that doesn't exist
417413 path = TestURL . gFileDoesNotExistPath
418414 url = NSURL ( fileURLWithPath: path)
419415 XCTAssertFalse ( url. hasDirectoryPath, " did not expect URL with directory path: \( url) " )
420- XCTAssertEqual ( path, url. path, " path from file path URL is wrong " )
416+ XCTAssertEqualFileSystemPaths ( path, url. path, " path from file path URL is wrong " )
421417
422418 // test with directory that exists
423419 path = TestURL . gDirectoryExistsPath
424420 url = NSURL ( fileURLWithPath: path)
425421 XCTAssertTrue ( url. hasDirectoryPath, " expected URL with directory path: \( url) " )
426- XCTAssertEqual ( path, url. path, " path from file path URL is wrong " )
422+ XCTAssertEqualFileSystemPaths ( path, url. path, " path from file path URL is wrong " )
427423
428424 // test with directory that doesn't exist
429425 path = TestURL . gDirectoryDoesNotExistPath
430426 url = NSURL ( fileURLWithPath: path)
431427 XCTAssertFalse ( url. hasDirectoryPath, " did not expect URL with directory path: \( url) " )
432- XCTAssertEqual ( path, url. path, " path from file path URL is wrong " )
428+ XCTAssertEqualFileSystemPaths ( path, url. path, " path from file path URL is wrong " )
433429
434430 // test with name relative to current working directory
435431 path = TestURL . gFileDoesNotExistName
@@ -473,31 +469,31 @@ class TestURL : XCTestCase {
473469 XCTAssertTrue ( url. hasDirectoryPath, " expected URL with directory path: \( url) " )
474470 url = NSURL ( fileURLWithPath: path, isDirectory: false )
475471 XCTAssertFalse ( url. hasDirectoryPath, " did not expect URL with directory path: \( url) " )
476- XCTAssertEqual ( path, url. path, " path from file path URL is wrong " )
472+ XCTAssertEqualFileSystemPaths ( path, url. path, " path from file path URL is wrong " )
477473
478474 // test with file that doesn't exist
479475 path = TestURL . gFileDoesNotExistPath
480476 url = NSURL ( fileURLWithPath: path, isDirectory: true )
481477 XCTAssertTrue ( url. hasDirectoryPath, " expected URL with directory path: \( url) " )
482478 url = NSURL ( fileURLWithPath: path, isDirectory: false )
483479 XCTAssertFalse ( url. hasDirectoryPath, " did not expect URL with directory path: \( url) " )
484- XCTAssertEqual ( path, url. path, " path from file path URL is wrong " )
480+ XCTAssertEqualFileSystemPaths ( path, url. path, " path from file path URL is wrong " )
485481
486482 // test with directory that exists
487483 path = TestURL . gDirectoryExistsPath
488484 url = NSURL ( fileURLWithPath: path, isDirectory: false )
489485 XCTAssertFalse ( url. hasDirectoryPath, " did not expect URL with directory path: \( url) " )
490486 url = NSURL ( fileURLWithPath: path, isDirectory: true )
491487 XCTAssertTrue ( url. hasDirectoryPath, " expected URL with directory path: \( url) " )
492- XCTAssertEqual ( path, url. path, " path from file path URL is wrong " )
488+ XCTAssertEqualFileSystemPaths ( path, url. path, " path from file path URL is wrong " )
493489
494490 // test with directory that doesn't exist
495491 path = TestURL . gDirectoryDoesNotExistPath
496492 url = NSURL ( fileURLWithPath: path, isDirectory: false )
497493 XCTAssertFalse ( url. hasDirectoryPath, " did not expect URL with directory path: \( url) " )
498494 url = NSURL ( fileURLWithPath: path, isDirectory: true )
499495 XCTAssertTrue ( url. hasDirectoryPath, " expected URL with directory path: \( url) " )
500- XCTAssertEqual ( path, url. path, " path from file path URL is wrong " )
496+ XCTAssertEqualFileSystemPaths ( path, url. path, " path from file path URL is wrong " )
501497
502498 // test with name relative to current working directory
503499 path = TestURL . gFileDoesNotExistName
0 commit comments