Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Have != return true when compared to nil. Fixes #87 #88

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading