Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some tests for parentPath/basename #309

Merged
merged 6 commits into from
Mar 3, 2022
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/Filesystem_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -493,38 +493,51 @@ TEST_F(FilesystemTest, cwd_error)
}

/////////////////////////////////////////////////
TEST_F(FilesystemTest, basename)
TEST_F(FilesystemTest, decomposition)
{
std::string absolute = joinPaths("", "home", "bob", "foo");
EXPECT_EQ(basename(absolute), "foo");
#ifndef _WIN32
EXPECT_EQ(parentPath(absolute), "/home/bob");
#else
EXPECT_EQ(parentPath(absolute), "home\\bob");
#endif

std::string relative = joinPaths("baz", "foobar");
EXPECT_EQ(basename(relative), "foobar");
EXPECT_EQ(parentPath(relative), "baz");

std::string bname = "bzzz";
EXPECT_EQ(basename(bname), "bzzz");
EXPECT_EQ(parentPath(bname), "bzzz");

std::string nobase = joinPaths("baz", "");
EXPECT_EQ(basename(nobase), "baz");
EXPECT_EQ(parentPath(nobase), "baz/");

std::string multiple_slash = separator("baz") + separator("") + separator("")
+ separator("");
EXPECT_EQ(basename(multiple_slash), "baz");
EXPECT_EQ(parentPath(multiple_slash), "baz//");

std::string multiple_slash_middle = separator("") + separator("home")
+ separator("") + separator("") + separator("bob") + separator("foo");
EXPECT_EQ(basename(multiple_slash_middle), "foo");
EXPECT_EQ(parentPath(multiple_slash_middle), "/home///bob");

std::string multiple_slash_start = separator("") + separator("")
+ separator("") + separator("home") + separator("bob") + separator("foo");
EXPECT_EQ(basename(multiple_slash_start), "foo");
EXPECT_EQ(parentPath(multiple_slash_start), "///home/bob");

std::string slash_only = separator("") + separator("");
EXPECT_EQ(basename(slash_only), separator(""));
EXPECT_EQ(parentPath(slash_only), "");

std::string multiple_slash_only = separator("") + separator("")
+ separator("") + separator("");
EXPECT_EQ(basename(multiple_slash_only), separator(""));
EXPECT_EQ(parentPath(multiple_slash_only), "//");
}

/////////////////////////////////////////////////
Expand Down