@@ -47,6 +47,60 @@ private func getTestData() -> [Any]? {
47
47
}
48
48
49
49
class TestURL : XCTestCase {
50
+ #if os(Windows)
51
+ func test_WindowsPathSeparator( ) {
52
+ // ensure that the mixed slashes are handled properly
53
+ // e.g. NOT file:///S:/b/u1%2/
54
+ let u1 = URL ( fileURLWithPath: " S: \\ b \\ u1/ " )
55
+ XCTAssertEqual ( u1. absoluteString, " file:///S:/b/u1/ " )
56
+
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/%2F/")
66
+ XCTAssertEqual ( u3. path, " S: \\ b \\ u3 \\ " )
67
+
68
+ // ensure that the regular conversion works
69
+ let u4 = URL ( fileURLWithPath: " S: \\ b \\ u4 " )
70
+ XCTAssertEqual ( u4. absoluteString, " file:///S:/b/u4 " )
71
+
72
+ // ensure that the trailing slash is added
73
+ let u5 = URL ( fileURLWithPath: " S: \\ b \\ u5 " , isDirectory: true )
74
+ XCTAssertEqual ( u5. absoluteString, " file:///S:/b/u5/ " )
75
+
76
+ // ensure that the trailing slash is preserved
77
+ let u6 = URL ( fileURLWithPath: " S: \\ b \\ u6 \\ " )
78
+ XCTAssertEqual ( u6. absoluteString, " file:///S:/b/u6/ " )
79
+
80
+ // ensure that we do not index beyond the start of the string
81
+ let u7 = URL ( fileURLWithPath: " eh " , relativeTo: URL ( fileURLWithPath: " S: \\ b " ) )
82
+ XCTAssertEqual ( u7. absoluteString, " file:///S:/b/eh " )
83
+
84
+ // ensure that / is handled properly
85
+ let u8 = URL ( fileURLWithPath: " / " )
86
+ XCTAssertEqual ( u8. absoluteString, " file:/// " )
87
+ }
88
+
89
+ func test_WindowsPathSeparator2( ) {
90
+ let u1 = URL ( fileURLWithPath: " S: \\ b \\ u1 \\ " , isDirectory: false )
91
+ XCTAssertEqual ( u1. absoluteString, " file:///S:/b/u1 " )
92
+
93
+ let u2 = URL ( fileURLWithPath: " / " , isDirectory: false )
94
+ XCTAssertEqual ( u2. absoluteString, " file:/// " )
95
+
96
+ let u3 = URL ( fileURLWithPath: " \\ " , isDirectory: false )
97
+ XCTAssertEqual ( u3. absoluteString, " file:/// " )
98
+
99
+ let u4 = URL ( fileURLWithPath: " S: \\ b \\ u3// \\ // " )
100
+ XCTAssertEqual ( u4. absoluteString, " file:///S:/b/u3/ " )
101
+ }
102
+ #endif
103
+
50
104
func test_fileURLWithPath_relativeTo( ) {
51
105
let homeDirectory = NSHomeDirectory ( )
52
106
let homeURL = URL ( fileURLWithPath: homeDirectory, isDirectory: true )
@@ -604,7 +658,7 @@ class TestURL : XCTestCase {
604
658
}
605
659
606
660
static var allTests : [ ( String , ( TestURL ) -> ( ) throws -> Void ) ] {
607
- return [
661
+ var tests : [ ( String , ( TestURL ) -> ( ) throws -> Void ) ] = [
608
662
( " test_URLStrings " , test_URLStrings) ,
609
663
( " test_fileURLWithPath_relativeTo " , test_fileURLWithPath_relativeTo ) ,
610
664
// TODO: these tests fail on linux, more investigation is needed
@@ -619,6 +673,15 @@ class TestURL : XCTestCase {
619
673
( " test_URLResourceValues " , testExpectedToFail ( test_URLResourceValues,
620
674
" test_URLResourceValues: Except for .nameKey, we have no testable attributes that work in the environment Swift CI uses, for now. SR-XXXX " ) ) ,
621
675
]
676
+
677
+ #if os(Windows)
678
+ tests. append ( contentsOf: [
679
+ ( " test_WindowsPathSeparator " , test_WindowsPathSeparator) ,
680
+ ( " test_WindowsPathSeparator2 " , test_WindowsPathSeparator2) ,
681
+ ] )
682
+ #endif
683
+
684
+ return tests
622
685
}
623
686
}
624
687
0 commit comments