summaryrefslogtreecommitdiff
path: root/Source/UnitTests/Common/StringUtilTest.cpp
diff options
context:
space:
mode:
authorNiel Lebeck <niel.lebeck@gmail.com>2024-12-27 11:56:35 -0800
committerNiel Lebeck <niel.lebeck@gmail.com>2025-01-29 22:07:19 -0800
commite5e3944d55a74afcd3fffd5980710deea600c1ad (patch)
tree6c406c8341d3c6282f90f39278be8e7a08a82750 /Source/UnitTests/Common/StringUtilTest.cpp
parentb5a0d293ae60ff979961589bbfaa18dce0958cc8 (diff)
Add a SplitPath unit test exercising Windows paths with drive letters
Diffstat (limited to 'Source/UnitTests/Common/StringUtilTest.cpp')
-rw-r--r--Source/UnitTests/Common/StringUtilTest.cpp35
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