Skip to content

Commit 5cf9ac5

Browse files
committed
fix negative comparison
1 parent 0bfe9d5 commit 5cf9ac5

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/main/java/com/github/sidhant92/boolparser/parser/antlr/BooleanFilterListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public void exitArithmeticExpression(BooleanExpressionParser.ArithmeticExpressio
6262

6363
@Override
6464
public void exitUnaryArithmeticExpression(BooleanExpressionParser.UnaryArithmeticExpressionContext ctx) {
65-
final Node leafNode = !currentNodes.isEmpty() ? currentNodes.pop() : mapTypesExpressionContext(
65+
final Node leafNode = !currentNodes.isEmpty() && currentNodes.peek() instanceof ArithmeticNode ? currentNodes.pop() : mapTypesExpressionContext(
6666
(BooleanExpressionParser.TypesExpressionContext) ctx.exp);
6767
currentNodes.add(ArithmeticNode.builder().left(leafNode).operator(Operator.UNARY).build());
6868
super.enterUnaryArithmeticExpression(ctx);

src/test/java/com/github/sidhant92/boolparser/application/BooleanExpressionEvaluatorTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,15 @@ public void testComparisonWithArithmeticFalseCondition1() {
587587
assertFalse(booleanOptional.get());
588588
}
589589

590+
@Test
591+
public void testNegativeComparison() {
592+
final Map<String, Object> data = new HashMap<>();
593+
data.put("a", -6);
594+
final Try<Boolean> resultOptional = booleanExpressionEvaluator.evaluate("a > -10 AND a < -2", data);
595+
assertTrue(resultOptional.isSuccess());
596+
assertEquals(resultOptional.get(), true);
597+
}
598+
590599
@Test
591600
public void testNullCheck() {
592601
final Map<String, Object> data = new HashMap<>();

0 commit comments

Comments
 (0)