Skip to content

Commit

Permalink
Add tests for Filepath::file_name()
Browse files Browse the repository at this point in the history
  • Loading branch information
Minoru committed Dec 29, 2023
1 parent 98db50e commit 0f1b160
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion test/filepath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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{}));
Expand Down Expand Up @@ -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"));
}
}

0 comments on commit 0f1b160

Please sign in to comment.