mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
Improve plugin equality operator.
Plugin objects would not match regex even though they may contain regex names, and it was possible for two non-equal regex names to match each other, which isn't desired.
This commit is contained in:
@@ -366,9 +366,13 @@ namespace loot {
|
||||
}
|
||||
|
||||
bool PluginMetadata::operator == (const PluginMetadata& rhs) const {
|
||||
return (boost::iequals(name, rhs.Name())
|
||||
|| (IsRegexPlugin() && regex_match(rhs.Name(), regex(name, regex::ECMAScript | regex::icase)))
|
||||
|| (rhs.IsRegexPlugin() && regex_match(name, regex(rhs.Name(), regex::ECMAScript | regex::icase))));
|
||||
if (IsRegexPlugin() == rhs.IsRegexPlugin())
|
||||
return boost::iequals(name, rhs.Name());
|
||||
|
||||
if (IsRegexPlugin())
|
||||
return regex_match(rhs.Name(), regex(name, regex::ECMAScript | regex::icase));
|
||||
else
|
||||
return regex_match(name, regex(rhs.Name(), regex::ECMAScript | regex::icase));
|
||||
}
|
||||
|
||||
bool PluginMetadata::operator != (const PluginMetadata& rhs) const {
|
||||
|
||||
@@ -158,7 +158,7 @@ namespace loot {
|
||||
}
|
||||
|
||||
bool Plugin::operator == (const Plugin& rhs) const {
|
||||
return boost::iequals(name, rhs.Name());
|
||||
return PluginMetadata(name) == PluginMetadata(rhs.Name());
|
||||
}
|
||||
|
||||
bool Plugin::operator != (const Plugin& rhs) const {
|
||||
|
||||
@@ -55,6 +55,21 @@ TEST_F(PluginMetadata, EqualityOperator) {
|
||||
pm2 = loot::PluginMetadata("Blan.\\.esm");
|
||||
EXPECT_TRUE(pm1 == pm2);
|
||||
EXPECT_TRUE(pm2 == pm1);
|
||||
|
||||
pm1 = loot::PluginMetadata("Blan.esm");
|
||||
pm2 = loot::PluginMetadata("Blan.\\.esm");
|
||||
EXPECT_FALSE(pm1 == pm2);
|
||||
EXPECT_FALSE(pm2 == pm1);
|
||||
|
||||
pm1 = loot::PluginMetadata("Blan.\\.esm");
|
||||
pm2 = loot::PluginMetadata("Blan.\\.esm");
|
||||
EXPECT_TRUE(pm1 == pm2);
|
||||
EXPECT_TRUE(pm2 == pm1);
|
||||
|
||||
pm1 = loot::PluginMetadata("Blan(k|p).esm");
|
||||
pm2 = loot::PluginMetadata("Blan.\\.esm");
|
||||
EXPECT_FALSE(pm1 == pm2);
|
||||
EXPECT_FALSE(pm2 == pm1);
|
||||
}
|
||||
|
||||
TEST_F(PluginMetadata, MergeMetadata) {
|
||||
|
||||
@@ -144,27 +144,73 @@ TEST_F(Plugin, IsActive) {
|
||||
TEST_F(Plugin, EqualityOperator) {
|
||||
loot::Plugin plugin1, plugin2;
|
||||
EXPECT_TRUE(plugin1 == plugin2);
|
||||
EXPECT_TRUE(plugin2 == plugin1);
|
||||
|
||||
plugin1 = loot::Plugin("Blank.esm");
|
||||
plugin2 = loot::Plugin("blank.esm");
|
||||
EXPECT_TRUE(plugin1 == plugin2);
|
||||
EXPECT_TRUE(plugin2 == plugin1);
|
||||
|
||||
plugin1 = loot::Plugin("Blank.esm");
|
||||
plugin2 = loot::Plugin("Blank.esp");
|
||||
EXPECT_FALSE(plugin1 == plugin2);
|
||||
EXPECT_FALSE(plugin2 == plugin1);
|
||||
|
||||
plugin1 = loot::Plugin("Blank.esm");
|
||||
plugin2 = loot::Plugin("Blan.\\.esm");
|
||||
EXPECT_TRUE(plugin1 == plugin2);
|
||||
EXPECT_TRUE(plugin2 == plugin1);
|
||||
|
||||
plugin1 = loot::Plugin("Blan.esm");
|
||||
plugin2 = loot::Plugin("Blan.\\.esm");
|
||||
EXPECT_FALSE(plugin1 == plugin2);
|
||||
EXPECT_FALSE(plugin2 == plugin1);
|
||||
|
||||
plugin1 = loot::Plugin("Blan.\\.esm");
|
||||
plugin2 = loot::Plugin("Blan.\\.esm");
|
||||
EXPECT_TRUE(plugin1 == plugin2);
|
||||
EXPECT_TRUE(plugin2 == plugin1);
|
||||
|
||||
plugin1 = loot::Plugin("Blan(k|p).esm");
|
||||
plugin2 = loot::Plugin("Blan.\\.esm");
|
||||
EXPECT_FALSE(plugin1 == plugin2);
|
||||
EXPECT_FALSE(plugin2 == plugin1);
|
||||
}
|
||||
|
||||
TEST_F(Plugin, InequalityOperator) {
|
||||
loot::Plugin plugin1, plugin2;
|
||||
EXPECT_FALSE(plugin1 != plugin2);
|
||||
EXPECT_FALSE(plugin2 != plugin1);
|
||||
|
||||
plugin1 = loot::Plugin("Blank.esm");
|
||||
plugin2 = loot::Plugin("blank.esm");
|
||||
EXPECT_FALSE(plugin1 != plugin2);
|
||||
EXPECT_FALSE(plugin2 != plugin1);
|
||||
|
||||
plugin1 = loot::Plugin("Blank.esm");
|
||||
plugin2 = loot::Plugin("Blank.esp");
|
||||
EXPECT_TRUE(plugin1 != plugin2);
|
||||
EXPECT_TRUE(plugin2 != plugin1);
|
||||
|
||||
plugin1 = loot::Plugin("Blank.esm");
|
||||
plugin2 = loot::Plugin("Blan.\\.esm");
|
||||
EXPECT_FALSE(plugin1 != plugin2);
|
||||
EXPECT_FALSE(plugin2 != plugin1);
|
||||
|
||||
plugin1 = loot::Plugin("Blan.esm");
|
||||
plugin2 = loot::Plugin("Blan.\\.esm");
|
||||
EXPECT_TRUE(plugin1 != plugin2);
|
||||
EXPECT_TRUE(plugin2 != plugin1);
|
||||
|
||||
plugin1 = loot::Plugin("Blan.\\.esm");
|
||||
plugin2 = loot::Plugin("Blan.\\.esm");
|
||||
EXPECT_FALSE(plugin1 != plugin2);
|
||||
EXPECT_FALSE(plugin2 != plugin1);
|
||||
|
||||
plugin1 = loot::Plugin("Blan(k|p).esm");
|
||||
plugin2 = loot::Plugin("Blan.\\.esm");
|
||||
EXPECT_TRUE(plugin1 != plugin2);
|
||||
EXPECT_TRUE(plugin2 != plugin1);
|
||||
}
|
||||
|
||||
TEST_F(Plugin, DoFormIDsOverlap) {
|
||||
|
||||
Reference in New Issue
Block a user