Skip to content

Commit

Permalink
Add not equals validation
Browse files Browse the repository at this point in the history
  • Loading branch information
jsixface committed Oct 29, 2017
1 parent 3618925 commit 38fcc29
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
3 changes: 3 additions & 0 deletions parser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ func (n *NodeEqual) LeftValue() NodeExpr {

// NOT EQUAL
func (n *NodeNotEqual) Assertion(lvalue string, rvalue string) bool {
if len(lvalue) == 40 {
return lvalue[0:len(rvalue)] != rvalue
}
return lvalue != rvalue
}

Expand Down
12 changes: 12 additions & 0 deletions runtime/commits_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package runtime

import (
"fmt"
"path/filepath"
"testing"

Expand Down Expand Up @@ -82,3 +83,14 @@ func TestSelectedFieldsCount(t *testing.T) {
t.Errorf("Selected 'author' and 'hash'. Got %v", table.fields)
}
}

func TestNotEqualsInWhere(t *testing.T) {
queryData := "select committer, hash from commits limit 1"
table := getTableForQuery(queryData, "../", t)
firstCommitter := table.rows[0]["committer"].(string)
query := fmt.Sprintf("select committer, hash from commits where committer != '%s' limit 1", firstCommitter)
table = getTableForQuery(query, "../", t)
if firstCommitter == table.rows[0]["committer"].(string) {
t.Errorf("Strill got the same committer as the first one. - %s", firstCommitter)
}
}
10 changes: 9 additions & 1 deletion runtime/visitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ func (v *RuntimeVisitor) VisitExpr(n parser.NodeExpr) error {
case reflect.TypeOf(new(parser.NodeIn)):
g := n.(*parser.NodeIn)
return v.VisitIn(g)

case reflect.TypeOf(new(parser.NodeNotEqual)):
g := n.(*parser.NodeNotEqual)
return v.VisitNotEqual(g)
}

return nil
Expand All @@ -101,7 +103,13 @@ func (v *RuntimeVisitor) VisitEqual(n *parser.NodeEqual) error {
lvalue := n.LeftValue().(*parser.NodeId).Value()
rvalue := n.RightValue().(*parser.NodeLiteral).Value()
boolRegister = n.Assertion(metadata(lvalue), rvalue)
return nil
}

func (v *RuntimeVisitor) VisitNotEqual(n *parser.NodeNotEqual) error {
lvalue := n.LeftValue().(*parser.NodeId).Value()
rvalue := n.RightValue().(*parser.NodeLiteral).Value()
boolRegister = n.Assertion(metadata(lvalue), rvalue)
return nil
}

Expand Down

0 comments on commit 38fcc29

Please sign in to comment.