Merge 653aec68afdcadaae9913d7baf79f738fac538d2 into 3ff51c3e80f2c2eb105d43ecb9acab9a62e01600

This commit is contained in:
Manikandan K S 2026-07-28 16:28:53 -04:00 committed by GitHub
commit bee4e54040
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 3 deletions

View File

@ -227,12 +227,12 @@ FilePath FilePath::RemoveFileName() const {
FilePath FilePath::MakeFileName(const FilePath& directory,
const FilePath& base_name, int number,
const char* extension) {
std::string base = base_name.IsEmpty() ? "file" : base_name.string();
std::string file;
if (number == 0) {
file = base_name.string() + "." + extension;
file = base + "." + extension;
} else {
file =
base_name.string() + "_" + StreamableToString(number) + "." + extension;
file = base + "_" + StreamableToString(number) + "." + extension;
}
return ConcatPaths(directory, FilePath(file));
}

View File

@ -274,6 +274,18 @@ TEST(MakeFileNameTest, GenerateWhenNumberIsNotZeroAndDirIsEmpty) {
EXPECT_EQ("bar_14.xml", actual.string());
}
TEST(MakeFileNameTest, GenerateWhenBaseNameEmpty) {
FilePath actual =
FilePath::MakeFileName(FilePath("foo"), FilePath(""), 0, "xml");
EXPECT_EQ("foo" GTEST_PATH_SEP_ "file.xml", actual.string());
}
TEST(MakeFileNameTest, GenerateWhenBaseNameEmptyNumberNonZero) {
FilePath actual =
FilePath::MakeFileName(FilePath("foo"), FilePath(""), 42, "xml");
EXPECT_EQ("foo" GTEST_PATH_SEP_ "file_42.xml", actual.string());
}
TEST(ConcatPathsTest, WorksWhenDirDoesNotEndWithPathSep) {
FilePath actual = FilePath::ConcatPaths(FilePath("foo"), FilePath("bar.xml"));
EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar.xml", actual.string());