Skip to content

Commit

Permalink
Fix issue when two filter "excludes" have the same string length (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
DefaultRyan authored May 5, 2021
1 parent 49399fb commit 866c5f4
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/impl/winmd_reader/filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ namespace winmd::reader

std::sort(m_rules.begin(), m_rules.end(), [](auto const& lhs, auto const& rhs)
{
auto size_compare = int(lhs.first.size()) - int(rhs.first.size());
return (size_compare > 0) || ((size_compare == 0) && !lhs.second);
return std::pair{ lhs.first.size(), lhs.second } > std::pair{ rhs.first.size(), rhs.second };
});
}

Expand Down
40 changes: 40 additions & 0 deletions test/filter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include "pch.h"
#include <winmd_reader.h>

using namespace winmd::reader;

TEST_CASE("filter_simple")
{
std::vector<std::string> include = { "N1", "N3", "N3.N4.N5" };
std::vector<std::string> exclude = { "N2", "N3.N4" };

filter f{ include, exclude };

REQUIRE(!f.empty());

REQUIRE(!f.includes("NN.T"));

REQUIRE(f.includes("N1.T"));
REQUIRE(f.includes("N3.T"));

REQUIRE(!f.includes("N2.T"));
REQUIRE(!f.includes("N3.N4.T"));

REQUIRE(f.includes("N3.N4.N5.T"));
}

TEST_CASE("filter_excludes_same_length")
{
std::vector<std::string> include = { "N.N1", "N.N2" };
std::vector<std::string> exclude = { "N.N3", "N.N4" };

filter f{ include, exclude };

REQUIRE(!f.empty());

REQUIRE(f.includes("N.N1.T"));
REQUIRE(f.includes("N.N2.T"));

REQUIRE(!f.includes("N.N3.T"));
REQUIRE(!f.includes("N.N4.T"));
}
1 change: 1 addition & 0 deletions test/winmd.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<ItemGroup>
<ClCompile Include="cache.cpp" />
<ClCompile Include="database.cpp" />
<ClCompile Include="filter.cpp" />
<ClCompile Include="main.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
Expand Down

0 comments on commit 866c5f4

Please sign in to comment.