diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e155ba..81b56af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,13 @@ # Changelog -### Unreleased +### 0.3.0 ~ 0.4.0 - 2018/Oct/4 -* List pending changes here. +* [BREAKING] Switch logic operators from & and | to && and || +* Add an annotation @filter-default-field + +### 0.2.0 - 2018/Oct/3 + +* Factor out filter hooks for better usability. ### 0.1.0 - 2018/Jul/18 diff --git a/README.md b/README.md index 3a32ea3..8e1366b 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ $ mycmd example p1 p2 --filter='color~=#^red.*#' The filter decides whether to include or exclude each **top-level element** based on the result of evaluating the provided expression on each element. - Nested data elements may be tested, e.g. via `attributes.color=red` -- Simple boolean logic may be used, e.g. `color=red&shape=round` +- Simple boolean logic may be used, e.g. `color=red&&shape=round` Parenthesis are not supported. diff --git a/VERSION b/VERSION index 746bd19..25a5afd 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.3.1-dev +0.4.0-dev diff --git a/src/Operators/LogicalAndOp.php b/src/Operators/LogicalAndOp.php index 7bb5d19..1023886 100644 --- a/src/Operators/LogicalAndOp.php +++ b/src/Operators/LogicalAndOp.php @@ -34,6 +34,6 @@ public function test(Data $row) */ public function __toString() { - return "{$this->lhs}&{$this->rhs}"; + return "{$this->lhs}&&{$this->rhs}"; } } diff --git a/src/Operators/LogicalOrOp.php b/src/Operators/LogicalOrOp.php index 63bd5e8..8c1d79c 100644 --- a/src/Operators/LogicalOrOp.php +++ b/src/Operators/LogicalOrOp.php @@ -34,6 +34,6 @@ public function test(Data $row) */ public function __toString() { - return "{$this->lhs}|{$this->rhs}"; + return "{$this->lhs}||{$this->rhs}"; } } diff --git a/tests/FactoryTest.php b/tests/FactoryTest.php index 2010d41..f1dd42f 100644 --- a/tests/FactoryTest.php +++ b/tests/FactoryTest.php @@ -33,19 +33,19 @@ public function testFactoryParsingValues() ['a!*=b', '!a*=b',], ['a!~=#b#', '!a~=#b#',], - ['a=b&c=d',], - ['a*=b|c=d',], - ['a~=#b#&c~=d',], - ['!a=b|!c=d',], - ['!a*=b&c*=d',], - ['!a~=#b#&c=d',], - ['a!=b&c!=d', '!a=b&!c=d',], - ['a!*=b|c!*=d', '!a*=b|!c*=d',], - ['a!~=#b#&c!~=#d#', '!a~=#b#&!c~=#d#',], - - ['a=b&c=d&e=f',], - ['a=b|c=d&e=f',], - ['a=b|c=d|e=f',], + ['a=b&&c=d',], + ['a*=b||c=d',], + ['a~=#b#&&c~=d',], + ['!a=b||!c=d',], + ['!a*=b&&c*=d',], + ['!a~=#b#&&c=d',], + ['a!=b&&c!=d', '!a=b&&!c=d',], + ['a!*=b||c!*=d', '!a*=b||!c*=d',], + ['a!~=#b#&&c!~=#d#', '!a~=#b#&&!c~=#d#',], + + ['a=b&&c=d&&e=f',], + ['a=b||c=d&&e=f',], + ['a=b||c=d||e=f',], ]; } @@ -100,16 +100,16 @@ public function testFactoryEvaluationValues() ['a.b~=#c#', ['a' => ['b' => 'abcd']], true,], ['a.b~=#c#', ['b' => ['b' => 'c']], false,], - ['a=b&c=d', ['a' => 'b', 'c' => 'd'], true,], - ['a=b&c=d', ['a' => 'b', 'c' => 'xd'], false,], - ['a=b|c=d', ['a' => 'b', 'c' => 'xd'], true,], + ['a=b&&c=d', ['a' => 'b', 'c' => 'd'], true,], + ['a=b&&c=d', ['a' => 'b', 'c' => 'xd'], false,], + ['a=b||c=d', ['a' => 'b', 'c' => 'xd'], true,], - ['a*=b&c*=d', ['a' => 'b', 'c' => 'd'], true,], - ['a*=b&c*=d', ['a' => 'b', 'c' => 'xd'], true,], - ['a*=b&c*=d', ['a' => 'b', 'c' => 'xy'], false,], - ['a*=b|c*=d', ['a' => 'b', 'c' => 'xd'], true,], - ['a*=b|c*=d', ['a' => 'xb', 'c' => 'xd'], true,], - ['a*=b|c*=d', ['a' => 'xy', 'c' => 'xy'], false,], + ['a*=b&&c*=d', ['a' => 'b', 'c' => 'd'], true,], + ['a*=b&&c*=d', ['a' => 'b', 'c' => 'xd'], true,], + ['a*=b&&c*=d', ['a' => 'b', 'c' => 'xy'], false,], + ['a*=b||c*=d', ['a' => 'b', 'c' => 'xd'], true,], + ['a*=b||c*=d', ['a' => 'xb', 'c' => 'xd'], true,], + ['a*=b||c*=d', ['a' => 'xy', 'c' => 'xy'], false,], ['a!=b', ['a' => 'b'], false,], ['a!=b', ['a' => 'abc'], true,], diff --git a/tests/FilterOutputDataTest.php b/tests/FilterOutputDataTest.php index 11ed08a..5ad683e 100644 --- a/tests/FilterOutputDataTest.php +++ b/tests/FilterOutputDataTest.php @@ -32,8 +32,8 @@ public function testFilterDataValues() return [ [$source, 'color=red', 'a', ], - [$source, 'color=blue|shape=triangular', 'b,c', ], - [$source, 'color=red&shape=square', '', ], + [$source, 'color=blue||shape=triangular', 'b,c', ], + [$source, 'color=red&&shape=square', '', ], ]; } diff --git a/tests/OpCommandsTest.php b/tests/OpCommandsTest.php index 12fab1f..a0731c8 100644 --- a/tests/OpCommandsTest.php +++ b/tests/OpCommandsTest.php @@ -53,13 +53,13 @@ public function exampleTestCommandParameters() ], [ - 'a=b&c=d|x=y', self::STATUS_OK, - 'parse', 'a=b&c=d|x=y', + 'a=b&&c=d||x=y', self::STATUS_OK, + 'parse', 'a=b&&c=d||x=y', ], [ 'Could not parse expression a', self::STATUS_ERROR, - 'parse', 'a&b', + 'parse', 'a&&b', ], [