diff options
| author | Admiral H. Curtiss <pikachu025@gmail.com> | 2025-02-02 18:16:13 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-02 18:16:13 +0100 |
| commit | 5a4cde62b657ccab898c1e16d2e87ca35d4d6567 (patch) | |
| tree | ef273c37978fd035b444748b33f0c2bbd6586bca | |
| parent | f1fe32c93b95fbb6faff97f661985328c86a1c8c (diff) | |
| parent | e5e3944d55a74afcd3fffd5980710deea600c1ad (diff) | |
Merge pull request #13246 from nlebeck/stringutil-tests
Add a `SplitPath` unit test exercising Windows paths with drive letters
| -rw-r--r-- | Source/UnitTests/Common/StringUtilTest.cpp | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/Source/UnitTests/Common/StringUtilTest.cpp b/Source/UnitTests/Common/StringUtilTest.cpp index abf37be585..5c21610a13 100644 --- a/Source/UnitTests/Common/StringUtilTest.cpp +++ b/Source/UnitTests/Common/StringUtilTest.cpp @@ -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 |
