mirror of
https://github.com/stenzek/duckstation.git
synced 2026-10-11 22:49:58 +00:00
INISettingsInterface: ClearSection() should not create an empty section
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user