Skip to content

Commit

Permalink
Add path tests
Browse files Browse the repository at this point in the history
  • Loading branch information
electroly committed Feb 9, 2024
1 parent 0d46b14 commit f867cd1
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions src/test/PathTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

using shared::Error;
using shared::getDirectoryName;
using shared::getExtension;
using shared::getFileName;
using shared::getFileNameWithoutExtension;
using shared::pathCombine;

TEST(PathTest, GetDirectoryName_EmptyPath) {
std::string filePath = "";
Expand All @@ -26,6 +30,31 @@ TEST(PathTest, GetDirectoryName_MacOSBehavior) {
std::string expectedDir = "/path/to";
EXPECT_EQ(getDirectoryName(filePath), expectedDir);
}

TEST(PathTest, GetFileName_MacOSBehavior) {
std::string filePath = "/path/to/file.txt";
std::string expectedFile = "file.txt";
EXPECT_EQ(getFileName(filePath), expectedFile);
}

TEST(PathTest, GetFileNameWithoutExtension_MacOSBehavior) {
std::string filePath = "/path/to/file.txt";
std::string expectedFile = "file";
EXPECT_EQ(getFileNameWithoutExtension(filePath), expectedFile);
}

TEST(PathTest, GetExtension_MacOSBehavior) {
std::string filePath = "/path/to/file.txt";
std::string expectedFile = ".txt";
EXPECT_EQ(getExtension(filePath), expectedFile);
}

TEST(PathTest, PathCombine_MacOSBehavior) {
std::string a = "/path/to";
std::string b = "file.txt";
std::string expected = "/path/to/file.txt";
EXPECT_EQ(pathCombine(a, b), expected);
}
#endif

#ifdef _WIN32
Expand All @@ -35,6 +64,31 @@ TEST(PathTest, GetDirectoryName_WindowsBehavior) {
std::string expectedDir = "C:\\path\\to";
EXPECT_EQ(getDirectoryName(filePath), expectedDir);
}

TEST(PathTest, GetFileName_WindowsBehavior) {
std::string filePath = "C:\\path\\to\\file.txt";
std::string expectedFile = "file.txt";
EXPECT_EQ(getFileName(filePath), expectedFile);
}

TEST(PathTest, GetFileNameWithoutExtension_WindowsBehavior) {
std::string filePath = "C:\\path\\to\\file.txt";
std::string expectedFile = "file";
EXPECT_EQ(getFileNameWithoutExtension(filePath), expectedFile);
}

TEST(PathTest, GetExtension_WindowsBehavior) {
std::string filePath = "C:\\path\\to\\file.txt";
std::string expectedFile = ".txt";
EXPECT_EQ(getExtension(filePath), expectedFile);
}

TEST(PathTest, PathCombine_WindowsBehavior) {
std::string a = "C:\\path\\to";
std::string b = "file.txt";
std::string expected = "C:\\path\\to\\file.txt";
EXPECT_EQ(pathCombine(a, b), expected);
}
#endif

#ifdef __linux__
Expand All @@ -44,4 +98,29 @@ TEST(PathTest, GetDirectoryName_LinuxBehavior) {
std::string expectedDir = "/path/to";
EXPECT_EQ(getDirectoryName(filePath), expectedDir);
}

TEST(PathTest, GetFileName_LinuxBehavior) {
std::string filePath = "/path/to/file.txt";
std::string expectedFile = "file.txt";
EXPECT_EQ(getFileName(filePath), expectedFile);
}

TEST(PathTest, GetFileNameWithoutExtension_LinuxBehavior) {
std::string filePath = "/path/to/file.txt";
std::string expectedFile = "file";
EXPECT_EQ(getFileNameWithoutExtension(filePath), expectedFile);
}

TEST(PathTest, GetExtension_LinuxBehavior) {
std::string filePath = "/path/to/file.txt";
std::string expectedFile = ".txt";
EXPECT_EQ(getExtension(filePath), expectedFile);
}

TEST(PathTest, PathCombine_LinuxBehavior) {
std::string a = "/path/to";
std::string b = "file.txt";
std::string expected = "/path/to/file.txt";
EXPECT_EQ(pathCombine(a, b), expected);
}
#endif

0 comments on commit f867cd1

Please sign in to comment.