-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from jsixface/bug/NilStarSelect
Add validation for fields in where clauses.
- Loading branch information
Showing
3 changed files
with
78 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package runtime | ||
|
||
import ( | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/cloudson/gitql/parser" | ||
"github.com/cloudson/gitql/semantical" | ||
) | ||
|
||
func TestTestAllFieldsInExprBranches(t *testing.T) { | ||
query := "select * from branches where name = 'something' and somthing > 'name'" | ||
err := parseAndVisitQuery(query, "../", t) | ||
if err == nil { | ||
t.Error("Expected error, received none") | ||
} | ||
} | ||
|
||
func TestTestAllFieldsInExprRefs(t *testing.T) { | ||
query := "select * from refs where name = 'something' or type = 'asdfasdfsd'" | ||
err := parseAndVisitQuery(query, "../", t) | ||
if err != nil { | ||
t.Errorf("Unexpedted error %s", err) | ||
} | ||
} | ||
|
||
func TestTestAllFieldsInExprTags(t *testing.T) { | ||
query := "select * from tags where type = 'blah'" | ||
err := parseAndVisitQuery(query, "../", t) | ||
if err == nil { | ||
t.Errorf("Unexpedted error %s", err) | ||
} | ||
} | ||
|
||
func parseAndVisitQuery(query, dir string, t *testing.T) error { | ||
parser.New(query) | ||
ast, errGit := parser.AST() | ||
failTestIfError(errGit, t) | ||
|
||
folder, errFile := filepath.Abs(dir) | ||
failTestIfError(errFile, t) | ||
ast.Path = &folder | ||
errGit = semantical.Analysis(ast) | ||
failTestIfError(errGit, t) | ||
|
||
builder = GetGitBuilder(ast.Path) | ||
visitor := new(RuntimeVisitor) | ||
err := visitor.Visit(ast) | ||
return err | ||
} |