Skip to content

Commit

Permalink
Add autocomplete + readme example for "distinct" (cleanups for issue #60
Browse files Browse the repository at this point in the history
) (#98)

* Add DISTINCT in autocomplete

* Simplify lexical test

* Add a test in semantical to ensure duplicate "distinct" is disallowed.

* Add a example for select distinct
  • Loading branch information
sesam authored Oct 10, 2020
1 parent a8735b9 commit 7962afd
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 23 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ As an example, this is the `commits` table:
* `select hash, message, author_email from commits where author = 'cloudson'`
* `select date, message from commits where date < '2014-04-10'`
* `select message from commits where 'hell' in message order by date asc`
* `select distinct author from commits where date < '2020-01-01'`

## Questions?

Expand Down
2 changes: 2 additions & 0 deletions autocomplete.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func suggestLatest(focused string, candidacies [][]string) [][]rune {
func containColumns(focused string) bool {
_, ok := isContained(focused, []string{
"select", // gitql> select [tab
"distinct,",
"name,",
"url,",
"push_url,",
Expand Down Expand Up @@ -72,6 +73,7 @@ func suggestQuery(inputs [][]rune, pos int) [][]rune {
// gitql> select [tab
// In the case where the most recent input is "select"
return [][]rune{
[]rune("distinct"),
[]rune("*"),
[]rune("name"),
[]rune("url"),
Expand Down
1 change: 1 addition & 0 deletions autocomplete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ func TestSuggestQuery(t *testing.T) {
[]rune(""),
}
assertSuggestsQuery(t, pattern2, []string{
"distinct",
"*",
"name",
"url",
Expand Down
28 changes: 5 additions & 23 deletions lexical/lexical_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,29 +135,11 @@ func TestReservedWords(t *testing.T) {

var token uint8

token, _ = Token()
assertToken(t, token, T_SELECT)

token, _ = Token()
assertToken(t, token, T_DISTINCT)

token, _ = Token()
assertToken(t, token, T_FROM)

token, _ = Token()
assertToken(t, token, T_WHERE)

token, _ = Token()
assertToken(t, token, T_IN)

token, _ = Token()
assertToken(t, token, T_NOT)

token, _ = Token()
assertToken(t, token, T_COUNT)

token, _ = Token()
assertToken(t, token, T_EOF)
tokens := []uint8{T_SELECT, T_DISTINCT, T_FROM, T_WHERE, T_IN, T_NOT, T_COUNT, T_EOF}
for i := range tokens {
token, _ = Token()
assertToken(t, token, tokens[i])
}
}

func TestNotReservedWords(t *testing.T) {
Expand Down
7 changes: 7 additions & 0 deletions semantical/semantical_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,14 @@ func TestSmallerWithDateWithoutTime(t *testing.T) {
if err != nil {
t.Fatalf(err.Error())
}
}

func TestRepeatedDistinct(t *testing.T) {
parser.New("select distinct distinct author from commits")
_, parserErr := parser.AST()
if parserErr == nil {
t.Fatalf(parserErr.Error())
}
}

// You should not test stupid things like "c" in "cloudson" or 1 = 1 ¬¬
Expand Down

0 comments on commit 7962afd

Please sign in to comment.