INISettingsInterface: ClearSection() should not create an empty section

This commit is contained in:
Stenzek
2026-10-02 20:33:49 +10:00
parent 9d00d6b6e3
commit 4122fed9ad
2 changed files with 23 additions and 13 deletions
@@ -601,16 +601,31 @@ TEST(INISettingsInterface, ClearSection)
EXPECT_FALSE(si.ContainsValue("S", "b"));
auto kvlist = si.GetKeyValueList("S");
EXPECT_TRUE(kvlist.empty());
EXPECT_EQ(si.SaveToString(), "[S]\n");
EXPECT_TRUE(si.IsDirty());
}
TEST(INISettingsInterface, ClearSectionCreatesIfMissing)
TEST(INISettingsInterface, ClearSectionMissingFromEmptySettings)
{
INISettingsInterface si;
si.LoadFromString("");
si.ClearSection("NewSection");
EXPECT_EQ(si.SaveToString(), "");
EXPECT_FALSE(si.IsDirty());
}
TEST(INISettingsInterface, ClearSectionMissingPreservesContentsAndDirtyFlag)
{
INISettingsInterface si;
si.LoadFromString("[S]\nkey = value\n");
si.ClearSection("Missing");
EXPECT_EQ(si.SaveToString(), "[S]\nkey = value\n");
EXPECT_FALSE(si.IsDirty());
si.SetStringValue("S", "key", "changed");
si.ClearSection("Missing");
EXPECT_EQ(si.SaveToString(), "[S]\nkey = changed\n");
EXPECT_TRUE(si.IsDirty());
auto kvlist = si.GetKeyValueList("NewSection");
EXPECT_TRUE(kvlist.empty());
}
TEST(INISettingsInterface, RemoveSection)
+5 -10
View File
@@ -540,16 +540,11 @@ void INISettingsInterface::DeleteValue(const char* section, const char* key)
void INISettingsInterface::ClearSection(const char* section)
{
auto sit = FindSection(section);
if (sit != m_sections.end())
{
sit->entries.clear();
m_dirty = true;
}
else
{
GetOrCreateSection(section);
m_dirty = true;
}
if (sit == m_sections.end())
return;
sit->entries.clear();
m_dirty = true;
}
void INISettingsInterface::RemoveSection(const char* section)