Skip to content
This repository has been archived by the owner on Feb 7, 2018. It is now read-only.

Commit

Permalink
Fix FormID equality comparison
Browse files Browse the repository at this point in the history
Where one FormID's plugin is a substring of the other's.
  • Loading branch information
Ortham committed Nov 25, 2015
1 parent ff15dfa commit 187960e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 3 additions & 4 deletions include/libespm/FormId.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,9 @@ namespace libespm {
inline bool operator == (const FormId& rhs) const {
std::string rhsPluginName = rhs.getPluginName();

return objectIndex == rhs.getObjectIndex() && std::equal(begin(pluginName),
end(pluginName),
begin(rhs.getPluginName()),
[](char lhs, char rhs) {
return objectIndex == rhs.getObjectIndex()
&& pluginName.size() == rhs.getPluginName().size()
&& std::equal(begin(pluginName), end(pluginName), begin(rhs.getPluginName()), [](char lhs, char rhs) {
return tolower(lhs) == tolower(rhs);
});
}
Expand Down
7 changes: 7 additions & 0 deletions src/tests/FormIdTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ namespace libespm {
EXPECT_NE(formId, otherFormId);
}

TEST_F(FormIdTest, formIdsWithEqualModIndicesAndNoMastersAndDifferentParentPluginNamesShouldNotBeEqual) {
FormId formId(parentPluginName, std::vector<std::string>(), 0x01);
FormId otherFormId(parentPluginName + ".ghost", std::vector<std::string>(), 0x01);

EXPECT_NE(formId, otherFormId);
}

TEST_F(FormIdTest, identicalFormIdsShouldBeEqual) {
FormId formId(parentPluginName, masters, 0x01);
FormId otherFormId(parentPluginName, masters, 0x01);
Expand Down

0 comments on commit 187960e

Please sign in to comment.