7 #include <gtest/gtest.h>
13 TEST(FileTests, TestFilePathMethods)
17 EXPECT_EQ(f.
to_str(),
"/tmp/archive.tar.gz");
18 EXPECT_EQ(f.
name(),
"archive.tar.gz");
19 EXPECT_EQ(f.
base(),
"archive");
20 EXPECT_EQ(f.
suffix(),
"gz");
24 std::vector<std::pair<std::string, std::string>> pathPairs = { {
"/tmp/jlm/",
"/tmp" },
25 {
"/tmp/jlm",
"/tmp" },
28 {
"d/d2/file.txt",
"d/d2" },
30 {
"./test2.txt",
"." },
35 for (
const auto & [fullPath, path] : pathPairs)
38 EXPECT_EQ(result, path);
42 TEST(FileTests, TestCreateDirectory)
47 if (filePath.Exists())
49 EXPECT_FALSE(filePath.Exists());
52 filePath.CreateDirectory();
55 EXPECT_TRUE(filePath.Exists() && filePath.IsDirectory());
58 filePath.CreateDirectory();
68 TEST(FileTests, TestFilepathJoin)
76 EXPECT_EQ(path1.
Join(path2).
to_str(),
"tmp/a/b/");
77 EXPECT_EQ(path2.
Join(path1).
to_str(),
"a/b/tmp");
80 EXPECT_EQ(path3.
Join(path1).
to_str(),
"/c/d/tmp");
84 EXPECT_EQ(path1.
Join(path4).
to_str(),
"tmp/.");
85 EXPECT_EQ(path2.
Join(path4).
to_str(),
"a/b/.");
87 EXPECT_EQ(emptyPath.
Join(path1).
to_str(),
"tmp");
90 TEST(FileTests, TestCreateUniqueFileName)
100 EXPECT_EQ(filePath.Dirname(), tmpDirectory.to_str());
TEST(FileTests, TestFilePathMethods)
static FilePath createUniqueFileName(const FilePath &directory, const std::string &fileNamePrefix, const std::string &fileNameSuffix)
Generates a unique file in a given directory with a prefix and suffix.
std::string name() const noexcept
Returns the name of the file, excluding the path.
void CreateDirectory() const
static FilePath TempDirectoryPath()
std::string complete_suffix() const noexcept
Returns the complete suffix (extension) of the file.
const std::string & to_str() const noexcept
FilePath Join(const std::string &other) const
std::string base() const noexcept
Returns the base name of the file without the path.
FilePath Dirname() const noexcept
Returns the path to the file or directory's parent directory. Emulates the behavior of the GNU coreut...
std::string suffix() const noexcept
Returns the suffix (extension) of the file.
static void remove(Node *node)
std::string CreateRandomAlphanumericString(std::size_t length)