diff --git a/runtime/commits.go b/runtime/commits.go index b7c6e75..49eb163 100644 --- a/runtime/commits.go +++ b/runtime/commits.go @@ -55,10 +55,8 @@ func walkCommits(n *parser.NodeProgram, visitor *RuntimeVisitor) (*TableData, er if err != nil { return nil, err } - if usingOrder { - if counter > s.Limit { - counter = s.Limit - } + if usingOrder && counter > s.Limit { + counter = s.Limit rowsSliced = rowsSliced[0:counter] } tableData := new(TableData) diff --git a/runtime/reference.go b/runtime/reference.go index e82d977..e09fdbd 100644 --- a/runtime/reference.go +++ b/runtime/reference.go @@ -52,10 +52,8 @@ func walkReferences(n *parser.NodeProgram, visitor *RuntimeVisitor) (*TableData, if err != nil { return nil, err } - if usingOrder { - if counter > s.Limit { - counter = s.Limit - } + if usingOrder && counter > s.Limit { + counter = s.Limit rowsSliced = rowsSliced[0:counter] } tableData := new(TableData) diff --git a/runtime/remotes.go b/runtime/remotes.go index cdb6cf8..91c348c 100644 --- a/runtime/remotes.go +++ b/runtime/remotes.go @@ -54,10 +54,8 @@ func walkRemotes(n *parser.NodeProgram, visitor *RuntimeVisitor) (*TableData, er if err != nil { return nil, err } - if usingOrder { - if counter > s.Limit { - counter = s.Limit - } + if usingOrder && counter > s.Limit { + counter = s.Limit rowsSliced = rowsSliced[0:counter] } tableData := new(TableData) diff --git a/runtime/runtime_test.go b/runtime/runtime_test.go index fa54dd9..1e25cfa 100644 --- a/runtime/runtime_test.go +++ b/runtime/runtime_test.go @@ -104,3 +104,29 @@ func TestCanConvertToTypeFormats(t *testing.T) { typeFormat := "json" Run(ast, &typeFormat) } + +func TestNotFoundCommitWithInStatementAndSorting(t *testing.T) { + folder, errFile := filepath.Abs("../") + + if errFile != nil { + t.Errorf(errFile.Error()) + } + + query := "select author from commits where 'thisisnotfound' in hash order by date desc" + + parser.New(query) + ast, errGit := parser.AST() + if errGit != nil { + t.Errorf(errGit.Error()) + } + ast.Path = &folder + errGit = semantical.Analysis(ast) + if errGit != nil { + t.Errorf(errGit.Error()) + } + + typeFormat := "table" + if errGit = Run(ast, &typeFormat); errGit != nil { + t.Errorf(errGit.Error()) + } +}