From ad0fc881354d4322ae1f8b61e806ee4e5fd39bc2 Mon Sep 17 00:00:00 2001 From: Michael Carroll Date: Thu, 3 Mar 2022 12:30:16 -0600 Subject: [PATCH] Add some tests for parentPath/basename (#309) Signed-off-by: Michael Carroll Signed-off-by: Louise Poubel Co-authored-by: Louise Poubel --- src/Filesystem_TEST.cc | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/src/Filesystem_TEST.cc b/src/Filesystem_TEST.cc index a193767f6..261621fd0 100644 --- a/src/Filesystem_TEST.cc +++ b/src/Filesystem_TEST.cc @@ -493,38 +493,71 @@ 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"); +#ifndef _WIN32 + EXPECT_EQ(parentPath(nobase), "baz/"); +#else + EXPECT_EQ(parentPath(nobase), "baz"); +#endif std::string multiple_slash = separator("baz") + separator("") + separator("") + separator(""); EXPECT_EQ(basename(multiple_slash), "baz"); +#ifndef _WIN32 + EXPECT_EQ(parentPath(multiple_slash), "baz//"); +#else + EXPECT_EQ(parentPath(multiple_slash), "baz\\\\"); +#endif std::string multiple_slash_middle = separator("") + separator("home") + separator("") + separator("") + separator("bob") + separator("foo"); EXPECT_EQ(basename(multiple_slash_middle), "foo"); +#ifndef _WIN32 + EXPECT_EQ(parentPath(multiple_slash_middle), "/home///bob"); +#else + EXPECT_EQ(parentPath(multiple_slash_middle), "\\home\\\\\\bob"); +#endif std::string multiple_slash_start = separator("") + separator("") + separator("") + separator("home") + separator("bob") + separator("foo"); EXPECT_EQ(basename(multiple_slash_start), "foo"); +#ifndef _WIN32 + EXPECT_EQ(parentPath(multiple_slash_start), "///home/bob"); +#else + EXPECT_EQ(parentPath(multiple_slash_start), "\\\\\\home\\bob"); +#endif 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("")); +#ifndef _WIN32 + EXPECT_EQ(parentPath(multiple_slash_only), "//"); +#else + EXPECT_EQ(parentPath(multiple_slash_only), "\\\\"); +#endif } /////////////////////////////////////////////////