Skip to content

Commit dd1aa90

Browse files
committed
(137600784) Guard old behavior in URL tests
1 parent 002921d commit dd1aa90

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

Tests/FoundationEssentialsTests/URLTests.swift

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -640,22 +640,30 @@ final class URLTests : XCTestCase {
640640
}
641641

642642
func testURLTildeFilePath() throws {
643-
var url = URL(filePath: "~")
643+
func urlIsAbsolute(_ url: URL) -> Bool {
644+
if url.relativePath.utf8.first == ._slash {
645+
return true
646+
}
647+
guard url.baseURL != nil else {
648+
return false
649+
}
650+
#if !FOUNDATION_FRAMEWORK_NSURL
651+
return url.path().utf8.first == ._slash
652+
#else
653+
return url.path.utf8.first == ._slash
654+
#endif
655+
}
656+
644657
// "~" must either be expanded to an absolute path or resolved against a base URL
645-
XCTAssertTrue(
646-
url.relativePath.utf8.first == ._slash || (url.baseURL != nil && url.path().utf8.first == ._slash)
647-
)
658+
var url = URL(filePath: "~")
659+
XCTAssertTrue(urlIsAbsolute(url))
648660

649661
url = URL(filePath: "~", directoryHint: .isDirectory)
650-
XCTAssertTrue(
651-
url.relativePath.utf8.first == ._slash || (url.baseURL != nil && url.path().utf8.first == ._slash)
652-
)
662+
XCTAssertTrue(urlIsAbsolute(url))
653663
XCTAssertEqual(url.path().utf8.last, ._slash)
654664

655665
url = URL(filePath: "~/")
656-
XCTAssertTrue(
657-
url.relativePath.utf8.first == ._slash || (url.baseURL != nil && url.path().utf8.first == ._slash)
658-
)
666+
XCTAssertTrue(urlIsAbsolute(url))
659667
XCTAssertEqual(url.path().utf8.last, ._slash)
660668
}
661669

@@ -677,7 +685,12 @@ final class URLTests : XCTestCase {
677685
XCTAssertEqual(url.path(), "/path.foo/")
678686
url.append(path: "/////")
679687
url.deletePathExtension()
688+
#if !FOUNDATION_FRAMEWORK_NSURL
680689
XCTAssertEqual(url.path(), "/path/")
690+
#else
691+
// Old behavior only searches the last empty component, so the extension isn't actually removed
692+
XCTAssertEqual(url.path(), "/path.foo///")
693+
#endif
681694
}
682695

683696
func testURLComponentsPercentEncodedUnencodedProperties() throws {

0 commit comments

Comments
 (0)