From 780c30267e553a8a68eab2fda66bc9cecca219b0 Mon Sep 17 00:00:00 2001 From: Niel Lebeck Date: Fri, 27 Dec 2024 11:56:35 -0800 Subject: [PATCH] Add a SplitPath unit test exercising Windows paths with drive letters --- Source/UnitTests/Common/StringUtilTest.cpp | 35 +++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/Source/UnitTests/Common/StringUtilTest.cpp b/Source/UnitTests/Common/StringUtilTest.cpp index abf37be5855c..d73b29a1e45d 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:". +TEST(StringUtil, SplitPathWindowsPathWithDriveLetter) +{ + // Verify that on Windows, valid paths that include a drive letter and volume separator (e.g., + // "C:") parse correctly. +#ifdef _WIN32 + 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 +}