diff options
author | Michael Muré <batolettre@gmail.com> | 2020-03-22 13:53:34 +0100 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2020-03-28 17:13:28 +0100 |
commit | 314fcbb2293d869c33d6a76aedd148aedff6561d (patch) | |
tree | 05386ddf08d7e1c2947a6fc6cf2fbd44efa19eaf /query | |
parent | 5e4dc87ffec7f87bbf3ebfcf256777ad773e8450 (diff) | |
download | git-bug-314fcbb2293d869c33d6a76aedd148aedff6561d.tar.gz |
query: no need for an ast package
Diffstat (limited to 'query')
-rw-r--r-- | query/parser.go | 35 | ||||
-rw-r--r-- | query/parser_test.go | 59 | ||||
-rw-r--r-- | query/query.go (renamed from query/ast/ast.go) | 6 |
3 files changed, 51 insertions, 49 deletions
diff --git a/query/parser.go b/query/parser.go index 89893b60..a379f750 100644 --- a/query/parser.go +++ b/query/parser.go @@ -4,7 +4,6 @@ import ( "fmt" "github.com/MichaelMure/git-bug/bug" - "github.com/MichaelMure/git-bug/query/ast" ) // Parse parse a query DSL @@ -12,15 +11,15 @@ import ( // Ex: "status:open author:descartes sort:edit-asc" // // Supported filter qualifiers and syntax are described in docs/queries.md -func Parse(query string) (*ast.Query, error) { +func Parse(query string) (*Query, error) { tokens, err := tokenize(query) if err != nil { return nil, err } - q := &ast.Query{ - OrderBy: ast.OrderByCreation, - OrderDirection: ast.OrderDescending, + q := &Query{ + OrderBy: OrderByCreation, + OrderDirection: OrderDescending, } sortingDone := false @@ -66,31 +65,31 @@ func Parse(query string) (*ast.Query, error) { return q, nil } -func parseSorting(q *ast.Query, value string) error { +func parseSorting(q *Query, value string) error { switch value { // default ASC case "id-desc": - q.OrderBy = ast.OrderById - q.OrderDirection = ast.OrderDescending + q.OrderBy = OrderById + q.OrderDirection = OrderDescending case "id", "id-asc": - q.OrderBy = ast.OrderById - q.OrderDirection = ast.OrderAscending + q.OrderBy = OrderById + q.OrderDirection = OrderAscending // default DESC case "creation", "creation-desc": - q.OrderBy = ast.OrderByCreation - q.OrderDirection = ast.OrderDescending + q.OrderBy = OrderByCreation + q.OrderDirection = OrderDescending case "creation-asc": - q.OrderBy = ast.OrderByCreation - q.OrderDirection = ast.OrderAscending + q.OrderBy = OrderByCreation + q.OrderDirection = OrderAscending // default DESC case "edit", "edit-desc": - q.OrderBy = ast.OrderByEdit - q.OrderDirection = ast.OrderDescending + q.OrderBy = OrderByEdit + q.OrderDirection = OrderDescending case "edit-asc": - q.OrderBy = ast.OrderByEdit - q.OrderDirection = ast.OrderAscending + q.OrderBy = OrderByEdit + q.OrderDirection = OrderAscending default: return fmt.Errorf("unknown sorting %s", value) diff --git a/query/parser_test.go b/query/parser_test.go index 065e647a..6a509adb 100644 --- a/query/parser_test.go +++ b/query/parser_test.go @@ -6,73 +6,72 @@ import ( "github.com/stretchr/testify/assert" "github.com/MichaelMure/git-bug/bug" - "github.com/MichaelMure/git-bug/query/ast" ) func TestParse(t *testing.T) { var tests = []struct { input string - output *ast.Query + output *Query }{ {"gibberish", nil}, {"status:", nil}, {":value", nil}, - {"status:open", &ast.Query{ - Filters: ast.Filters{Status: []bug.Status{bug.OpenStatus}}, + {"status:open", &Query{ + Filters: Filters{Status: []bug.Status{bug.OpenStatus}}, }}, - {"status:closed", &ast.Query{ - Filters: ast.Filters{Status: []bug.Status{bug.ClosedStatus}}, + {"status:closed", &Query{ + Filters: Filters{Status: []bug.Status{bug.ClosedStatus}}, }}, {"status:unknown", nil}, - {"author:rene", &ast.Query{ - Filters: ast.Filters{Author: []string{"rene"}}, + {"author:rene", &Query{ + Filters: Filters{Author: []string{"rene"}}, }}, - {`author:"René Descartes"`, &ast.Query{ - Filters: ast.Filters{Author: []string{"René Descartes"}}, + {`author:"René Descartes"`, &Query{ + Filters: Filters{Author: []string{"René Descartes"}}, }}, - {"actor:bernhard", &ast.Query{ - Filters: ast.Filters{Actor: []string{"bernhard"}}, + {"actor:bernhard", &Query{ + Filters: Filters{Actor: []string{"bernhard"}}, }}, - {"participant:leonhard", &ast.Query{ - Filters: ast.Filters{Participant: []string{"leonhard"}}, + {"participant:leonhard", &Query{ + Filters: Filters{Participant: []string{"leonhard"}}, }}, - {"label:hello", &ast.Query{ - Filters: ast.Filters{Label: []string{"hello"}}, + {"label:hello", &Query{ + Filters: Filters{Label: []string{"hello"}}, }}, - {`label:"Good first issue"`, &ast.Query{ - Filters: ast.Filters{Label: []string{"Good first issue"}}, + {`label:"Good first issue"`, &Query{ + Filters: Filters{Label: []string{"Good first issue"}}, }}, - {"title:titleOne", &ast.Query{ - Filters: ast.Filters{Title: []string{"titleOne"}}, + {"title:titleOne", &Query{ + Filters: Filters{Title: []string{"titleOne"}}, }}, - {`title:"Bug titleTwo"`, &ast.Query{ - Filters: ast.Filters{Title: []string{"Bug titleTwo"}}, + {`title:"Bug titleTwo"`, &Query{ + Filters: Filters{Title: []string{"Bug titleTwo"}}, }}, - {"no:label", &ast.Query{ - Filters: ast.Filters{NoLabel: true}, + {"no:label", &Query{ + Filters: Filters{NoLabel: true}, }}, - {"sort:edit", &ast.Query{ - OrderBy: ast.OrderByEdit, + {"sort:edit", &Query{ + OrderBy: OrderByEdit, }}, {"sort:unknown", nil}, {`status:open author:"René Descartes" participant:leonhard label:hello label:"Good first issue" sort:edit-desc`, - &ast.Query{ - Filters: ast.Filters{ + &Query{ + Filters: Filters{ Status: []bug.Status{bug.OpenStatus}, Author: []string{"René Descartes"}, Participant: []string{"leonhard"}, Label: []string{"hello", "Good first issue"}, }, - OrderBy: ast.OrderByEdit, - OrderDirection: ast.OrderDescending, + OrderBy: OrderByEdit, + OrderDirection: OrderDescending, }, }, } diff --git a/query/ast/ast.go b/query/query.go index fe77abf9..a499ad38 100644 --- a/query/ast/ast.go +++ b/query/query.go @@ -1,7 +1,11 @@ -package ast +package query import "github.com/MichaelMure/git-bug/bug" +// Query is the intermediary representation of a Bug's query. It is either +// produced by parsing a query string (ex: "status:open author:rene") or created +// manually. This query doesn't do anything by itself and need to be interpreted +// for the specific domain of application. type Query struct { Filters OrderBy |