commit fabc210ac377fe171427af2a54e9063959a8fbd6
parent 04d8296a62a5a7c84e88ff9c32b16189eab6e3bc
Author: cfillion <cfillion@users.noreply.github.com>
Date: Sat, 3 Sep 2016 01:10:42 -0400
filter: improve behavior of NOT ( ) grouping
`NOT ( a b )` matches if the rows does not contain a AND b:
a b = false
a = true
b = true
(same as `NOT a OR NOT b`)
`NOT a NOT b` matches if the rows contains neither a or b:
a b = false
a = false
b = false
Diffstat:
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/filter.cpp b/src/filter.cpp
@@ -18,7 +18,6 @@
#include "filter.hpp"
#include <boost/algorithm/string.hpp>
-#include <unordered_set>
using namespace std;
@@ -158,15 +157,15 @@ void Filter::Group::push(const NodePtr &node)
bool Filter::Group::match(const vector<string> &rows) const
{
for(const NodePtr &node : m_nodes) {
- if(node->match(rows) ^ test(NotFlag)) {
+ if(node->match(rows)) {
if(m_type == MatchAny)
return true;
}
else if(m_type == MatchAll)
- return false;
+ return test(NotFlag);
}
- return m_type == MatchAll;
+ return m_type == MatchAll && !test(NotFlag);
}
Filter::Token::Token(const std::string &buf, int flags)
diff --git a/test/filter.cpp b/test/filter.cpp
@@ -273,8 +273,9 @@ TEST_CASE("AND grouping", M) {
f.set("NOT ( apple orange ) bacon");
REQUIRE(f.match({"bacon"}));
- REQUIRE_FALSE(f.match({"apple bacon"}));
- REQUIRE_FALSE(f.match({"orange bacon"}));
+ REQUIRE(f.match({"apple bacon"}));
+ REQUIRE(f.match({"orange bacon"}));
+ REQUIRE_FALSE(f.match({"apple bacon orange"}));
}
SECTION("NOT + AND + OR grouping") {