Skip to content
This repository has been archived by the owner on Sep 2, 2022. It is now read-only.

Commit

Permalink
parser: fix create table without name (#52)
Browse files Browse the repository at this point in the history
* parser: fix create table without name #29

* test: negative test cases for parser #29 

Co-authored-by: Tim Satke <[email protected]>
  • Loading branch information
Shivam010 and tsatke authored Sep 23, 2020
1 parent 72f7cbb commit 404b9c9
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
31 changes: 31 additions & 0 deletions internal/parser/issue29_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package parser

import "testing"

func TestIssue29(t *testing.T) {
NegativeTest{
Name: "issue29",
Query: "CREATE TABLE(n,FOREIGN KEY()REFERENCES n ON DELETE CASCADE)",
}.Run(t)
}

func TestIssue29WithoutTableName(t *testing.T) {
NegativeTest{
Name: "issue29 without table name",
Query: "CREATE TABLE (foo)",
}.Run(t)
}

func TestIssue29WithNumericColumn(t *testing.T) {
NegativeTest{
Name: "issue29 with numeric column",
Query: "CREATE TABLE foo(1)",
}.Run(t)
}

func TestIssue29WithNumericTable(t *testing.T) {
NegativeTest{
Name: "issue29 with numeric column",
Query: "CREATE TABLE 1(foo)",
}.Run(t)
}
27 changes: 27 additions & 0 deletions internal/parser/negative_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package parser

import (
"github.com/stretchr/testify/assert"
"testing"
)

type NegativeTest struct {
Name string
Query string
}

func (nt NegativeTest) Run(t *testing.T) {
t.Helper()
t.Run(nt.Name, func(t *testing.T) {
assert := assert.New(t)

p, err := New(nt.Query)
assert.NoError(err)
_, errs, ok := p.Next()
assert.True(ok, "expected exactly one statement")
assert.NotEmpty(errs, "expected errors")

_, _, ok = p.Next()
assert.False(ok, "expected only one statement")
})
}
2 changes: 2 additions & 0 deletions internal/parser/simple_parser_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -2532,6 +2532,8 @@ func (p *simpleParser) parseCreateTableStmt(createToken, tempToken, temporaryTok
stmt.SchemaName = next
stmt.TableName = next
p.consumeToken()
} else {
r.unexpectedToken(token.Literal)
}

next, ok = p.lookahead(r)
Expand Down

0 comments on commit 404b9c9

Please sign in to comment.