Skip to content

Commit d121864

Browse files
committed
Move string path tests from Data IO suite to String suite
1 parent fa740b3 commit d121864

File tree

2 files changed

+49
-56
lines changed

2 files changed

+49
-56
lines changed

Tests/FoundationEssentialsTests/DataIOTests.swift

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -217,61 +217,5 @@ private final class DataIOTests {
217217
let maps = try String(contentsOfFile: "/proc/self/maps", encoding: .utf8)
218218
#expect(!maps.isEmpty)
219219
}
220-
221-
// MARK: - String Path Tests
222-
// TODO: Move these to string tests
223-
@Test func stringDeletingLastPathComponent() {
224-
#expect("/a/b/c".deletingLastPathComponent() == "/a/b")
225-
#expect("".deletingLastPathComponent() == "")
226-
#expect("/".deletingLastPathComponent() == "/")
227-
#expect("q".deletingLastPathComponent() == "")
228-
#expect("/aaa".deletingLastPathComponent() == "/")
229-
#expect("/aaa/".deletingLastPathComponent() == "/")
230-
#expect("/a/b/c/".deletingLastPathComponent() == "/a/b")
231-
#expect("hello".deletingLastPathComponent() == "")
232-
#expect("hello/".deletingLastPathComponent() == "")
233-
#expect("/hello/".deletingLastPathComponent() == "/")
234-
#expect("hello///".deletingLastPathComponent() == "")
235-
#expect("a/".deletingLastPathComponent() == "")
236-
#expect("a/b".deletingLastPathComponent() == "a")
237-
#expect("a/b/".deletingLastPathComponent() == "a")
238-
#expect("a//b//".deletingLastPathComponent() == "a")
239-
}
240-
241-
@Test func appendingPathComponent() {
242-
let comp = "test"
243-
#expect("/a/b/c".appendingPathComponent(comp) == "/a/b/c/test")
244-
#expect("".appendingPathComponent(comp) == "test")
245-
#expect("/".appendingPathComponent(comp) == "/test")
246-
#expect("q".appendingPathComponent(comp) == "q/test")
247-
#expect("/aaa".appendingPathComponent(comp) == "/aaa/test")
248-
#expect("/a/b/c/".appendingPathComponent(comp) == "/a/b/c/test")
249-
#expect("hello".appendingPathComponent(comp) == "hello/test")
250-
#expect("hello/".appendingPathComponent(comp) == "hello/test")
251-
252-
#expect("hello/".appendingPathComponent("/test") == "hello/test")
253-
#expect("hello".appendingPathComponent("/test") == "hello/test")
254-
#expect("hello///".appendingPathComponent("///test") == "hello/test")
255-
#expect("hello".appendingPathComponent("test/") == "hello/test")
256-
#expect("hello".appendingPathComponent("test/test2") == "hello/test/test2")
257-
#expect("hello".appendingPathComponent("test/test2/") == "hello/test/test2")
258-
#expect("hello".appendingPathComponent("test///test2/") == "hello/test/test2")
259-
#expect("hello".appendingPathComponent("/") == "hello")
260-
#expect("//".appendingPathComponent("/") == "/")
261-
#expect("".appendingPathComponent("") == "")
262-
}
263-
264-
@Test func stringLastPathComponent() {
265-
#expect("/a/b/c".lastPathComponent == "c")
266-
#expect("".lastPathComponent == "")
267-
#expect("/".lastPathComponent == "/")
268-
#expect("q".lastPathComponent == "q")
269-
#expect("/aaa".lastPathComponent == "aaa")
270-
#expect("/a/b/c/".lastPathComponent == "c")
271-
#expect("hello".lastPathComponent == "hello")
272-
#expect("hello/".lastPathComponent == "hello")
273-
#expect("hello///".lastPathComponent == "hello")
274-
#expect("//a//".lastPathComponent == "a")
275-
}
276220
}
277221

Tests/FoundationEssentialsTests/StringTests.swift

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,14 @@ private struct StringTests {
424424
#expect("/////".lastPathComponent == "/")
425425
#expect("/./..//./..//".lastPathComponent == "..")
426426
#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")
427435
}
428436

429437
@Test func testRemovingDotSegments() {
@@ -893,6 +901,47 @@ private struct StringTests {
893901
#expect(result == expected)
894902
}
895903
}
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+
}
896945

897946
@Test func dataUsingEncoding() {
898947
let s = "hello 🧮"

0 commit comments

Comments
 (0)