Skip to content

Commit

Permalink
Have != return true when compared to nil. Fixes #87
Browse files Browse the repository at this point in the history
  • Loading branch information
plorenz committed Nov 19, 2024
1 parent 7d0ccd2 commit bf5bd4f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
9 changes: 9 additions & 0 deletions ast/bolt_listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ func (symbols *testSymbols) EvalBool(name string) *bool {

func (symbols *testSymbols) EvalString(name string) *string {
value := symbols.getValue(name)
if value == nil {
return nil
}
typedVal, ok := value.(string)
if ok {
return &typedVal
Expand Down Expand Up @@ -452,6 +455,12 @@ func TestStringFilters(t *testing.T) {
{"string not contains, result true", `sn not contains 321`, true},
{"string not contains, result true", `sn not contains 321.123`, true},

// nil tests
{"string is null, result true", `n = null`, true},
{"string is not null, result false", `n != null`, false},
{"null string equal to value, result false", `n = "foo"`, false},
{"null string not equal to value, result true", `n != "foo"`, true},

/*
{"string LT, result true", `s < "jello"`, true},.
{"string LT, result false", `s < "cello"`, false},
Expand Down
15 changes: 15 additions & 0 deletions ast/node_expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ func (node *BinaryDatetimeExprNode) EvalBool(s Symbols) bool {
rightResult := node.right.EvalDatetime(s)

if leftResult == nil || rightResult == nil {
if node.op == BinaryOpNEQ {
return leftResult != rightResult
}
return false
}

Expand Down Expand Up @@ -254,6 +257,9 @@ func (node *BinaryFloat64ExprNode) EvalBool(s Symbols) bool {
rightResult := node.right.EvalFloat64(s)

if leftResult == nil || rightResult == nil {
if node.op == BinaryOpNEQ {
return leftResult != rightResult
}
return false
}

Expand Down Expand Up @@ -306,6 +312,9 @@ func (node *BinaryInt64ExprNode) EvalBool(s Symbols) bool {
rightResult := node.right.EvalInt64(s)

if leftResult == nil || rightResult == nil {
if node.op == BinaryOpNEQ {
return leftResult != rightResult
}
return false
}

Expand Down Expand Up @@ -373,6 +382,12 @@ func (node *BinaryStringExprNode) EvalBool(s Symbols) bool {
rightResult := node.right.EvalString(s)

if leftResult == nil || rightResult == nil {
if node.op == BinaryOpNEQ {
return leftResult != rightResult
}
if node.op == BinaryOpNotContains || node.op == BinaryOpNotIContains {
return true
}
return false
}

Expand Down

0 comments on commit bf5bd4f

Please sign in to comment.