UriUtilsTest: clean

This commit is contained in:
dece 2022-02-16 11:06:52 +01:00
parent fd5471b615
commit a76e84cf1d

View file

@ -45,39 +45,27 @@ class UriUtilsTest {
fun joinUrls() {
assertEquals(
"gemini://dece.space/some-file.gmi",
dev.lowrespalmtree.comet.utils.joinUrls("gemini://dece.space/", "some-file.gmi")
.toString()
joinUrls("gemini://dece.space/", "some-file.gmi").toString()
)
assertEquals(
"gemini://dece.space/some-file.gmi",
dev.lowrespalmtree.comet.utils.joinUrls("gemini://dece.space/", "./some-file.gmi")
.toString()
joinUrls("gemini://dece.space/", "./some-file.gmi").toString()
)
assertEquals(
"gemini://dece.space/some-file.gmi",
dev.lowrespalmtree.comet.utils.joinUrls("gemini://dece.space/dir1", "/some-file.gmi")
.toString()
joinUrls("gemini://dece.space/dir1", "/some-file.gmi").toString()
)
assertEquals(
"gemini://dece.space/dir1/other-file.gmi",
dev.lowrespalmtree.comet.utils.joinUrls(
"gemini://dece.space/dir1/file.gmi",
"other-file.gmi"
).toString()
joinUrls("gemini://dece.space/dir1/file.gmi", "other-file.gmi").toString()
)
assertEquals(
"gemini://dece.space/top-level.gmi",
dev.lowrespalmtree.comet.utils.joinUrls(
"gemini://dece.space/dir1/file.gmi",
"../top-level.gmi"
).toString()
joinUrls("gemini://dece.space/dir1/file.gmi", "../top-level.gmi").toString()
)
assertEquals(
"s://hard/test/b/d/a.gmi",
dev.lowrespalmtree.comet.utils.joinUrls(
"s://hard/dir/a",
"./../test/b/c/../d/e/f/../.././a.gmi"
).toString()
joinUrls("s://hard/dir/a", "./../test/b/c/../d/e/f/../.././a.gmi").toString()
)
}
@ -93,28 +81,28 @@ class UriUtilsTest {
Pair("mid/content=5/../6", "mid/6"),
Pair("../../../../g", "g")
).forEach { (path, expected) ->
assertEquals(expected, dev.lowrespalmtree.comet.utils.removeDotSegments(path))
assertEquals(expected, removeDotSegments(path))
}
}
@Test
fun removeLastSegment() {
assertEquals("", dev.lowrespalmtree.comet.utils.removeLastSegment(""))
assertEquals("", dev.lowrespalmtree.comet.utils.removeLastSegment("/"))
assertEquals("", dev.lowrespalmtree.comet.utils.removeLastSegment("/a"))
assertEquals("/a", dev.lowrespalmtree.comet.utils.removeLastSegment("/a/"))
assertEquals("/a", dev.lowrespalmtree.comet.utils.removeLastSegment("/a/b"))
assertEquals("/a/b/c", dev.lowrespalmtree.comet.utils.removeLastSegment("/a/b/c/d"))
assertEquals("//", dev.lowrespalmtree.comet.utils.removeLastSegment("///"))
assertEquals("", removeLastSegment(""))
assertEquals("", removeLastSegment("/"))
assertEquals("", removeLastSegment("/a"))
assertEquals("/a", removeLastSegment("/a/"))
assertEquals("/a", removeLastSegment("/a/b"))
assertEquals("/a/b/c", removeLastSegment("/a/b/c/d"))
assertEquals("//", removeLastSegment("///"))
}
@Test
fun popFirstSegment() {
assertEquals(Pair("", ""), dev.lowrespalmtree.comet.utils.popFirstSegment(""))
assertEquals(Pair("a", ""), dev.lowrespalmtree.comet.utils.popFirstSegment("a"))
assertEquals(Pair("/a", ""), dev.lowrespalmtree.comet.utils.popFirstSegment("/a"))
assertEquals(Pair("/a", "/"), dev.lowrespalmtree.comet.utils.popFirstSegment("/a/"))
assertEquals(Pair("/a", "/b"), dev.lowrespalmtree.comet.utils.popFirstSegment("/a/b"))
assertEquals(Pair("a", "/b"), dev.lowrespalmtree.comet.utils.popFirstSegment("a/b"))
assertEquals(Pair("", ""), popFirstSegment(""))
assertEquals(Pair("a", ""), popFirstSegment("a"))
assertEquals(Pair("/a", ""), popFirstSegment("/a"))
assertEquals(Pair("/a", "/"), popFirstSegment("/a/"))
assertEquals(Pair("/a", "/b"), popFirstSegment("/a/b"))
assertEquals(Pair("a", "/b"), popFirstSegment("a/b"))
}
}