summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Batischev <eual.jp@gmail.com>2023-12-29 07:03:47 +0300
committerAlexander Batischev <eual.jp@gmail.com>2024-10-01 19:12:44 +0300
commit550febac58230d84246770425e43cf7cf8387290 (patch)
treea27f2a4a03f4f75f4dae24e62fde52e8991e4722
parentff4d9aef61923382ba45f07b5e137c0de86f28ed (diff)
Add tests for Filepath::file_name()
-rw-r--r--test/filepath.cpp26
1 files changed, 25 insertions, 1 deletions
diff --git a/test/filepath.cpp b/test/filepath.cpp
index 6a67de75..ffa2ca70 100644
--- a/test/filepath.cpp
+++ b/test/filepath.cpp
@@ -126,7 +126,7 @@ TEST_CASE("Can check if path is absolute", "[Filepath]")
TEST_CASE("Can check if path starts with a given base path", "[Filepath]")
{
SECTION("Empty path") {
- Filepath path;
+ const Filepath path;
SECTION("Base path is empty") {
REQUIRE(path.starts_with(Filepath{}));
@@ -163,3 +163,27 @@ TEST_CASE("Can check if path starts with a given base path", "[Filepath]")
}
}
}
+
+TEST_CASE("Can extract the final component of the path (file or directory name)",
+ "[Filepath]")
+{
+ SECTION("Empty path has no final component") {
+ const Filepath path;
+ REQUIRE(path.file_name() == nonstd::nullopt);
+ }
+
+ SECTION("The final component of a path with single level is the path itself") {
+ const auto path = Filepath::from_locale_string("hello");
+ REQUIRE(path.file_name().value() == path);
+ }
+
+ SECTION("Multi-level path") {
+ const auto path = Filepath::from_locale_string("/dev/pts/0");
+ REQUIRE(path.file_name().value() == Filepath::from_locale_string("0"));
+ }
+
+ SECTION("Final component is not a valid UTF-8 string") {
+ const auto path = Filepath::from_locale_string("/whatever/one\x80two");
+ REQUIRE(path.file_name().value() == Filepath::from_locale_string("one\x80two"));
+ }
+}