@@ -424,6 +424,14 @@ private struct StringTests {
424
424
#expect( " ///// " . lastPathComponent == " / " )
425
425
#expect( " /./..//./..// " . lastPathComponent == " .. " )
426
426
#expect( " /😎/😂/❤️/ " . lastPathComponent == " ❤️ " )
427
+
428
+ #expect( " /a/b/c " . lastPathComponent == " c " )
429
+ #expect( " /aaa " . lastPathComponent == " aaa " )
430
+ #expect( " /a/b/c/ " . lastPathComponent == " c " )
431
+ #expect( " hello " . lastPathComponent == " hello " )
432
+ #expect( " hello/ " . lastPathComponent == " hello " )
433
+ #expect( " hello/// " . lastPathComponent == " hello " )
434
+ #expect( " //a// " . lastPathComponent == " a " )
427
435
}
428
436
429
437
@Test func testRemovingDotSegments( ) {
@@ -893,6 +901,47 @@ private struct StringTests {
893
901
#expect( result == expected)
894
902
}
895
903
}
904
+
905
+ @Test func deletingLastPathComponent( ) {
906
+ #expect( " /a/b/c " . deletingLastPathComponent ( ) == " /a/b " )
907
+ #expect( " " . deletingLastPathComponent ( ) == " " )
908
+ #expect( " / " . deletingLastPathComponent ( ) == " / " )
909
+ #expect( " q " . deletingLastPathComponent ( ) == " " )
910
+ #expect( " /aaa " . deletingLastPathComponent ( ) == " / " )
911
+ #expect( " /aaa/ " . deletingLastPathComponent ( ) == " / " )
912
+ #expect( " /a/b/c/ " . deletingLastPathComponent ( ) == " /a/b " )
913
+ #expect( " hello " . deletingLastPathComponent ( ) == " " )
914
+ #expect( " hello/ " . deletingLastPathComponent ( ) == " " )
915
+ #expect( " /hello/ " . deletingLastPathComponent ( ) == " / " )
916
+ #expect( " hello/// " . deletingLastPathComponent ( ) == " " )
917
+ #expect( " a/ " . deletingLastPathComponent ( ) == " " )
918
+ #expect( " a/b " . deletingLastPathComponent ( ) == " a " )
919
+ #expect( " a/b/ " . deletingLastPathComponent ( ) == " a " )
920
+ #expect( " a//b// " . deletingLastPathComponent ( ) == " a " )
921
+ }
922
+
923
+ @Test func appendingPathComponent( ) {
924
+ let comp = " test "
925
+ #expect( " /a/b/c " . appendingPathComponent ( comp) == " /a/b/c/test " )
926
+ #expect( " " . appendingPathComponent ( comp) == " test " )
927
+ #expect( " / " . appendingPathComponent ( comp) == " /test " )
928
+ #expect( " q " . appendingPathComponent ( comp) == " q/test " )
929
+ #expect( " /aaa " . appendingPathComponent ( comp) == " /aaa/test " )
930
+ #expect( " /a/b/c/ " . appendingPathComponent ( comp) == " /a/b/c/test " )
931
+ #expect( " hello " . appendingPathComponent ( comp) == " hello/test " )
932
+ #expect( " hello/ " . appendingPathComponent ( comp) == " hello/test " )
933
+
934
+ #expect( " hello/ " . appendingPathComponent ( " /test " ) == " hello/test " )
935
+ #expect( " hello " . appendingPathComponent ( " /test " ) == " hello/test " )
936
+ #expect( " hello/// " . appendingPathComponent ( " ///test " ) == " hello/test " )
937
+ #expect( " hello " . appendingPathComponent ( " test/ " ) == " hello/test " )
938
+ #expect( " hello " . appendingPathComponent ( " test/test2 " ) == " hello/test/test2 " )
939
+ #expect( " hello " . appendingPathComponent ( " test/test2/ " ) == " hello/test/test2 " )
940
+ #expect( " hello " . appendingPathComponent ( " test///test2/ " ) == " hello/test/test2 " )
941
+ #expect( " hello " . appendingPathComponent ( " / " ) == " hello " )
942
+ #expect( " // " . appendingPathComponent ( " / " ) == " / " )
943
+ #expect( " " . appendingPathComponent ( " " ) == " " )
944
+ }
896
945
897
946
@Test func dataUsingEncoding( ) {
898
947
let s = " hello 🧮 "
0 commit comments