@@ -81,6 +81,8 @@ class TestNSString : XCTestCase {
81
81
( " test_stringByExpandingTildeInPath " , test_stringByExpandingTildeInPath) ,
82
82
( " test_stringByStandardizingPath " , test_stringByStandardizingPath) ,
83
83
( " test_stringByRemovingPercentEncoding " , test_stringByRemovingPercentEncoding) ,
84
+ ( " test_stringByAppendingPathExtension " , test_stringByAppendingPathExtension) ,
85
+ ( " test_stringByDeletingPathExtension " , test_stringByDeletingPathExtension) ,
84
86
( " test_ExternalRepresentation " , test_ExternalRepresentation) ,
85
87
( " test_mutableStringConstructor " , test_mutableStringConstructor) ,
86
88
( " test_PrefixSuffix " , test_PrefixSuffix) ,
@@ -836,6 +838,36 @@ class TestNSString : XCTestCase {
836
838
XCTAssertNil ( s2, " returns nil for a string with an invalid percent encoding " )
837
839
}
838
840
841
+ func test_stringByAppendingPathExtension( ) {
842
+ let values : Dictionary = [
843
+ NSString ( string: " /tmp/scratch.old " ) : " /tmp/scratch.old.tiff " ,
844
+ NSString ( string: " /tmp/scratch. " ) : " /tmp/scratch..tiff " ,
845
+ NSString ( string: " /tmp/ " ) : " /tmp.tiff " ,
846
+ NSString ( string: " /scratch " ) : " /scratch.tiff " ,
847
+ NSString ( string: " /~scratch " ) : " /~scratch.tiff " ,
848
+ NSString ( string: " scratch " ) : " scratch.tiff " ,
849
+ ]
850
+ for (fileName, expectedResult) in values {
851
+ let result = fileName. stringByAppendingPathExtension ( " tiff " )
852
+ XCTAssertEqual ( result, expectedResult, " expected \( expectedResult) for \( fileName) but got \( result) " )
853
+ }
854
+ }
855
+
856
+ func test_stringByDeletingPathExtension( ) {
857
+ let values : Dictionary = [
858
+ NSString ( string: " /tmp/scratch.tiff " ) : " /tmp/scratch " ,
859
+ NSString ( string: " /tmp/ " ) : " /tmp " ,
860
+ NSString ( string: " scratch.bundle " ) : " scratch " ,
861
+ NSString ( string: " scratch..tiff " ) : " scratch. " ,
862
+ NSString ( string: " .tiff " ) : " .tiff " ,
863
+ NSString ( string: " / " ) : " / " ,
864
+ ]
865
+ for (fileName, expectedResult) in values {
866
+ let result = fileName. stringByDeletingPathExtension
867
+ XCTAssertEqual ( result, expectedResult, " expected \( expectedResult) for \( fileName) but got \( result) " )
868
+ }
869
+ }
870
+
839
871
func test_ExternalRepresentation( ) {
840
872
// Ensure NSString can be used to create an external data representation
841
873
0 commit comments