Skip to content

Commit

Permalink
handle negative comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
sidhant92 committed Aug 24, 2024
1 parent 99128b0 commit 5d02762
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/parser/antlr/custom_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func (l *CustomListener) ExitComparatorExpression(ctx *lib.ComparatorExpressionC

func (l *CustomListener) ExitUnaryArithmeticExpression(ctx *lib.UnaryArithmeticExpressionContext) {
var leafNode logical.Node
if len(l.Nodes) > 0 {
if len(l.Nodes) > 0 && reflect.TypeOf(l.Nodes[0]) == reflect.TypeOf(&arithmetic.ArithmeticNode{}) {
leafNode = l.pop()
} else {
leafNode = l.mapTypesExpressionContext(ctx.GetExp().(*lib.TypesExpressionContext))
Expand Down
9 changes: 9 additions & 0 deletions pkg/application/boolean_expression_evaluator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,15 @@ func TestDefaultFieldFalse(t *testing.T) {
assert.False(t, res)
}

func TestNegativeComparison(t *testing.T) {
data := map[string]interface{}{
"a": -6,
}
res, err := evaluator.Evaluate("a > -10 AND a < -2", data)
assert.Nil(t, err)
assert.True(t, res)
}

func TestContainsAnyTrueCondition(t *testing.T) {
data := map[string]interface{}{
"age": []int32{1, 2, 3},
Expand Down

0 comments on commit 5d02762

Please sign in to comment.