Skip to content

Commit

Permalink
Add a SplitPath unit test exercising Windows paths with drive letters
Browse files Browse the repository at this point in the history
  • Loading branch information
nlebeck committed Dec 27, 2024
1 parent 05cad38 commit bf3ef37
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion Source/UnitTests/Common/StringUtilTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,37 @@ TEST(StringUtil, SplitPathBackslashesNotRecognizedAsSeparators)
EXPECT_EQ(extension, ".txt");
}

// TODO: add `SplitPath` test coverage for paths containing Windows drives, e.g., "C:".
#ifdef _WIN32
TEST(StringUtil, SplitPathWindowsPathWithDriveLetter)
{
// Verify that on Windows, valid paths that include a drive letter and volume separator (e.g.,
// "C:") parse correctly.
std::string path;
std::string filename;
std::string extension;

// Absolute path with drive letter
EXPECT_TRUE(SplitPath("C:/dir/some_file.txt", &path, &filename, &extension));
EXPECT_EQ(path, "C:/dir/");
EXPECT_EQ(filename, "some_file");
EXPECT_EQ(extension, ".txt");

// Relative path with drive letter
EXPECT_TRUE(SplitPath("C:dir/some_file.txt", &path, &filename, &extension));
EXPECT_EQ(path, "C:dir/");
EXPECT_EQ(filename, "some_file");
EXPECT_EQ(extension, ".txt");

// Relative path with drive letter and no directory
EXPECT_TRUE(SplitPath("C:some_file.txt", &path, &filename, &extension));
EXPECT_EQ(path, "C:");
EXPECT_EQ(filename, "some_file");
EXPECT_EQ(extension, ".txt");

// Path that is just the drive letter
EXPECT_TRUE(SplitPath("C:", &path, &filename, &extension));
EXPECT_EQ(path, "C:");
EXPECT_EQ(filename, "");
EXPECT_EQ(extension, "");
}
#endif

0 comments on commit bf3ef37

Please sign in to comment.