This repository has been archived by the owner on Sep 2, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
parser: fix create table without name (#52)
* parser: fix create table without name #29 * test: negative test cases for parser #29 Co-authored-by: Tim Satke <[email protected]>
- Loading branch information
Showing
3 changed files
with
60 additions
and
0 deletions.
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
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) | ||
} |
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,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") | ||
}) | ||
} |
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