@@ -1002,25 +1002,30 @@ class TestNSString: LoopbackServerTest {
1002
1002
}
1003
1003
1004
1004
func test_expandingTildeInPath( ) {
1005
+ // Android home directory is the root directory, so the result of ~ may
1006
+ // actually have a trailing path separator, but only if it is the root
1007
+ // directory itself.
1008
+ let rootDirectory = " / "
1009
+
1005
1010
do {
1006
1011
let path : NSString = " ~ "
1007
1012
let result = path. expandingTildeInPath
1008
1013
XCTAssert ( result == NSHomeDirectory ( ) , " Could resolve home directory for current user " )
1009
- XCTAssertFalse ( result. hasSuffix ( " / " ) , " Result have no trailing path separator " )
1014
+ XCTAssertFalse ( result. hasSuffix ( " / " ) && result != rootDirectory , " Result should not have a trailing path separator " )
1010
1015
}
1011
1016
1012
1017
do {
1013
1018
let path : NSString = " ~/ "
1014
1019
let result = path. expandingTildeInPath
1015
1020
XCTAssert ( result == NSHomeDirectory ( ) , " Could resolve home directory for current user " )
1016
- XCTAssertFalse ( result. hasSuffix ( " / " ) , " Result have no trailing path separator " )
1021
+ XCTAssertFalse ( result. hasSuffix ( " / " ) && result != rootDirectory , " Result should not have a trailing path separator " )
1017
1022
}
1018
1023
1019
1024
do {
1020
1025
let path = NSString ( string: " ~ \( NSUserName ( ) ) " )
1021
1026
let result = path. expandingTildeInPath
1022
1027
XCTAssert ( result == NSHomeDirectory ( ) , " Could resolve home directory for specific user " )
1023
- XCTAssertFalse ( result. hasSuffix ( " / " ) , " Result have no trailing path separator " )
1028
+ XCTAssertFalse ( result. hasSuffix ( " / " ) && result != rootDirectory , " Result should not have a trailing path separator " )
1024
1029
}
1025
1030
1026
1031
do {
@@ -1052,7 +1057,7 @@ class TestNSString: LoopbackServerTest {
1052
1057
do {
1053
1058
let path : NSString = " ~/foo/bar/ "
1054
1059
let result = path. standardizingPath
1055
- let expected = NSHomeDirectory ( ) + " / foo/bar"
1060
+ let expected = NSHomeDirectory ( ) . appendingPathComponent ( " foo/bar " )
1056
1061
XCTAssertEqual ( result, expected, " standardizingPath expanding initial tilde. " )
1057
1062
}
1058
1063
0 commit comments