From 50e220acef0e2e1796e2814c4f4db81cb46e8ada Mon Sep 17 00:00:00 2001 From: ginokent <29125616+ginokent@users.noreply.github.com> Date: Wed, 14 Aug 2024 20:45:54 +0900 Subject: [PATCH 1/4] refactor: Provide more detailed error information --- pkg/ddl/cockroachdb/parser.go | 12 ++++++++++-- pkg/ddl/mysql/parser.go | 12 ++++++++++-- pkg/ddl/postgres/parser.go | 12 ++++++++++-- pkg/ddl/spanner/parser.go | 12 ++++++++++-- 4 files changed, 40 insertions(+), 8 deletions(-) diff --git a/pkg/ddl/cockroachdb/parser.go b/pkg/ddl/cockroachdb/parser.go index bbc50f7..4f2437c 100644 --- a/pkg/ddl/cockroachdb/parser.go +++ b/pkg/ddl/cockroachdb/parser.go @@ -107,9 +107,17 @@ func (p *Parser) parseCreateStatement() (Stmt, error) { //nolint:ireturn switch p.currentToken.Type { //nolint:exhaustive case TOKEN_TABLE: - return p.parseCreateTableStmt() + stmt, err := p.parseCreateTableStmt() + if err != nil { + return nil, apperr.Errorf("parseCreateTableStmt: %w", err) + } + return stmt, nil case TOKEN_INDEX, TOKEN_UNIQUE: - return p.parseCreateIndexStmt() + stmt, err := p.parseCreateIndexStmt() + if err != nil { + return nil, apperr.Errorf("parseCreateIndexStmt: %w", err) + } + return stmt, nil default: return nil, apperr.Errorf("currentToken=%#v: %w", p.currentToken, ddl.ErrUnexpectedToken) } diff --git a/pkg/ddl/mysql/parser.go b/pkg/ddl/mysql/parser.go index a193aa5..4f944dc 100644 --- a/pkg/ddl/mysql/parser.go +++ b/pkg/ddl/mysql/parser.go @@ -106,9 +106,17 @@ func (p *Parser) parseCreateStatement() (Stmt, error) { //nolint:ireturn switch p.currentToken.Type { //nolint:exhaustive case TOKEN_TABLE: - return p.parseCreateTableStmt() + stmt, err := p.parseCreateTableStmt() + if err != nil { + return nil, apperr.Errorf("parseCreateTableStmt: %w", err) + } + return stmt, nil case TOKEN_INDEX, TOKEN_UNIQUE: - return p.parseCreateIndexStmt() + stmt, err := p.parseCreateIndexStmt() + if err != nil { + return nil, apperr.Errorf("parseCreateIndexStmt: %w", err) + } + return stmt, nil default: return nil, apperr.Errorf("currentToken=%#v: %w", p.currentToken, ddl.ErrUnexpectedToken) } diff --git a/pkg/ddl/postgres/parser.go b/pkg/ddl/postgres/parser.go index 007d7ad..2f67e07 100644 --- a/pkg/ddl/postgres/parser.go +++ b/pkg/ddl/postgres/parser.go @@ -107,9 +107,17 @@ func (p *Parser) parseCreateStatement() (Stmt, error) { //nolint:ireturn switch p.currentToken.Type { //nolint:exhaustive case TOKEN_TABLE: - return p.parseCreateTableStmt() + stmt, err := p.parseCreateTableStmt() + if err != nil { + return nil, apperr.Errorf("parseCreateTableStmt: %w", err) + } + return stmt, nil case TOKEN_INDEX, TOKEN_UNIQUE: - return p.parseCreateIndexStmt() + stmt, err := p.parseCreateIndexStmt() + if err != nil { + return nil, apperr.Errorf("parseCreateIndexStmt: %w", err) + } + return stmt, nil default: return nil, apperr.Errorf("currentToken=%#v: %w", p.currentToken, ddl.ErrUnexpectedToken) } diff --git a/pkg/ddl/spanner/parser.go b/pkg/ddl/spanner/parser.go index e22ccaa..deb59bc 100644 --- a/pkg/ddl/spanner/parser.go +++ b/pkg/ddl/spanner/parser.go @@ -106,9 +106,17 @@ func (p *Parser) parseCreateStatement() (Stmt, error) { //nolint:ireturn switch p.currentToken.Type { //nolint:exhaustive case TOKEN_TABLE: - return p.parseCreateTableStmt() + stmt, err := p.parseCreateTableStmt() + if err != nil { + return nil, apperr.Errorf("parseCreateTableStmt: %w", err) + } + return stmt, nil case TOKEN_INDEX, TOKEN_UNIQUE: - return p.parseCreateIndexStmt() + stmt, err := p.parseCreateIndexStmt() + if err != nil { + return nil, apperr.Errorf("parseCreateIndexStmt: %w", err) + } + return stmt, nil default: return nil, apperr.Errorf("currentToken=%#v: %w", p.currentToken, ddl.ErrUnexpectedToken) } From 81265d676367bc9994549db44fa84ce763fcde34 Mon Sep 17 00:00:00 2001 From: ginokent <29125616+ginokent@users.noreply.github.com> Date: Wed, 14 Aug 2024 21:31:51 +0900 Subject: [PATCH 2/4] chore: Add make git-force-push-skip-local-ci --- Makefile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Makefile b/Makefile index 293ba7a..64c267c 100644 --- a/Makefile +++ b/Makefile @@ -85,6 +85,12 @@ git-push-skip-local-ci: ## Run git push with skip local CI git push -mv ${REPO_ROOT}/.git/hooks/pre-push{.bak,} +.PHONY: git-force-push-skip-local-ci +git-force-push-skip-local-ci: ## Run git push with skip local CI + -mv ${REPO_ROOT}/.git/hooks/pre-push{,.bak} + git push -f + -mv ${REPO_ROOT}/.git/hooks/pre-push{.bak,} + .PHONY: act-check act-check: @if ! command -v act >/dev/null 2>&1; then \ From d0402ef430d974dc84e45773028ddfb2cdcb5499 Mon Sep 17 00:00:00 2001 From: ginokent <29125616+ginokent@users.noreply.github.com> Date: Wed, 14 Aug 2024 21:06:54 +0900 Subject: [PATCH 3/4] refactor: Modify to distinguish errors between current and peek --- pkg/ddl/cockroachdb/parser.go | 30 +++++++++++++++--------------- pkg/ddl/errors.go | 2 ++ pkg/ddl/mysql/parser.go | 32 ++++++++++++++++---------------- pkg/ddl/postgres/parser.go | 30 +++++++++++++++--------------- pkg/ddl/spanner/parser.go | 32 ++++++++++++++++---------------- pkg/ddl/spanner/parser_test.go | 10 +++++----- 6 files changed, 69 insertions(+), 67 deletions(-) diff --git a/pkg/ddl/cockroachdb/parser.go b/pkg/ddl/cockroachdb/parser.go index 4f2437c..71dedd0 100644 --- a/pkg/ddl/cockroachdb/parser.go +++ b/pkg/ddl/cockroachdb/parser.go @@ -94,7 +94,7 @@ LabelDDL: case TOKEN_EOF: break LabelDDL default: - return nil, apperr.Errorf("currentToken=%#v: %w", p.currentToken, ddl.ErrUnexpectedToken) + return nil, apperr.Errorf("currentToken=%#v, peekToken=%#v: %w", p.currentToken, p.peekToken, ddl.ErrUnexpectedCurrentToken) } p.nextToken() @@ -119,7 +119,7 @@ func (p *Parser) parseCreateStatement() (Stmt, error) { //nolint:ireturn } return stmt, nil default: - return nil, apperr.Errorf("currentToken=%#v: %w", p.currentToken, ddl.ErrUnexpectedToken) + return nil, apperr.Errorf("currentToken=%#v, peekToken=%#v: %w", p.currentToken, p.peekToken, ddl.ErrUnexpectedCurrentToken) } } @@ -175,7 +175,7 @@ LabelColumns: case isConstraint(p.currentToken.Type): constraint, err := p.parseTableConstraint(createTableStmt.Name.Name) if err != nil { - return nil, apperr.Errorf(errFmtPrefix+"parseConstraint: %w", err) + return nil, apperr.Errorf(errFmtPrefix+"parseTableConstraint: %w", err) } createTableStmt.Constraints = createTableStmt.Constraints.Append(constraint) case p.isCurrentToken(TOKEN_COMMA): @@ -186,10 +186,10 @@ LabelColumns: case TOKEN_SEMICOLON, TOKEN_EOF: break LabelColumns default: - return nil, apperr.Errorf(errFmtPrefix+"peekToken=%#v: %w", p.peekToken, ddl.ErrUnexpectedToken) + return nil, apperr.Errorf(errFmtPrefix+"currentToken=%#v, peekToken=%#v: %w", p.currentToken, p.peekToken, ddl.ErrUnexpectedPeekToken) } default: - return nil, apperr.Errorf(errFmtPrefix+"currentToken=%#v: %w", p.currentToken, ddl.ErrUnexpectedToken) + return nil, apperr.Errorf(errFmtPrefix+"currentToken=%#v, peekToken=%#v: %w", p.currentToken, p.peekToken, ddl.ErrUnexpectedCurrentToken) } } @@ -321,7 +321,7 @@ func (p *Parser) parseColumn(tableName *Ident) (*Column, []Constraint, error) { } } default: - return nil, nil, apperr.Errorf(errFmtPrefix+"currentToken=%#v: %w", p.currentToken, ddl.ErrUnexpectedToken) + return nil, nil, apperr.Errorf(errFmtPrefix+"currentToken=%#v, peekToken=%#v: %w", p.currentToken, p.peekToken, ddl.ErrUnexpectedCurrentToken) } return column, constraints, nil @@ -364,7 +364,7 @@ LabelDefault: if isConstraint(p.currentToken.Type) { break LabelDefault } - return nil, apperr.Errorf("currentToken=%#v: %w", p.currentToken, ddl.ErrUnexpectedToken) + return nil, apperr.Errorf("currentToken=%#v, peekToken=%#v: %w", p.currentToken, p.peekToken, ddl.ErrUnexpectedCurrentToken) } p.nextToken() @@ -406,7 +406,7 @@ LabelExpr: } idents = append(idents, NewRawIdent(value)) case TOKEN_EOF: - return nil, apperr.Errorf("currentToken=%#v: %w", p.currentToken, ddl.ErrUnexpectedToken) + return nil, apperr.Errorf("currentToken=%#v, peekToken=%#v: %w", p.currentToken, p.peekToken, ddl.ErrUnexpectedCurrentToken) default: if isReservedValue(p.currentToken.Type) { idents = append(idents, NewRawIdent(p.currentToken.Type.String())) @@ -500,7 +500,7 @@ LabelConstraints: case TOKEN_IDENT, TOKEN_COMMA, TOKEN_CLOSE_PAREN: break LabelConstraints default: - return nil, apperr.Errorf("currentToken=%#v: %w", p.currentToken, ddl.ErrUnexpectedToken) + return nil, apperr.Errorf("currentToken=%#v, peekToken=%#v: %w", p.currentToken, p.peekToken, ddl.ErrUnexpectedCurrentToken) } p.nextToken() @@ -515,7 +515,7 @@ func (p *Parser) parseTableConstraint(tableName *Ident) (Constraint, error) { // if p.isCurrentToken(TOKEN_CONSTRAINT) { p.nextToken() // current = constraint_name if p.currentToken.Type != TOKEN_IDENT { - return nil, apperr.Errorf("currentToken=%#v: %w", p.currentToken, ddl.ErrUnexpectedToken) + return nil, apperr.Errorf("currentToken=%#v, peekToken=%#v: %w", p.currentToken, p.peekToken, ddl.ErrUnexpectedCurrentToken) } constraintName = NewRawIdent(p.currentToken.Literal.Str) p.nextToken() // current = PRIMARY or CHECK //diff:ignore-line-postgres-cockroach @@ -630,7 +630,7 @@ func (p *Parser) parseTableConstraint(tableName *Ident) (Constraint, error) { // c.Columns = idents return c, nil default: - return nil, apperr.Errorf("currentToken=%s: %w", p.currentToken.Type, ddl.ErrUnexpectedToken) + return nil, apperr.Errorf("currentToken=%#v, peekToken=%#v: %w", p.currentToken, p.peekToken, ddl.ErrUnexpectedCurrentToken) } } @@ -716,7 +716,7 @@ LabelIdents: p.nextToken() break LabelIdents default: - return nil, apperr.Errorf("currentToken=%#v: %w", p.currentToken, ddl.ErrUnexpectedToken) + return nil, apperr.Errorf("currentToken=%#v, peekToken=%#v: %w", p.currentToken, p.peekToken, ddl.ErrUnexpectedCurrentToken) } p.nextToken() } @@ -737,7 +737,7 @@ LabelIdents: case TOKEN_CLOSE_PAREN: break LabelIdents case TOKEN_EOF, TOKEN_ILLEGAL: - return nil, apperr.Errorf("currentToken=%#v: %w", p.currentToken, ddl.ErrUnexpectedToken) + return nil, apperr.Errorf("currentToken=%#v, peekToken=%#v: %w", p.currentToken, p.peekToken, ddl.ErrUnexpectedCurrentToken) default: idents = append(idents, NewRawIdent(p.currentToken.Literal.Str)) } @@ -815,7 +815,7 @@ func (p *Parser) checkCurrentToken(expectedTypes ...TokenType) error { return nil } } - return apperr.Errorf("currentToken: expected=%s, but got=%#v: %w", stringz.JoinStringers(",", expectedTypes...), p.currentToken, ddl.ErrUnexpectedToken) + return apperr.Errorf("currentToken=%#v, peekToken=%#v: expected=%v, but got=%v: %w", p.currentToken, p.peekToken, stringz.JoinStringers(",", expectedTypes...), p.currentToken.Type, ddl.ErrUnexpectedCurrentToken) } func (p *Parser) isPeekToken(expectedTypes ...TokenType) bool { @@ -833,5 +833,5 @@ func (p *Parser) checkPeekToken(expectedTypes ...TokenType) error { return nil } } - return apperr.Errorf("peekToken: expected=%s, but got=%#v: %w", stringz.JoinStringers(",", expectedTypes...), p.peekToken, ddl.ErrUnexpectedToken) + return apperr.Errorf("currentToken=%#v, peekToken=%#v: expected=%v, but got=%v: %w", p.currentToken, p.peekToken, stringz.JoinStringers(",", expectedTypes...), p.peekToken.Type, ddl.ErrUnexpectedPeekToken) } diff --git a/pkg/ddl/errors.go b/pkg/ddl/errors.go index 7247f1d..1930cb2 100644 --- a/pkg/ddl/errors.go +++ b/pkg/ddl/errors.go @@ -5,6 +5,8 @@ import ( ) var ( + ErrUnexpectedCurrentToken = errors.New("unexpected current token") + ErrUnexpectedPeekToken = errors.New("unexpected peek token") ErrUnexpectedToken = errors.New("unexpected token") ErrNoDifference = errors.New("no difference") ErrNotSupported = errors.New("not supported") diff --git a/pkg/ddl/mysql/parser.go b/pkg/ddl/mysql/parser.go index 4f944dc..4b72a3c 100644 --- a/pkg/ddl/mysql/parser.go +++ b/pkg/ddl/mysql/parser.go @@ -93,7 +93,7 @@ LabelDDL: case TOKEN_EOF: break LabelDDL default: - return nil, apperr.Errorf("currentToken=%#v: %w", p.currentToken, ddl.ErrUnexpectedToken) + return nil, apperr.Errorf("currentToken=%#v, peekToken=%#v: %w", p.currentToken, p.peekToken, ddl.ErrUnexpectedCurrentToken) } p.nextToken() @@ -118,7 +118,7 @@ func (p *Parser) parseCreateStatement() (Stmt, error) { //nolint:ireturn } return stmt, nil default: - return nil, apperr.Errorf("currentToken=%#v: %w", p.currentToken, ddl.ErrUnexpectedToken) + return nil, apperr.Errorf("currentToken=%#v, peekToken=%#v: %w", p.currentToken, p.peekToken, ddl.ErrUnexpectedCurrentToken) } } @@ -174,7 +174,7 @@ LabelColumns: case isConstraint(p.currentToken.Type): constraint, err := p.parseTableConstraint(createTableStmt.Name.Name) if err != nil { - return nil, apperr.Errorf(errFmtPrefix+"parseConstraint: %w", err) + return nil, apperr.Errorf(errFmtPrefix+"parseTableConstraint: %w", err) } createTableStmt.Constraints = createTableStmt.Constraints.Append(constraint) case p.isCurrentToken(TOKEN_COMMA): @@ -184,7 +184,7 @@ LabelColumns: p.nextToken() break LabelColumns default: - return nil, apperr.Errorf(errFmtPrefix+"currentToken=%#v: %w", p.currentToken, ddl.ErrUnexpectedToken) + return nil, apperr.Errorf(errFmtPrefix+"currentToken=%#v, peekToken=%#v: %w", p.currentToken, p.peekToken, ddl.ErrUnexpectedCurrentToken) } } @@ -254,7 +254,7 @@ LabelTableOptions: case TOKEN_SEMICOLON, TOKEN_EOF: break LabelTableOptions default: - return nil, apperr.Errorf(errFmtPrefix+"currentToken=%#v: %w", p.currentToken, ddl.ErrUnexpectedToken) + return nil, apperr.Errorf(errFmtPrefix+"currentToken=%#v, peekToken=%#v: %w", p.currentToken, p.peekToken, ddl.ErrUnexpectedCurrentToken) } createTableStmt.Options = append(createTableStmt.Options, opt) p.nextToken() @@ -383,7 +383,7 @@ func (p *Parser) parseColumn(tableName *Ident) (*Column, []Constraint, error) { case TOKEN_CASCADE, TOKEN_RESTRICT, TOKEN_CURRENT_TIMESTAMP: column.OnAction += " " + p.currentToken.Literal.String() default: - return nil, nil, apperr.Errorf(errFmtPrefix+"currentToken=%#v: %w", p.currentToken, ddl.ErrUnexpectedToken) + return nil, nil, apperr.Errorf(errFmtPrefix+"currentToken=%#v, peekToken=%#v: %w", p.currentToken, p.peekToken, ddl.ErrUnexpectedCurrentToken) } case TOKEN_CHARACTER: p.nextToken() // current = SET @@ -420,7 +420,7 @@ func (p *Parser) parseColumn(tableName *Ident) (*Column, []Constraint, error) { p.nextToken() // current = COMMA or CLOSE_PAREN } default: - return nil, nil, apperr.Errorf(errFmtPrefix+"currentToken=%#v: %w", p.currentToken, ddl.ErrUnexpectedToken) + return nil, nil, apperr.Errorf(errFmtPrefix+"currentToken=%#v, peekToken=%#v: %w", p.currentToken, p.peekToken, ddl.ErrUnexpectedCurrentToken) } return column, constraints, nil @@ -465,7 +465,7 @@ LabelDefault: if isConstraint(p.currentToken.Type) { break LabelDefault } - return nil, apperr.Errorf("currentToken=%#v: %w", p.currentToken, ddl.ErrUnexpectedToken) + return nil, apperr.Errorf("currentToken=%#v, peekToken=%#v: %w", p.currentToken, p.peekToken, ddl.ErrUnexpectedCurrentToken) } p.nextToken() @@ -507,7 +507,7 @@ LabelExpr: } idents = append(idents, NewRawIdent(value)) case TOKEN_EOF: - return nil, apperr.Errorf("currentToken=%#v: %w", p.currentToken, ddl.ErrUnexpectedToken) + return nil, apperr.Errorf("currentToken=%#v, peekToken=%#v: %w", p.currentToken, p.peekToken, ddl.ErrUnexpectedCurrentToken) default: if isReservedValue(p.currentToken.Type) { idents = append(idents, NewRawIdent(p.currentToken.Type.String())) @@ -594,7 +594,7 @@ LabelConstraints: case TOKEN_IDENT, TOKEN_COMMA, TOKEN_CLOSE_PAREN, TOKEN_COMMENT: break LabelConstraints default: - return nil, apperr.Errorf("currentToken=%#v: %w", p.currentToken, ddl.ErrUnexpectedToken) + return nil, apperr.Errorf("currentToken=%#v, peekToken=%#v: %w", p.currentToken, p.peekToken, ddl.ErrUnexpectedCurrentToken) } p.nextToken() @@ -609,7 +609,7 @@ func (p *Parser) parseTableConstraint(tableName *Ident) (Constraint, error) { // if p.isCurrentToken(TOKEN_CONSTRAINT) { p.nextToken() // current = constraint_name if p.currentToken.Type != TOKEN_IDENT { - return nil, apperr.Errorf("currentToken=%#v: %w", p.currentToken, ddl.ErrUnexpectedToken) + return nil, apperr.Errorf("currentToken=%#v, peekToken=%#v: %w", p.currentToken, p.peekToken, ddl.ErrUnexpectedCurrentToken) } constraintName = NewRawIdent(p.currentToken.Literal.Str) p.nextToken() // current = PRIMARY or CHECK @@ -737,7 +737,7 @@ func (p *Parser) parseTableConstraint(tableName *Ident) (Constraint, error) { // constraint.Expr = constraint.Expr.Append(idents...) return constraint, nil default: - return nil, apperr.Errorf("currentToken=%s: %w", p.currentToken.Type, ddl.ErrUnexpectedToken) + return nil, apperr.Errorf("currentToken=%#v, peekToken=%#v: %w", p.currentToken, p.peekToken, ddl.ErrUnexpectedCurrentToken) } } @@ -825,7 +825,7 @@ LabelIdents: p.nextToken() break LabelIdents default: - return nil, apperr.Errorf("currentToken=%#v: %w", p.currentToken, ddl.ErrUnexpectedToken) + return nil, apperr.Errorf("currentToken=%#v, peekToken=%#v: %w", p.currentToken, p.peekToken, ddl.ErrUnexpectedCurrentToken) } p.nextToken() } @@ -874,7 +874,7 @@ LabelIdents: case TOKEN_CLOSE_PAREN: break LabelIdents case TOKEN_EOF, TOKEN_ILLEGAL: - return nil, apperr.Errorf("currentToken=%#v: %w", p.currentToken, ddl.ErrUnexpectedToken) + return nil, apperr.Errorf("currentToken=%#v, peekToken=%#v: %w", p.currentToken, p.peekToken, ddl.ErrUnexpectedCurrentToken) default: idents = append(idents, NewRawIdent(p.currentToken.Literal.Str)) } @@ -958,7 +958,7 @@ func (p *Parser) checkCurrentToken(expectedTypes ...TokenType) error { return nil } } - return apperr.Errorf("currentToken: expected=%s, but got=%#v: %w", stringz.JoinStringers(",", expectedTypes...), p.currentToken, ddl.ErrUnexpectedToken) + return apperr.Errorf("currentToken=%#v, peekToken=%#v: expected=%v, but got=%v: %w", p.currentToken, p.peekToken, stringz.JoinStringers(",", expectedTypes...), p.currentToken.Type, ddl.ErrUnexpectedCurrentToken) } func (p *Parser) isPeekToken(expectedTypes ...TokenType) bool { @@ -976,5 +976,5 @@ func (p *Parser) checkPeekToken(expectedTypes ...TokenType) error { return nil } } - return apperr.Errorf("peekToken: expected=%s, but got=%#v: %w", stringz.JoinStringers(",", expectedTypes...), p.peekToken, ddl.ErrUnexpectedToken) + return apperr.Errorf("currentToken=%#v, peekToken=%#v: expected=%v, but got=%v: %w", p.currentToken, p.peekToken, stringz.JoinStringers(",", expectedTypes...), p.peekToken.Type, ddl.ErrUnexpectedPeekToken) } diff --git a/pkg/ddl/postgres/parser.go b/pkg/ddl/postgres/parser.go index 2f67e07..7d3d3af 100644 --- a/pkg/ddl/postgres/parser.go +++ b/pkg/ddl/postgres/parser.go @@ -94,7 +94,7 @@ LabelDDL: case TOKEN_EOF: break LabelDDL default: - return nil, apperr.Errorf("currentToken=%#v: %w", p.currentToken, ddl.ErrUnexpectedToken) + return nil, apperr.Errorf("currentToken=%#v, peekToken=%#v: %w", p.currentToken, p.peekToken, ddl.ErrUnexpectedCurrentToken) } p.nextToken() @@ -119,7 +119,7 @@ func (p *Parser) parseCreateStatement() (Stmt, error) { //nolint:ireturn } return stmt, nil default: - return nil, apperr.Errorf("currentToken=%#v: %w", p.currentToken, ddl.ErrUnexpectedToken) + return nil, apperr.Errorf("currentToken=%#v, peekToken=%#v: %w", p.currentToken, p.peekToken, ddl.ErrUnexpectedCurrentToken) } } @@ -175,7 +175,7 @@ LabelColumns: case isConstraint(p.currentToken.Type): constraint, err := p.parseTableConstraint(createTableStmt.Name.Name) if err != nil { - return nil, apperr.Errorf(errFmtPrefix+"parseConstraint: %w", err) + return nil, apperr.Errorf(errFmtPrefix+"parseTableConstraint: %w", err) } createTableStmt.Constraints = createTableStmt.Constraints.Append(constraint) case p.isCurrentToken(TOKEN_COMMA): @@ -186,10 +186,10 @@ LabelColumns: case TOKEN_SEMICOLON, TOKEN_EOF: break LabelColumns default: - return nil, apperr.Errorf(errFmtPrefix+"peekToken=%#v: %w", p.peekToken, ddl.ErrUnexpectedToken) + return nil, apperr.Errorf(errFmtPrefix+"currentToken=%#v, peekToken=%#v: %w", p.currentToken, p.peekToken, ddl.ErrUnexpectedPeekToken) } default: - return nil, apperr.Errorf(errFmtPrefix+"currentToken=%#v: %w", p.currentToken, ddl.ErrUnexpectedToken) + return nil, apperr.Errorf(errFmtPrefix+"currentToken=%#v, peekToken=%#v: %w", p.currentToken, p.peekToken, ddl.ErrUnexpectedCurrentToken) } } @@ -321,7 +321,7 @@ func (p *Parser) parseColumn(tableName *Ident) (*Column, []Constraint, error) { } } default: - return nil, nil, apperr.Errorf(errFmtPrefix+"currentToken=%#v: %w", p.currentToken, ddl.ErrUnexpectedToken) + return nil, nil, apperr.Errorf(errFmtPrefix+"currentToken=%#v, peekToken=%#v: %w", p.currentToken, p.peekToken, ddl.ErrUnexpectedCurrentToken) } return column, constraints, nil @@ -364,7 +364,7 @@ LabelDefault: if isConstraint(p.currentToken.Type) { break LabelDefault } - return nil, apperr.Errorf("currentToken=%#v: %w", p.currentToken, ddl.ErrUnexpectedToken) + return nil, apperr.Errorf("currentToken=%#v, peekToken=%#v: %w", p.currentToken, p.peekToken, ddl.ErrUnexpectedCurrentToken) } p.nextToken() @@ -406,7 +406,7 @@ LabelExpr: } idents = append(idents, NewRawIdent(value)) case TOKEN_EOF: - return nil, apperr.Errorf("currentToken=%#v: %w", p.currentToken, ddl.ErrUnexpectedToken) + return nil, apperr.Errorf("currentToken=%#v, peekToken=%#v: %w", p.currentToken, p.peekToken, ddl.ErrUnexpectedCurrentToken) default: if isReservedValue(p.currentToken.Type) { idents = append(idents, NewRawIdent(p.currentToken.Type.String())) @@ -499,7 +499,7 @@ LabelConstraints: case TOKEN_IDENT, TOKEN_COMMA, TOKEN_CLOSE_PAREN: break LabelConstraints default: - return nil, apperr.Errorf("currentToken=%#v: %w", p.currentToken, ddl.ErrUnexpectedToken) + return nil, apperr.Errorf("currentToken=%#v, peekToken=%#v: %w", p.currentToken, p.peekToken, ddl.ErrUnexpectedCurrentToken) } p.nextToken() @@ -514,7 +514,7 @@ func (p *Parser) parseTableConstraint(tableName *Ident) (Constraint, error) { // if p.isCurrentToken(TOKEN_CONSTRAINT) { p.nextToken() // current = constraint_name if p.currentToken.Type != TOKEN_IDENT { - return nil, apperr.Errorf("currentToken=%#v: %w", p.currentToken, ddl.ErrUnexpectedToken) + return nil, apperr.Errorf("currentToken=%#v, peekToken=%#v: %w", p.currentToken, p.peekToken, ddl.ErrUnexpectedCurrentToken) } constraintName = NewRawIdent(p.currentToken.Literal.Str) p.nextToken() // current = PRIMARY or CHECK or UNIQUE //diff:ignore-line-postgres-cockroach @@ -624,7 +624,7 @@ func (p *Parser) parseTableConstraint(tableName *Ident) (Constraint, error) { // c.Columns = idents return c, nil default: - return nil, apperr.Errorf("currentToken=%s: %w", p.currentToken.Type, ddl.ErrUnexpectedToken) + return nil, apperr.Errorf("currentToken=%#v, peekToken=%#v: %w", p.currentToken, p.peekToken, ddl.ErrUnexpectedCurrentToken) } } @@ -705,7 +705,7 @@ LabelIdents: p.nextToken() break LabelIdents default: - return nil, apperr.Errorf("currentToken=%#v: %w", p.currentToken, ddl.ErrUnexpectedToken) + return nil, apperr.Errorf("currentToken=%#v, peekToken=%#v: %w", p.currentToken, p.peekToken, ddl.ErrUnexpectedCurrentToken) } p.nextToken() } @@ -726,7 +726,7 @@ LabelIdents: case TOKEN_CLOSE_PAREN: break LabelIdents case TOKEN_EOF, TOKEN_ILLEGAL: - return nil, apperr.Errorf("currentToken=%#v: %w", p.currentToken, ddl.ErrUnexpectedToken) + return nil, apperr.Errorf("currentToken=%#v, peekToken=%#v: %w", p.currentToken, p.peekToken, ddl.ErrUnexpectedCurrentToken) default: idents = append(idents, NewRawIdent(p.currentToken.Literal.Str)) } @@ -801,7 +801,7 @@ func (p *Parser) checkCurrentToken(expectedTypes ...TokenType) error { return nil } } - return apperr.Errorf("currentToken: expected=%s, but got=%#v: %w", stringz.JoinStringers(",", expectedTypes...), p.currentToken, ddl.ErrUnexpectedToken) + return apperr.Errorf("currentToken=%#v, peekToken=%#v: expected=%v, but got=%v: %w", p.currentToken, p.peekToken, stringz.JoinStringers(",", expectedTypes...), p.currentToken.Type, ddl.ErrUnexpectedCurrentToken) } func (p *Parser) isPeekToken(expectedTypes ...TokenType) bool { @@ -819,5 +819,5 @@ func (p *Parser) checkPeekToken(expectedTypes ...TokenType) error { return nil } } - return apperr.Errorf("peekToken: expected=%s, but got=%#v: %w", stringz.JoinStringers(",", expectedTypes...), p.peekToken, ddl.ErrUnexpectedToken) + return apperr.Errorf("currentToken=%#v, peekToken=%#v: expected=%v, but got=%v: %w", p.currentToken, p.peekToken, stringz.JoinStringers(",", expectedTypes...), p.peekToken.Type, ddl.ErrUnexpectedPeekToken) } diff --git a/pkg/ddl/spanner/parser.go b/pkg/ddl/spanner/parser.go index deb59bc..4e1177a 100644 --- a/pkg/ddl/spanner/parser.go +++ b/pkg/ddl/spanner/parser.go @@ -93,7 +93,7 @@ LabelDDL: case TOKEN_EOF: break LabelDDL default: - return nil, apperr.Errorf("currentToken=%#v: %w", p.currentToken, ddl.ErrUnexpectedToken) + return nil, apperr.Errorf("currentToken=%#v, peekToken=%#v: %w", p.currentToken, p.peekToken, ddl.ErrUnexpectedCurrentToken) } p.nextToken() @@ -118,7 +118,7 @@ func (p *Parser) parseCreateStatement() (Stmt, error) { //nolint:ireturn } return stmt, nil default: - return nil, apperr.Errorf("currentToken=%#v: %w", p.currentToken, ddl.ErrUnexpectedToken) + return nil, apperr.Errorf("currentToken=%#v, peekToken=%#v: %w", p.currentToken, p.peekToken, ddl.ErrUnexpectedCurrentToken) } } @@ -174,7 +174,7 @@ LabelColumns: case isConstraint(p.currentToken.Type): constraint, err := p.parseTableConstraint(createTableStmt.Name.Name) if err != nil { - return nil, apperr.Errorf(errFmtPrefix+"parseConstraint: %w", err) + return nil, apperr.Errorf(errFmtPrefix+"parseTableConstraint: %w", err) } createTableStmt.Constraints = createTableStmt.Constraints.Append(constraint) case p.isCurrentToken(TOKEN_COMMA): @@ -184,7 +184,7 @@ LabelColumns: p.nextToken() break LabelColumns default: - return nil, apperr.Errorf(errFmtPrefix+"currentToken=%#v: %w", p.currentToken, ddl.ErrUnexpectedToken) + return nil, apperr.Errorf(errFmtPrefix+"currentToken=%#v, peekToken=%#v: %w", p.currentToken, p.peekToken, ddl.ErrUnexpectedCurrentToken) } } @@ -240,7 +240,7 @@ LabelTableOptions: } onAction += " NO ACTION" default: - return nil, apperr.Errorf(errFmtPrefix+"currentToken=%#v: %w", p.currentToken, ddl.ErrUnexpectedToken) + return nil, apperr.Errorf(errFmtPrefix+"currentToken=%#v, peekToken=%#v: %w", p.currentToken, p.peekToken, ddl.ErrUnexpectedCurrentToken) } opt.Value = opt.Value.Append(NewRawIdent(onAction)) } @@ -327,7 +327,7 @@ LabelTableOptions: case TOKEN_SEMICOLON, TOKEN_EOF: break LabelTableOptions default: - return nil, apperr.Errorf(errFmtPrefix+"currentToken=%#v: %w", p.currentToken, ddl.ErrUnexpectedToken) + return nil, apperr.Errorf(errFmtPrefix+"currentToken=%#v, peekToken=%#v: %w", p.currentToken, p.peekToken, ddl.ErrUnexpectedCurrentToken) } p.nextToken() } @@ -469,7 +469,7 @@ func (p *Parser) parseColumn(tableName *Ident) (*Column, []Constraint, error) { column.Options = column.Options.Append(idents...) } default: - return nil, nil, apperr.Errorf(errFmtPrefix+"currentToken=%#v: %w", p.currentToken, ddl.ErrUnexpectedToken) + return nil, nil, apperr.Errorf(errFmtPrefix+"currentToken=%#v, peekToken=%#v: %w", p.currentToken, p.peekToken, ddl.ErrUnexpectedCurrentToken) } return column, constraints, nil @@ -514,7 +514,7 @@ LabelDefault: if isConstraint(p.currentToken.Type) { break LabelDefault } - return nil, apperr.Errorf("currentToken=%#v: %w", p.currentToken, ddl.ErrUnexpectedToken) + return nil, apperr.Errorf("currentToken=%#v, peekToken=%#v: %w", p.currentToken, p.peekToken, ddl.ErrUnexpectedCurrentToken) } p.nextToken() @@ -556,7 +556,7 @@ LabelExpr: } idents = append(idents, NewRawIdent(value)) case TOKEN_EOF: - return nil, apperr.Errorf("currentToken=%#v: %w", p.currentToken, ddl.ErrUnexpectedToken) + return nil, apperr.Errorf("currentToken=%#v, peekToken=%#v: %w", p.currentToken, p.peekToken, ddl.ErrUnexpectedCurrentToken) default: if isReservedValue(p.currentToken.Type) { idents = append(idents, NewRawIdent(p.currentToken.Type.String())) @@ -612,7 +612,7 @@ LabelConstraints: case TOKEN_OPTIONS, TOKEN_IDENT, TOKEN_COMMA, TOKEN_CLOSE_PAREN: break LabelConstraints default: - return nil, apperr.Errorf("currentToken=%#v: %w", p.currentToken, ddl.ErrUnexpectedToken) + return nil, apperr.Errorf("currentToken=%#v, peekToken=%#v: %w", p.currentToken, p.peekToken, ddl.ErrUnexpectedCurrentToken) } p.nextToken() @@ -627,7 +627,7 @@ func (p *Parser) parseTableConstraint(tableName *Ident) (Constraint, error) { // if p.isCurrentToken(TOKEN_CONSTRAINT) { p.nextToken() // current = constraint_name if p.currentToken.Type != TOKEN_IDENT { - return nil, apperr.Errorf("currentToken=%#v: %w", p.currentToken, ddl.ErrUnexpectedToken) + return nil, apperr.Errorf("currentToken=%#v, peekToken=%#v: %w", p.currentToken, p.peekToken, ddl.ErrUnexpectedCurrentToken) } constraintName = NewRawIdent(p.currentToken.Literal.Str) p.nextToken() // current = PRIMARY or CHECK //diff:ignore-line-postgres-cockroach @@ -691,7 +691,7 @@ func (p *Parser) parseTableConstraint(tableName *Ident) (Constraint, error) { // constraint.Expr = constraint.Expr.Append(idents...) return constraint, nil default: - return nil, apperr.Errorf("currentToken=%s: %w", p.currentToken.Type, ddl.ErrUnexpectedToken) + return nil, apperr.Errorf("currentToken=%#v, peekToken=%#v: %w", p.currentToken, p.peekToken, ddl.ErrUnexpectedCurrentToken) } } @@ -741,7 +741,7 @@ LabelIdents: p.nextToken() break LabelIdents default: - return nil, apperr.Errorf("currentToken=%#v: %w", p.currentToken, ddl.ErrUnexpectedToken) + return nil, apperr.Errorf("currentToken=%#v, peekToken=%#v: %w", p.currentToken, p.peekToken, ddl.ErrUnexpectedCurrentToken) } p.nextToken() } @@ -760,7 +760,7 @@ LabelIdents: case TOKEN_CLOSE_PAREN: break LabelIdents case TOKEN_EOF, TOKEN_ILLEGAL: - return nil, apperr.Errorf("currentToken=%#v: %w", p.currentToken, ddl.ErrUnexpectedToken) + return nil, apperr.Errorf("currentToken=%#v, peekToken=%#v: %w", p.currentToken, p.peekToken, ddl.ErrUnexpectedCurrentToken) default: idents = append(idents, NewRawIdent(p.currentToken.Literal.String())) } @@ -837,7 +837,7 @@ func (p *Parser) checkCurrentToken(expectedTypes ...TokenType) error { return nil } } - return apperr.Errorf("currentToken: expected=%s, but got=%#v: %w", stringz.JoinStringers(",", expectedTypes...), p.currentToken, ddl.ErrUnexpectedToken) + return apperr.Errorf("currentToken=%#v, peekToken=%#v: expected=%v, but got=%v: %w", p.currentToken, p.peekToken, stringz.JoinStringers(",", expectedTypes...), p.currentToken.Type, ddl.ErrUnexpectedCurrentToken) } func (p *Parser) isPeekToken(expectedTypes ...TokenType) bool { @@ -855,5 +855,5 @@ func (p *Parser) checkPeekToken(expectedTypes ...TokenType) error { return nil } } - return apperr.Errorf("peekToken: expected=%s, but got=%#v: %w", stringz.JoinStringers(",", expectedTypes...), p.peekToken, ddl.ErrUnexpectedToken) + return apperr.Errorf("currentToken=%#v, peekToken=%#v: expected=%v, but got=%v: %w", p.currentToken, p.peekToken, stringz.JoinStringers(",", expectedTypes...), p.peekToken.Type, ddl.ErrUnexpectedPeekToken) } diff --git a/pkg/ddl/spanner/parser_test.go b/pkg/ddl/spanner/parser_test.go index 2fad78b..29369e8 100644 --- a/pkg/ddl/spanner/parser_test.go +++ b/pkg/ddl/spanner/parser_test.go @@ -186,12 +186,12 @@ CREATE TABLE IF NOT EXISTS complex_defaults ( { name: "failure,CREATE_TABLE_table_name_column_name_INVALID_DEFAULT_OPEN_PAREN", input: `CREATE TABLE "users" ("id" STRING(36) DEFAULT ("id",`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_INVALID_PRIMARY_KEY", input: `CREATE TABLE "users" ("id" STRING(36) PRIMARY NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_INVALID_REFERENCES", @@ -201,7 +201,7 @@ CREATE TABLE IF NOT EXISTS complex_defaults ( { name: "failure,CREATE_TABLE_table_name_column_name_INVALID_REFERENCES_IDENTS", input: `CREATE TABLE "users" ("id" STRING(36) REFERENCES "groups" (NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_INVALID_CHECK", @@ -352,7 +352,7 @@ CREATE TABLE IF NOT EXISTS complex_defaults ( { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_INVALID_FOREIGN", input: `CREATE TABLE "users" ("id" STRING(36), FOREIGN NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_INVALID_FOREIGN_KEY", @@ -397,7 +397,7 @@ CREATE TABLE IF NOT EXISTS complex_defaults ( { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_UNIQUE_INDEX_INVALID", input: `CREATE TABLE "users" ("id" STRING(36), UNIQUE INDEX users_idx_name NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_UNIQUE_INDEX_COLUMN_INVALID", From 3b53af0d168da8284925d61b0e1b9445446cc421 Mon Sep 17 00:00:00 2001 From: ginokent <29125616+ginokent@users.noreply.github.com> Date: Wed, 14 Aug 2024 21:09:10 +0900 Subject: [PATCH 4/4] test: Modify to distinguish errors between current and peek --- pkg/ddl/cockroachdb/parser_test.go | 145 +++++++++++------------ pkg/ddl/mysql/parser_test.go | 183 ++++++++++++++--------------- pkg/ddl/postgres/parser_test.go | 143 +++++++++++----------- pkg/ddl/spanner/parser_test.go | 153 ++++++++++++------------ 4 files changed, 302 insertions(+), 322 deletions(-) diff --git a/pkg/ddl/cockroachdb/parser_test.go b/pkg/ddl/cockroachdb/parser_test.go index 1a56c12..c69cfaf 100644 --- a/pkg/ddl/cockroachdb/parser_test.go +++ b/pkg/ddl/cockroachdb/parser_test.go @@ -160,277 +160,272 @@ CREATE TABLE IF NOT EXISTS complex_defaults ( { name: "failure,invalid", input: `)invalid`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_INVALID", input: `CREATE INVALID;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_INVALID", input: `CREATE TABLE;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_IF_INVALID", input: `CREATE TABLE IF;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_TABLE_IF_NOT_INVALID", input: `CREATE TABLE IF NOT;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_TABLE_table_name_INVALID", input: `CREATE TABLE "users";`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_INVALID", input: `CREATE TABLE "users" ("id";`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_data_type_INVALID", input: `CREATE TABLE "users" ("id" UUID;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_INVALID", input: `CREATE TABLE "users" ("id" UUID, CONSTRAINT "invalid" NOT;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { - name: "failure,CREATE_TABLE_table_name_column_name_INVALID", + name: "failure,CREATE_TABLE_table_name_column_name_data_type__INVALID", input: `CREATE TABLE "users" ("id" UUID)(;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_COMMA_INVALID", input: `CREATE TABLE "users" ("id" TIMESTAMP CREATE`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_DATA_TYPE_INVALID", input: `CREATE TABLE "users" ("id" VARYING();`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_INVALID_NOT", input: `CREATE TABLE "users" ("id" UUID NULL NOT;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_INVALID_DEFAULT", input: `CREATE TABLE "users" ("id" UUID DEFAULT ("id")`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_INVALID_DEFAULT_OPEN_PAREN", input: `CREATE TABLE "users" ("id" UUID DEFAULT ("id",`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_INVALID_PRIMARY_KEY", input: `CREATE TABLE "users" ("id" UUID PRIMARY NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_INVALID_REFERENCES", input: `CREATE TABLE "users" ("id" UUID REFERENCES NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_INVALID_REFERENCES_IDENTS", input: `CREATE TABLE "users" ("id" UUID REFERENCES "groups" (NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_INVALID_CHECK", input: `CREATE TABLE "users" ("id" UUID CHECK NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CHECK_INVALID_IDENTS", input: `CREATE TABLE "users" ("id" UUID CHECK (NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_INVALID_IDENT", input: `CREATE TABLE "users" ("id" UUID, CONSTRAINT NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_INVALID_PRIMARY", input: `CREATE TABLE "users" ("id" UUID, PRIMARY NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_INVALID_PRIMARY_KEY", input: `CREATE TABLE "users" ("id" UUID, PRIMARY KEY NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_INVALID_PRIMARY_KEY_OPEN_PAREN", input: `CREATE TABLE "users" ("id" UUID, PRIMARY KEY (NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { - name: "failure,CREATE_TABLE_table_name_column_name_REFERENCES_INVALID", + name: "failure,CREATE_TABLE_table_name_column_name_REFERENCES_ON_INVALID", input: `CREATE TABLE "users" ("id" UUID REFERENCES foo (foo_id) ON`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { - name: "failure,CREATE_TABLE_table_name_column_name_REFERENCES_INVALID", + name: "failure,CREATE_TABLE_table_name_column_name_REFERENCES_ON_DELETE_INVALID", input: `CREATE TABLE "users" ("id" UUID REFERENCES foo (foo_id) ON DELETE`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { - name: "failure,CREATE_TABLE_table_name_column_name_REFERENCES_INVALID", + name: "failure,CREATE_TABLE_table_name_column_name_REFERENCES_ON_DELETE_NO_INVALID", input: `CREATE TABLE "users" ("id" UUID REFERENCES foo (foo_id) ON DELETE NO`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { - name: "failure,CREATE_TABLE_table_name_column_name_REFERENCES_INVALID", + name: "failure,CREATE_TABLE_table_name_column_name_REFERENCES_ON_DELETE_NO_ACTION_INVALID", input: `CREATE TABLE "users" ("id" UUID REFERENCES foo (foo_id) ON DELETE NO ACTION`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_INVALID_FOREIGN", input: `CREATE TABLE "users" ("id" UUID, FOREIGN NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_INVALID_FOREIGN_KEY", input: `CREATE TABLE "users" ("id" UUID, FOREIGN KEY NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_INVALID_FOREIGN_KEY_OPEN_PAREN", input: `CREATE TABLE "users" ("id" UUID, FOREIGN KEY (NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_FOREIGN_KEY_IDENTS_INVALID", input: `CREATE TABLE "users" ("id" UUID, FOREIGN KEY ("group_id") NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_FOREIGN_KEY_IDENTS_REFERENCES_INVALID", input: `CREATE TABLE "users" ("id" UUID, FOREIGN KEY ("group_id") REFERENCES `, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_FOREIGN_KEY_IDENTS_REFERENCES_INVALID_IDENTS", input: `CREATE TABLE "users" ("id" UUID, FOREIGN KEY ("group_id") REFERENCES "groups" NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_FOREIGN_KEY_IDENTS_REFERENCES_INVALID_CLOSE_PAREN", input: `CREATE TABLE "users" ("id" UUID, FOREIGN KEY ("group_id") REFERENCES "groups" ("id")`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_FOREIGN_KEY_IDENTS_REFERENCES_ON_INVALID", input: `CREATE TABLE "users" ("id" UUID, FOREIGN KEY ("group_id") REFERENCES "groups" ("id") ON`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_FOREIGN_KEY_IDENTS_REFERENCES_ON_DELETE_INVALID", input: `CREATE TABLE "users" ("id" UUID, FOREIGN KEY ("group_id") REFERENCES "groups" ("id") ON DELETE`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_FOREIGN_KEY_IDENTS_REFERENCES_ON_DELETE_NO_INVALID", input: `CREATE TABLE "users" ("id" UUID, FOREIGN KEY ("group_id") REFERENCES "groups" ("id") ON DELETE NO`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_FOREIGN_KEY_IDENTS_REFERENCES_ON_DELETE_NO_INVALID", input: `CREATE TABLE "users" ("id" UUID, FOREIGN KEY ("group_id") REFERENCES "groups" ("id") ON DELETE NO ACTION`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_UNIQUE_INVALID", input: `CREATE TABLE "users" ("id" UUID, UNIQUE NOT`, - wantErr: ddl.ErrUnexpectedToken, - }, - { - name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_UNIQUE_INVALID", - input: `CREATE TABLE "users" ("id" UUID, UNIQUE NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_UNIQUE_INDEX_INVALID", input: `CREATE TABLE "users" ("id" UUID, UNIQUE INDEX users_idx_name NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_UNIQUE_INDEX_COLUMN_INVALID", input: `CREATE TABLE "users" ("id" UUID, UNIQUE INDEX users_idx_name (NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { - name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_UNIQUE_INVALID", + name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_UNIQUE_INDEX_INVALID", input: `CREATE TABLE "users" ("id" UUID, UNIQUE INDEX NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_UNIQUE_IDENTS_INVALID", input: `CREATE TABLE "users" ("id" UUID, name TEXT, UNIQUE ("id", name)`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_INDEX_INVALID", input: `CREATE INDEX NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_INDEX_IF_INVALID", input: `CREATE INDEX IF;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_INDEX_IF_NOT_INVALID", input: `CREATE INDEX IF NOT;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_INDEX_IF_NOT_EXISTS_INVALID", input: `CREATE INDEX IF NOT EXISTS;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_INDEX_index_name_INVALID", input: `CREATE INDEX users_idx_username NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_INDEX_index_name_ON_INVALID", input: `CREATE INDEX users_idx_username ON NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_INDEX_index_name_ON_table_name_INVALID", input: `CREATE INDEX users_idx_username ON users NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_INDEX_index_name_ON_table_name_USING_INVALID", input: `CREATE INDEX users_idx_username ON users USING NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_INDEX_index_name_ON_table_name_USING_method_INVALID", input: `CREATE INDEX users_idx_username ON users USING btree NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_INDEX_index_name_ON_table_name_USING_method_OPEN_INVALID", input: `CREATE INDEX users_idx_username ON users USING btree (NOT)`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, } @@ -462,7 +457,7 @@ func TestParser_parseColumn(t *testing.T) { t.Parallel() _, _, err := NewParser(NewLexer(`NOT`)).parseColumn(&Ident{Name: "table_name", QuotationMark: `"`, Raw: `"table_name"`}) - require.ErrorIs(t, err, ddl.ErrUnexpectedToken) + require.ErrorIs(t, err, ddl.ErrUnexpectedCurrentToken) }) t.Run("failure,parseDataType", func(t *testing.T) { @@ -473,7 +468,7 @@ func TestParser_parseColumn(t *testing.T) { p.nextToken() p.nextToken() _, _, err := p.parseColumn(&Ident{Name: "table_name", QuotationMark: `"`, Raw: `"table_name"`}) - require.ErrorIs(t, err, ddl.ErrUnexpectedToken) + require.ErrorIs(t, err, ddl.ErrUnexpectedCurrentToken) }) } @@ -497,7 +492,7 @@ func TestParser_parseExpr(t *testing.T) { p.nextToken() p.nextToken() _, err := p.parseExpr() - require.ErrorIs(t, err, ddl.ErrUnexpectedToken) + require.ErrorIs(t, err, ddl.ErrUnexpectedCurrentToken) }) t.Run("failure,invalid2", func(t *testing.T) { @@ -507,7 +502,7 @@ func TestParser_parseExpr(t *testing.T) { p.nextToken() p.nextToken() _, err := p.parseExpr() - require.ErrorIs(t, err, ddl.ErrUnexpectedToken) + require.ErrorIs(t, err, ddl.ErrUnexpectedCurrentToken) }) } @@ -521,7 +516,7 @@ func TestParser_parseDataType(t *testing.T) { p.nextToken() p.nextToken() _, err := p.parseDataType() - require.ErrorIs(t, err, ddl.ErrUnexpectedToken) + require.ErrorIs(t, err, ddl.ErrUnexpectedPeekToken) }) t.Run("failure,TIMESTAMP_WITH_TIME_NOT", func(t *testing.T) { @@ -531,7 +526,7 @@ func TestParser_parseDataType(t *testing.T) { p.nextToken() p.nextToken() _, err := p.parseDataType() - require.ErrorIs(t, err, ddl.ErrUnexpectedToken) + require.ErrorIs(t, err, ddl.ErrUnexpectedPeekToken) }) t.Run("failure,DOUBLE_NOT", func(t *testing.T) { @@ -541,7 +536,7 @@ func TestParser_parseDataType(t *testing.T) { p.nextToken() p.nextToken() _, err := p.parseDataType() - require.ErrorIs(t, err, ddl.ErrUnexpectedToken) + require.ErrorIs(t, err, ddl.ErrUnexpectedPeekToken) }) t.Run("failure,DOUBLE_PRECISION", func(t *testing.T) { @@ -551,7 +546,7 @@ func TestParser_parseDataType(t *testing.T) { p.nextToken() p.nextToken() _, err := p.parseDataType() - require.ErrorIs(t, err, ddl.ErrUnexpectedToken) + require.ErrorIs(t, err, ddl.ErrUnexpectedCurrentToken) }) t.Run("failure,CHARACTER_NOT", func(t *testing.T) { @@ -561,7 +556,7 @@ func TestParser_parseDataType(t *testing.T) { p.nextToken() p.nextToken() _, err := p.parseDataType() - require.ErrorIs(t, err, ddl.ErrUnexpectedToken) + require.ErrorIs(t, err, ddl.ErrUnexpectedPeekToken) }) t.Run("failure,CHARACTER_VARYING_NOT", func(t *testing.T) { @@ -571,6 +566,6 @@ func TestParser_parseDataType(t *testing.T) { p.nextToken() p.nextToken() _, err := p.parseDataType() - require.ErrorIs(t, err, ddl.ErrUnexpectedToken) + require.ErrorIs(t, err, ddl.ErrUnexpectedCurrentToken) }) } diff --git a/pkg/ddl/mysql/parser_test.go b/pkg/ddl/mysql/parser_test.go index 4d8c0b9..853bd49 100644 --- a/pkg/ddl/mysql/parser_test.go +++ b/pkg/ddl/mysql/parser_test.go @@ -162,377 +162,372 @@ CREATE TABLE IF NOT EXISTS complex_defaults ( { name: "failure,invalid", input: `)invalid`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_INVALID", input: `CREATE INVALID;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_INVALID", input: `CREATE TABLE;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_IF_INVALID", input: `CREATE TABLE IF;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_TABLE_IF_NOT_INVALID", input: `CREATE TABLE IF NOT;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_TABLE_table_name_INVALID", input: `CREATE TABLE "users";`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_INVALID", input: `CREATE TABLE "users" ("id";`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_data_type_INVALID", input: `CREATE TABLE "users" ("id" VARCHAR(36);`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_data_type_CHARACTER_INVALID", input: `CREATE TABLE "users" ("id" VARCHAR(36) CHARACTER`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_data_type_CHARACTER_SET_INVALID", input: `CREATE TABLE "users" ("id" VARCHAR(36) CHARACTER SET`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_INVALID", input: `CREATE TABLE "users" ("id" VARCHAR(36), CONSTRAINT "invalid" NOT;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { - name: "failure,CREATE_TABLE_table_name_column_name_INVALID", + name: "failure,CREATE_TABLE_table_name_column_name_data_type__INVALID", input: `CREATE TABLE "users" ("id" VARCHAR(36))(;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_COMMA_INVALID", input: `CREATE TABLE "users" ("id" TIMESTAMP CREATE`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_DATA_TYPE_INVALID", input: `CREATE TABLE "users" ("id" VARYING();`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_INVALID_NOT", input: `CREATE TABLE "users" ("id" VARCHAR(36) NULL NOT;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_ON_INVALID", input: `CREATE TABLE "users" ("id" VARCHAR(36), ts DATETIME ON`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { - name: "failure,CREATE_TABLE_table_name_column_name_ON_UPDATE INVALID", + name: "failure,CREATE_TABLE_table_name_column_name_ON_UPDATE_INVALID", input: `CREATE TABLE "users" ("id" VARCHAR(36), ts DATETIME ON UPDATE`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_INVALID_DEFAULT", input: `CREATE TABLE "users" ("id" VARCHAR(36) DEFAULT ("id")`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_INVALID_DEFAULT_OPEN_PAREN", input: `CREATE TABLE "users" ("id" VARCHAR(36) DEFAULT ("id",`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_INVALID_PRIMARY_KEY", input: `CREATE TABLE "users" ("id" VARCHAR(36) PRIMARY NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_INVALID_REFERENCES", input: `CREATE TABLE "users" ("id" VARCHAR(36) REFERENCES NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_INVALID_REFERENCES_INVALID", input: `CREATE TABLE "users" ("id" VARCHAR(36) REFERENCES "groups" (NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_INVALID_REFERENCES_ON_INVALID", input: `CREATE TABLE "users" ("id" VARCHAR(36) REFERENCES "groups" (id) ON`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_INVALID_REFERENCES_ON_UPDATE_NO_INVALID", input: `CREATE TABLE "users" ("id" VARCHAR(36) REFERENCES "groups" (id) ON UPDATE NO`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_INVALID_REFERENCES_ON_UPDATE_NO_ACTION_ON_INVALID", input: `CREATE TABLE "users" ("id" VARCHAR(36) REFERENCES "groups" (id) ON UPDATE NO ACTION ON`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_INVALID_REFERENCES_ON_UPDATE_NO_ACTION_ON_DELETE_INVALID", input: `CREATE TABLE "users" ("id" VARCHAR(36) REFERENCES "groups" (id) ON UPDATE NO ACTION ON DELETE`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { - name: "failure,CREATE_TABLE_table_name_column_name_INVALID_REFERENCES_ON_UPDATE_NO_ACTION_ON_DELETE_INVALID", + name: "failure,CREATE_TABLE_table_name_column_name_INVALID_REFERENCES_ON_UPDATE_NO_ACTION_ON_DELETE_NO_ACTION_INVALID", input: `CREATE TABLE "users" ("id" VARCHAR(36) REFERENCES "groups" (id) ON UPDATE NO ACTION ON DELETE NO ACTION`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_INVALID_REFERENCESIN_IDENTS", input: `CREATE TABLE "users" ("id" VARCHAR(36) REFERENCES "groups" (id) ON UPDATE NO ACTION ON DELETE NO`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_INVALID_CHECK", input: `CREATE TABLE "users" ("id" VARCHAR(36) CHECK NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CHECK_INVALID_IDENTS", input: `CREATE TABLE "users" ("id" VARCHAR(36) CHECK (NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_INVALID_IDENT", input: `CREATE TABLE "users" ("id" VARCHAR(36), CONSTRAINT NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_INVALID_PRIMARY", input: `CREATE TABLE "users" ("id" VARCHAR(36), PRIMARY NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_INVALID_PRIMARY_KEY", input: `CREATE TABLE "users" ("id" VARCHAR(36), PRIMARY KEY NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_INVALID_PRIMARY_KEY_OPEN_PAREN", input: `CREATE TABLE "users" ("id" VARCHAR(36), PRIMARY KEY (NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_INVALID_FOREIGN", input: `CREATE TABLE "users" ("id" VARCHAR(36), FOREIGN NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_INVALID_FOREIGN_KEY", input: `CREATE TABLE "users" ("id" VARCHAR(36), FOREIGN KEY NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_INVALID_FOREIGN_KEY_OPEN_PAREN", input: `CREATE TABLE "users" ("id" VARCHAR(36), FOREIGN KEY (NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_FOREIGN_KEY_IDENTS_INVALID", input: `CREATE TABLE "users" ("id" VARCHAR(36), FOREIGN KEY ("group_id") NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_FOREIGN_KEY_IDENTS_REFERENCES_INVALID", input: `CREATE TABLE "users" ("id" VARCHAR(36), FOREIGN KEY ("group_id") REFERENCES `, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_FOREIGN_KEY_IDENTS_REFERENCES_INVALID_IDENTS", input: `CREATE TABLE "users" ("id" VARCHAR(36), FOREIGN KEY ("group_id") REFERENCES "groups" NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_FOREIGN_KEY_IDENTS_REFERENCES_INVALID_CLOSE_PAREN", input: `CREATE TABLE "users" ("id" VARCHAR(36), FOREIGN KEY ("group_id") REFERENCES "groups" ("id")`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_FOREIGN_KEY_IDENTS_REFERENCES_ON_INVALID", input: `CREATE TABLE "users" ("id" VARCHAR(36), FOREIGN KEY ("group_id") REFERENCES "groups" ("id") ON`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_FOREIGN_KEY_IDENTS_REFERENCES_ON_DELETE_NO_ACTION_INVALID", input: `CREATE TABLE "users" ("id" VARCHAR(36), FOREIGN KEY ("group_id") REFERENCES "groups" ("id") ON DELETE NO ACTION`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_FOREIGN_KEY_IDENTS_REFERENCES_ON_DELETE_NO_ACTION_ON_UPDATE_INVALID", input: `CREATE TABLE "users" ("id" VARCHAR(36), FOREIGN KEY ("group_id") REFERENCES "groups" ("id") ON DELETE NO ACTION ON UPDATE`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_FOREIGN_KEY_IDENTS_REFERENCES_ON_DELETE_NO_ACTION_ON_UPDATE_NO_ACTION_INVALID", input: `CREATE TABLE "users" ("id" VARCHAR(36), FOREIGN KEY ("group_id") REFERENCES "groups" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION`, - wantErr: ddl.ErrUnexpectedToken, - }, - { - name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_UNIQUE_INVALID", - input: `CREATE TABLE "users" ("id" VARCHAR(36), UNIQUE NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_UNIQUE_INVALID", input: `CREATE TABLE "users" ("id" VARCHAR(36), UNIQUE NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_UNIQUE_INDEX_INVALID", input: `CREATE TABLE "users" ("id" VARCHAR(36), UNIQUE INDEX users_idx_name NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_UNIQUE_INDEX_COLUMN_INVALID", input: `CREATE TABLE "users" ("id" VARCHAR(36), UNIQUE INDEX users_idx_name (NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { - name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_UNIQUE_INVALID", + name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_UNIQUE_INDEX_INVALID", input: `CREATE TABLE "users" ("id" VARCHAR(36), UNIQUE INDEX NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_UNIQUE_IDENTS_INVALID", input: `CREATE TABLE "users" ("id" VARCHAR(36), name TEXT, UNIQUE ("id", name)`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { - name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_UNIQUE_IDENTS_CHECK_INVALID", + name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_CHECK_INVALID", input: `CREATE TABLE "users" ("id" VARCHAR(36), name TEXT, CHECK INVALID`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { - name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_UNIQUE_IDENTS_CHECK_OPEN_INVALID", + name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_CHECK_OPEN_INVALID", input: `CREATE TABLE "users" ("id" VARCHAR(36), name TEXT, CHECK (INVALID`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { - name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_UNIQUE_IDENTS_CHECK_OPEN_CLOSE_INVALID", + name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_CHECK_OPEN_CLOSE_INVALID", input: `CREATE TABLE "users" ("id" VARCHAR(36), name TEXT, CHECK ("id" NOT NULL)`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_UNIQUE_KEY_IDENTS_ENGINE_INVALID", input: `CREATE TABLE "users" ("id" VARCHAR(36), name TEXT, UNIQUE KEY users_idx_on_id_name ("id", name)) ENGINE`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_UNIQUE_KEY_IDENTS_ENGINE_EQUAL_INVALID", input: `CREATE TABLE "users" ("id" VARCHAR(36), name TEXT, UNIQUE KEY users_idx_on_id_name ("id", name)) ENGINE=`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_UNIQUE_KEY_IDENTS_AUTO_INCREMENT_INVALID", input: `CREATE TABLE "users" ("id" VARCHAR(36), name TEXT, UNIQUE KEY users_idx_on_id_name ("id", name)) AUTO_INCREMENT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_UNIQUE_KEY_IDENTS_AUTO_INCREMENT_EQUAL_INVALID", input: `CREATE TABLE "users" ("id" VARCHAR(36), name TEXT, UNIQUE KEY users_idx_on_id_name ("id", name)) AUTO_INCREMENT=`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_UNIQUE_KEY_IDENTS_DEFAULT_INVALID", input: `CREATE TABLE "users" ("id" VARCHAR(36), name TEXT, UNIQUE KEY users_idx_on_id_name ("id", name)) DEFAULT=`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_UNIQUE_KEY_IDENTS_DEFAULT_CHARSET_INVALID", input: `CREATE TABLE "users" ("id" VARCHAR(36), name TEXT, UNIQUE KEY users_idx_on_id_name ("id", name)) DEFAULT CHARSET`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_UNIQUE_KEY_IDENTS_DEFAULT_CHARSET_EQUAL_INVALID", input: `CREATE TABLE "users" ("id" VARCHAR(36), name TEXT, UNIQUE KEY users_idx_on_id_name ("id", name)) DEFAULT CHARSET=`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_UNIQUE_KEY_IDENTS_COLLATE_INVALID", input: `CREATE TABLE "users" ("id" VARCHAR(36), name TEXT, UNIQUE KEY users_idx_on_id_name ("id", name)) COLLATE`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_UNIQUE_KEY_IDENTS_COLLATE_EQUAL_INVALID", input: `CREATE TABLE "users" ("id" VARCHAR(36), name TEXT, UNIQUE KEY users_idx_on_id_name ("id", name)) COLLATE=`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_UNIQUE_KEY_IDENTS_COMMENT_INVALID", input: `CREATE TABLE "users" ("id" VARCHAR(36), name TEXT, UNIQUE KEY users_idx_on_id_name ("id", name)) COMMENT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_UNIQUE_KEY_IDENTS_COMMENT_EQUAL_INVALID", input: `CREATE TABLE "users" ("id" VARCHAR(36), name TEXT, UNIQUE KEY users_idx_on_id_name ("id", name)) COMMENT=`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_INDEX_INVALID", input: `CREATE INDEX NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_INDEX_IF_INVALID", input: `CREATE INDEX IF;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_INDEX_IF_NOT_INVALID", input: `CREATE INDEX IF NOT;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_INDEX_IF_NOT_EXISTS_INVALID", input: `CREATE INDEX IF NOT EXISTS;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_INDEX_index_name_INVALID", input: `CREATE INDEX users_idx_username NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_INDEX_index_name_ON_INVALID", input: `CREATE INDEX users_idx_username ON NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_INDEX_index_name_ON_table_name_INVALID", input: `CREATE INDEX users_idx_username ON users NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_INDEX_index_name_ON_table_name_USING_INVALID", input: `CREATE INDEX users_idx_username ON users USING NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_INDEX_index_name_ON_table_name_USING_method_INVALID", input: `CREATE INDEX users_idx_username ON users USING btree NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_INDEX_index_name_ON_table_name_USING_method_OPEN_INVALID", input: `CREATE INDEX users_idx_username ON users USING btree (NOT)`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, } @@ -564,7 +559,7 @@ func TestParser_parseColumn(t *testing.T) { t.Parallel() _, _, err := NewParser(NewLexer(`NOT`)).parseColumn(&Ident{Name: "table_name", QuotationMark: `"`, Raw: `"table_name"`}) - require.ErrorIs(t, err, ddl.ErrUnexpectedToken) + require.ErrorIs(t, err, ddl.ErrUnexpectedCurrentToken) }) t.Run("failure,parseDataType", func(t *testing.T) { @@ -575,7 +570,7 @@ func TestParser_parseColumn(t *testing.T) { p.nextToken() p.nextToken() _, _, err := p.parseColumn(&Ident{Name: "table_name", QuotationMark: `"`, Raw: `"table_name"`}) - require.ErrorIs(t, err, ddl.ErrUnexpectedToken) + require.ErrorIs(t, err, ddl.ErrUnexpectedCurrentToken) }) } @@ -588,7 +583,7 @@ func TestParser_parseOnAction(t *testing.T) { p.nextToken() p.nextToken() _, err := p.parseOnAction() - require.ErrorIs(t, err, ddl.ErrUnexpectedToken) + require.ErrorIs(t, err, ddl.ErrUnexpectedCurrentToken) }) } @@ -602,7 +597,7 @@ func TestParser_parseExpr(t *testing.T) { p.nextToken() p.nextToken() _, err := p.parseExpr() - require.ErrorIs(t, err, ddl.ErrUnexpectedToken) + require.ErrorIs(t, err, ddl.ErrUnexpectedCurrentToken) }) t.Run("failure,invalid2", func(t *testing.T) { @@ -612,7 +607,7 @@ func TestParser_parseExpr(t *testing.T) { p.nextToken() p.nextToken() _, err := p.parseExpr() - require.ErrorIs(t, err, ddl.ErrUnexpectedToken) + require.ErrorIs(t, err, ddl.ErrUnexpectedCurrentToken) }) } @@ -636,7 +631,7 @@ func TestParser_parseDataType(t *testing.T) { p.nextToken() p.nextToken() _, err := p.parseDataType() - require.ErrorIs(t, err, ddl.ErrUnexpectedToken) + require.ErrorIs(t, err, ddl.ErrUnexpectedCurrentToken) }) t.Run("failure,CHARACTER_NOT", func(t *testing.T) { @@ -646,7 +641,7 @@ func TestParser_parseDataType(t *testing.T) { p.nextToken() p.nextToken() _, err := p.parseDataType() - require.ErrorIs(t, err, ddl.ErrUnexpectedToken) + require.ErrorIs(t, err, ddl.ErrUnexpectedPeekToken) }) t.Run("failure,CHARACTER_VARYING_NOT", func(t *testing.T) { @@ -656,6 +651,6 @@ func TestParser_parseDataType(t *testing.T) { p.nextToken() p.nextToken() _, err := p.parseDataType() - require.ErrorIs(t, err, ddl.ErrUnexpectedToken) + require.ErrorIs(t, err, ddl.ErrUnexpectedCurrentToken) }) } diff --git a/pkg/ddl/postgres/parser_test.go b/pkg/ddl/postgres/parser_test.go index 85d880d..6a80c1d 100644 --- a/pkg/ddl/postgres/parser_test.go +++ b/pkg/ddl/postgres/parser_test.go @@ -105,272 +105,267 @@ CREATE TABLE IF NOT EXISTS complex_defaults ( { name: "failure,invalid", input: `)invalid`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_INVALID", input: `CREATE INVALID;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_INVALID", input: `CREATE TABLE;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_IF_INVALID", input: `CREATE TABLE IF;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_TABLE_IF_NOT_INVALID", input: `CREATE TABLE IF NOT;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_TABLE_table_name_INVALID", input: `CREATE TABLE "users";`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_INVALID", input: `CREATE TABLE "users" ("id";`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_data_type_INVALID", input: `CREATE TABLE "users" ("id" UUID;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_INVALID", input: `CREATE TABLE "users" ("id" UUID, CONSTRAINT "invalid" NOT;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { - name: "failure,CREATE_TABLE_table_name_column_name_INVALID", + name: "failure,CREATE_TABLE_table_name_column_name_data_type__INVALID", input: `CREATE TABLE "users" ("id" UUID)(;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_COMMA_INVALID", input: `CREATE TABLE "users" ("id" UUID,(;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_DATA_TYPE_INVALID", input: `CREATE TABLE "users" ("id" VARYING();`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_INVALID_NOT", input: `CREATE TABLE "users" ("id" UUID NULL NOT;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_INVALID_DEFAULT", input: `CREATE TABLE "users" ("id" UUID DEFAULT ("id")`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_INVALID_DEFAULT_OPEN_PAREN", input: `CREATE TABLE "users" ("id" UUID DEFAULT ("id",`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_INVALID_PRIMARY_KEY", input: `CREATE TABLE "users" ("id" UUID PRIMARY NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_INVALID_REFERENCES", input: `CREATE TABLE "users" ("id" UUID REFERENCES NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_INVALID_REFERENCES_IDENTS", input: `CREATE TABLE "users" ("id" UUID REFERENCES "groups" (NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_INVALID_CHECK", input: `CREATE TABLE "users" ("id" UUID CHECK NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CHECK_INVALID_IDENTS", input: `CREATE TABLE "users" ("id" UUID CHECK (NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_INVALID_IDENT", input: `CREATE TABLE "users" ("id" UUID, CONSTRAINT NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_INVALID_PRIMARY", input: `CREATE TABLE "users" ("id" UUID, PRIMARY NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_INVALID_PRIMARY_KEY", input: `CREATE TABLE "users" ("id" UUID, PRIMARY KEY NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_INVALID_PRIMARY_KEY_OPEN_PAREN", input: `CREATE TABLE "users" ("id" UUID, PRIMARY KEY (NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { - name: "failure,CREATE_TABLE_table_name_column_name_REFERENCES_INVALID", + name: "failure,CREATE_TABLE_table_name_column_name_REFERENCES_ON_INVALID", input: `CREATE TABLE "users" ("id" UUID REFERENCES foo (foo_id) ON`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { - name: "failure,CREATE_TABLE_table_name_column_name_REFERENCES_INVALID", + name: "failure,CREATE_TABLE_table_name_column_name_REFERENCES_ON_DELETE_INVALID", input: `CREATE TABLE "users" ("id" UUID REFERENCES foo (foo_id) ON DELETE`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { - name: "failure,CREATE_TABLE_table_name_column_name_REFERENCES_INVALID", + name: "failure,CREATE_TABLE_table_name_column_name_REFERENCES_ON_DELETE_NO_INVALID", input: `CREATE TABLE "users" ("id" UUID REFERENCES foo (foo_id) ON DELETE NO`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { - name: "failure,CREATE_TABLE_table_name_column_name_REFERENCES_INVALID", + name: "failure,CREATE_TABLE_table_name_column_name_REFERENCES_ON_DELETE_NO_ACTION_INVALID", input: `CREATE TABLE "users" ("id" UUID REFERENCES foo (foo_id) ON DELETE NO ACTION`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_INVALID_FOREIGN", input: `CREATE TABLE "users" ("id" UUID, FOREIGN NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_INVALID_FOREIGN_KEY", input: `CREATE TABLE "users" ("id" UUID, FOREIGN KEY NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_INVALID_FOREIGN_KEY_OPEN_PAREN", input: `CREATE TABLE "users" ("id" UUID, FOREIGN KEY (NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_FOREIGN_KEY_IDENTS_INVALID", input: `CREATE TABLE "users" ("id" UUID, FOREIGN KEY ("group_id") NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_FOREIGN_KEY_IDENTS_REFERENCES_INVALID", input: `CREATE TABLE "users" ("id" UUID, FOREIGN KEY ("group_id") REFERENCES `, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_FOREIGN_KEY_IDENTS_REFERENCES_INVALID_IDENTS", input: `CREATE TABLE "users" ("id" UUID, FOREIGN KEY ("group_id") REFERENCES "groups" NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_FOREIGN_KEY_IDENTS_REFERENCES_INVALID_CLOSE_PAREN", input: `CREATE TABLE "users" ("id" UUID, FOREIGN KEY ("group_id") REFERENCES "groups" ("id")`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_FOREIGN_KEY_IDENTS_REFERENCES_ON_INVALID", input: `CREATE TABLE "users" ("id" UUID, FOREIGN KEY ("group_id") REFERENCES "groups" ("id") ON`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_FOREIGN_KEY_IDENTS_REFERENCES_ON_DELETE_INVALID", input: `CREATE TABLE "users" ("id" UUID, FOREIGN KEY ("group_id") REFERENCES "groups" ("id") ON DELETE`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_FOREIGN_KEY_IDENTS_REFERENCES_ON_DELETE_NO_INVALID", input: `CREATE TABLE "users" ("id" UUID, FOREIGN KEY ("group_id") REFERENCES "groups" ("id") ON DELETE NO`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_FOREIGN_KEY_IDENTS_REFERENCES_ON_DELETE_NO_INVALID", input: `CREATE TABLE "users" ("id" UUID, FOREIGN KEY ("group_id") REFERENCES "groups" ("id") ON DELETE NO ACTION`, - wantErr: ddl.ErrUnexpectedToken, - }, - { - name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_UNIQUE_INVALID", - input: `CREATE TABLE "users" ("id" UUID, UNIQUE NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { - name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_UNIQUE_INVALID", + name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_UNIQUE_NOT_INVALID", input: `CREATE TABLE "users" ("id" UUID, UNIQUE NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_UNIQUE_INVALID", input: `CREATE TABLE "users" ("id" UUID, UNIQUE;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_UNIQUE_COLUMN_INVALID", input: `CREATE TABLE "users" ("id" UUID, UNIQUE (;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_UNIQUE_IDENTS_INVALID", input: `CREATE TABLE "users" ("id" UUID, name TEXT, UNIQUE ("id", name)`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_INDEX_INVALID", input: `CREATE INDEX NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_INDEX_IF_INVALID", input: `CREATE INDEX IF;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_INDEX_IF_NOT_INVALID", input: `CREATE INDEX IF NOT;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_INDEX_IF_NOT_EXISTS_INVALID", input: `CREATE INDEX IF NOT EXISTS;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_INDEX_index_name_INVALID", input: `CREATE INDEX users_idx_username NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_INDEX_index_name_ON_INVALID", input: `CREATE INDEX users_idx_username ON NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_INDEX_index_name_ON_table_name_INVALID", input: `CREATE INDEX users_idx_username ON users NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_INDEX_index_name_ON_table_name_USING_INVALID", input: `CREATE INDEX users_idx_username ON users USING NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_INDEX_index_name_ON_table_name_USING_method_INVALID", input: `CREATE INDEX users_idx_username ON users USING btree NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_INDEX_index_name_ON_table_name_USING_method_OPEN_INVALID", input: `CREATE INDEX users_idx_username ON users USING btree (NOT)`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, } @@ -402,7 +397,7 @@ func TestParser_parseColumn(t *testing.T) { t.Parallel() _, _, err := NewParser(NewLexer(`NOT`)).parseColumn(&Ident{Name: "table_name", QuotationMark: `"`, Raw: `"table_name"`}) - require.ErrorIs(t, err, ddl.ErrUnexpectedToken) + require.ErrorIs(t, err, ddl.ErrUnexpectedCurrentToken) }) t.Run("failure,parseDataType", func(t *testing.T) { @@ -413,7 +408,7 @@ func TestParser_parseColumn(t *testing.T) { p.nextToken() p.nextToken() _, _, err := p.parseColumn(&Ident{Name: "table_name", QuotationMark: `"`, Raw: `"table_name"`}) - require.ErrorIs(t, err, ddl.ErrUnexpectedToken) + require.ErrorIs(t, err, ddl.ErrUnexpectedCurrentToken) }) } @@ -437,7 +432,7 @@ func TestParser_parseExpr(t *testing.T) { p.nextToken() p.nextToken() _, err := p.parseExpr() - require.ErrorIs(t, err, ddl.ErrUnexpectedToken) + require.ErrorIs(t, err, ddl.ErrUnexpectedCurrentToken) }) t.Run("failure,invalid2", func(t *testing.T) { @@ -447,7 +442,7 @@ func TestParser_parseExpr(t *testing.T) { p.nextToken() p.nextToken() _, err := p.parseExpr() - require.ErrorIs(t, err, ddl.ErrUnexpectedToken) + require.ErrorIs(t, err, ddl.ErrUnexpectedCurrentToken) }) } @@ -461,7 +456,7 @@ func TestParser_parseDataType(t *testing.T) { p.nextToken() p.nextToken() _, err := p.parseDataType() - require.ErrorIs(t, err, ddl.ErrUnexpectedToken) + require.ErrorIs(t, err, ddl.ErrUnexpectedPeekToken) }) t.Run("failure,TIMESTAMP_WITH_TIME_NOT", func(t *testing.T) { @@ -471,7 +466,7 @@ func TestParser_parseDataType(t *testing.T) { p.nextToken() p.nextToken() _, err := p.parseDataType() - require.ErrorIs(t, err, ddl.ErrUnexpectedToken) + require.ErrorIs(t, err, ddl.ErrUnexpectedPeekToken) }) t.Run("failure,DOUBLE_NOT", func(t *testing.T) { @@ -481,7 +476,7 @@ func TestParser_parseDataType(t *testing.T) { p.nextToken() p.nextToken() _, err := p.parseDataType() - require.ErrorIs(t, err, ddl.ErrUnexpectedToken) + require.ErrorIs(t, err, ddl.ErrUnexpectedPeekToken) }) t.Run("failure,DOUBLE_PRECISION", func(t *testing.T) { @@ -491,7 +486,7 @@ func TestParser_parseDataType(t *testing.T) { p.nextToken() p.nextToken() _, err := p.parseDataType() - require.ErrorIs(t, err, ddl.ErrUnexpectedToken) + require.ErrorIs(t, err, ddl.ErrUnexpectedCurrentToken) }) t.Run("failure,CHARACTER_NOT", func(t *testing.T) { @@ -501,7 +496,7 @@ func TestParser_parseDataType(t *testing.T) { p.nextToken() p.nextToken() _, err := p.parseDataType() - require.ErrorIs(t, err, ddl.ErrUnexpectedToken) + require.ErrorIs(t, err, ddl.ErrUnexpectedPeekToken) }) t.Run("failure,CHARACTER_VARYING_NOT", func(t *testing.T) { @@ -511,6 +506,6 @@ func TestParser_parseDataType(t *testing.T) { p.nextToken() p.nextToken() _, err := p.parseDataType() - require.ErrorIs(t, err, ddl.ErrUnexpectedToken) + require.ErrorIs(t, err, ddl.ErrUnexpectedCurrentToken) }) } diff --git a/pkg/ddl/spanner/parser_test.go b/pkg/ddl/spanner/parser_test.go index 29369e8..b5f404c 100644 --- a/pkg/ddl/spanner/parser_test.go +++ b/pkg/ddl/spanner/parser_test.go @@ -101,87 +101,87 @@ CREATE TABLE IF NOT EXISTS complex_defaults ( { name: "failure,invalid", input: `)invalid`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_INVALID", input: `CREATE INVALID;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_INVALID", input: `CREATE TABLE;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_IF_INVALID", input: `CREATE TABLE IF;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_TABLE_IF_NOT_INVALID", input: `CREATE TABLE IF NOT;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_TABLE_table_name_INVALID", input: `CREATE TABLE "users";`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_INVALID", input: `CREATE TABLE "users" ("id";`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_data_type_INVALID", input: `CREATE TABLE "users" ("id" STRING(36);`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_data_type_INVALID", input: `CREATE TABLE "users" ("id" STRING(36), enabled BOOL DEFAULT (FALSE);`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_data_type_INVALID", input: `CREATE TABLE "users" ("id" STRING(36), enabled BOOL DEFAULT (TRUE AND FALSE);`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_data_type_OPTIONS_INVALID", input: `CREATE TABLE "users" ("id" STRING(36), created_at TIMESTAMP OPTIONS (allow_commit_timestamp = true;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_INVALID", input: `CREATE TABLE "users" ("id" STRING(36), CONSTRAINT "invalid" NOT;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { - name: "failure,CREATE_TABLE_table_name_column_name_INVALID", + name: "failure,CREATE_TABLE_table_name_column_name_data_type__INVALID", input: `CREATE TABLE "users" ("id" STRING(36))(;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_COMMA_INVALID", input: `CREATE TABLE "users" ("id" TIMESTAMP CREATE`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_DATA_TYPE_INVALID", input: `CREATE TABLE "users" ("id" VARYING();`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_INVALID_NOT", input: `CREATE TABLE "users" ("id" STRING(36) NULL NOT;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_INVALID_DEFAULT", input: `CREATE TABLE "users" ("id" STRING(36) DEFAULT ("id")`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_INVALID_DEFAULT_OPEN_PAREN", @@ -196,7 +196,7 @@ CREATE TABLE IF NOT EXISTS complex_defaults ( { name: "failure,CREATE_TABLE_table_name_column_name_INVALID_REFERENCES", input: `CREATE TABLE "users" ("id" STRING(36) REFERENCES NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_INVALID_REFERENCES_IDENTS", @@ -206,148 +206,148 @@ CREATE TABLE IF NOT EXISTS complex_defaults ( { name: "failure,CREATE_TABLE_table_name_column_name_INVALID_CHECK", input: `CREATE TABLE "users" ("id" STRING(36) CHECK NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CHECK_INVALID_IDENTS", input: `CREATE TABLE "users" ("id" STRING(36) CHECK (NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_INVALID_IDENT", input: `CREATE TABLE "users" ("id" STRING(36), CONSTRAINT NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_CHECK_INVALID", input: `CREATE TABLE "users" ("id" STRING(36), CONSTRAINT constraint_name CHECK`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_CHECK_OPEN_INVALID", input: `CREATE TABLE "users" ("id" STRING(36), CONSTRAINT constraint_name CHECK (`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_INVALID_PRIMARY", input: `CREATE TABLE "users" ("id" STRING(36)) PRIMARY NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_OPTION_PRIMARY_KEY_INVALID", input: `CREATE TABLE "users" ("id" STRING(36)) PRIMARY KEY NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_OPTION_PRIMARY_KEY_OPEN_PAREN_INVALID", input: `CREATE TABLE "users" ("id" STRING(36)) PRIMARY KEY (NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_OPTION_PRIMARY_KEY_OPEN_PAREN_column_name_INVALID", input: `CREATE TABLE "users" ("id" STRING(36)) PRIMARY KEY (id`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_OPTION_PRIMARY_KEY_INTERLEAVE_INVALID", input: `CREATE TABLE "users" ("id" STRING(36)) PRIMARY KEY (id), INTERLEAVE;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_OPTION_PRIMARY_KEY_INTERLEAVE_IN_INVALID", input: `CREATE TABLE "users" ("id" STRING(36)) PRIMARY KEY (id), INTERLEAVE IN;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_OPTION_PRIMARY_KEY_INTERLEAVE_IN_PARENT_INVALID", input: `CREATE TABLE "users" ("id" STRING(36)) PRIMARY KEY (id), INTERLEAVE IN PARENT;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_OPTION_PRIMARY_KEY_INTERLEAVE_IN_PARENT_ON_INVALID", input: `CREATE TABLE "users" ("id" STRING(36)) PRIMARY KEY (id), INTERLEAVE IN PARENT table_name ON;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_OPTION_PRIMARY_KEY_INTERLEAVE_IN_PARENT_ON_DELETE_INVALID", input: `CREATE TABLE "users" ("id" STRING(36)) PRIMARY KEY (id), INTERLEAVE IN PARENT table_name ON DELETE;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_OPTION_PRIMARY_KEY_INTERLEAVE_IN_PARENT_ON_DELETE_CASCADE_INVALID", input: `CREATE TABLE "users" ("id" STRING(36)) PRIMARY KEY (id), INTERLEAVE IN PARENT table_name ON DELETE CASCADE NOT;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_OPTION_PRIMARY_KEY_INTERLEAVE_IN_PARENT_ON_DELETE_NO_INVALID", input: `CREATE TABLE "users" ("id" STRING(36)) PRIMARY KEY (id), INTERLEAVE IN PARENT table_name ON DELETE NO;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, // ROW DELETION POLICY (OLDER_THAN(ExpiredDate, INTERVAL 0 DAY)); { name: "failure,CREATE_TABLE_table_name_column_name_OPTION_PRIMARY_KEY_ROW_INVALID", input: `CREATE TABLE "users" ("id" STRING(36)) PRIMARY KEY (id), ROW;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_OPTION_PRIMARY_KEY_ROW_DELETION_INVALID", input: `CREATE TABLE "users" ("id" STRING(36)) PRIMARY KEY (id), ROW DELETION;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_OPTION_PRIMARY_KEY_ROW_DELETION_POLICY_INVALID", input: `CREATE TABLE "users" ("id" STRING(36)) PRIMARY KEY (id), ROW DELETION POLICY;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_OPTION_PRIMARY_KEY_ROW_DELETION_POLICY_(_INVALID", input: `CREATE TABLE "users" ("id" STRING(36)) PRIMARY KEY (id), ROW DELETION POLICY (;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_OPTION_PRIMARY_KEY_ROW_DELETION_POLICY_(_INVALID", input: `CREATE TABLE "users" ("id" STRING(36)) PRIMARY KEY (id), ROW DELETION POLICY (;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_OPTION_PRIMARY_KEY_ROW_DELETION_POLICY_OLDER_THAN_INVALID", input: `CREATE TABLE "users" ("id" STRING(36)) PRIMARY KEY (id), ROW DELETION POLICY (OLDER_THAN;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_OPTION_PRIMARY_KEY_ROW_DELETION_POLICY_OLDER_THAN_OPEN_INVALID", input: `CREATE TABLE "users" ("id" STRING(36)) PRIMARY KEY (id), ROW DELETION POLICY (OLDER_THAN(;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_OPTION_PRIMARY_KEY_ROW_DELETION_POLICY_OLDER_THAN_OPEN_column_name_INVALID", input: `CREATE TABLE "users" ("id" STRING(36)) PRIMARY KEY (id), ROW DELETION POLICY (OLDER_THAN(ExpiredDate;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_OPTION_PRIMARY_KEY_ROW_DELETION_POLICY_OLDER_THAN_OPEN_column_name_COMMA_INVALID", input: `CREATE TABLE "users" ("id" STRING(36)) PRIMARY KEY (id), ROW DELETION POLICY (OLDER_THAN(ExpiredDate,;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_OPTION_PRIMARY_KEY_ROW_DELETION_POLICY_OLDER_THAN_OPEN_column_name_COMMA_INTERVAL_INVALID", input: `CREATE TABLE "users" ("id" STRING(36)) PRIMARY KEY (id), ROW DELETION POLICY (OLDER_THAN(ExpiredDate, INTERVAL;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_OPTION_PRIMARY_KEY_ROW_DELETION_POLICY_OLDER_THAN_OPEN_column_name_COMMA_INTERVAL_NUMBER_INVALID", input: `CREATE TABLE "users" ("id" STRING(36)) PRIMARY KEY (id), ROW DELETION POLICY (OLDER_THAN(ExpiredDate, INTERVAL 0;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_OPTION_PRIMARY_KEY_ROW_DELETION_POLICY_OLDER_THAN_OPEN_column_name_COMMA_INTERVAL_NUMBER_DAY_INVALID", input: `CREATE TABLE "users" ("id" STRING(36)) PRIMARY KEY (id), ROW DELETION POLICY (OLDER_THAN(ExpiredDate, INTERVAL 0 DAY;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_OPTION_PRIMARY_KEY_ROW_DELETION_POLICY_OLDER_THAN_OPEN_column_name_COMMA_INTERVAL_NUMBER_DAY_CLOSE_INVALID", input: `CREATE TABLE "users" ("id" STRING(36)) PRIMARY KEY (id), ROW DELETION POLICY (OLDER_THAN(ExpiredDate, INTERVAL 0 DAY);`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_INVALID_FOREIGN", @@ -357,42 +357,37 @@ CREATE TABLE IF NOT EXISTS complex_defaults ( { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_INVALID_FOREIGN_KEY", input: `CREATE TABLE "users" ("id" STRING(36), FOREIGN KEY NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_INVALID_FOREIGN_KEY_OPEN_PAREN", input: `CREATE TABLE "users" ("id" STRING(36), FOREIGN KEY (NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_FOREIGN_KEY_IDENTS_INVALID", input: `CREATE TABLE "users" ("id" STRING(36), FOREIGN KEY ("group_id") NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_FOREIGN_KEY_IDENTS_REFERENCES_INVALID", input: `CREATE TABLE "users" ("id" STRING(36), FOREIGN KEY ("group_id") REFERENCES `, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_FOREIGN_KEY_IDENTS_REFERENCES_INVALID_IDENTS", input: `CREATE TABLE "users" ("id" STRING(36), FOREIGN KEY ("group_id") REFERENCES "groups" NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_FOREIGN_KEY_IDENTS_REFERENCES_INVALID_CLOSE_PAREN", input: `CREATE TABLE "users" ("id" STRING(36), FOREIGN KEY ("group_id") REFERENCES "groups" ("id")`, - wantErr: ddl.ErrUnexpectedToken, - }, - { - name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_UNIQUE_INVALID", - input: `CREATE TABLE "users" ("id" STRING(36), UNIQUE NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_UNIQUE_INVALID", input: `CREATE TABLE "users" ("id" STRING(36), UNIQUE NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_UNIQUE_INDEX_INVALID", @@ -402,67 +397,67 @@ CREATE TABLE IF NOT EXISTS complex_defaults ( { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_UNIQUE_INDEX_COLUMN_INVALID", input: `CREATE TABLE "users" ("id" STRING(36), UNIQUE INDEX users_idx_name (NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { - name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_UNIQUE_INVALID", + name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_UNIQUE_INDEX_INVALID", input: `CREATE TABLE "users" ("id" STRING(36), UNIQUE INDEX NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_TABLE_table_name_column_name_CONSTRAINT_UNIQUE_IDENTS_INVALID", input: `CREATE TABLE "users" ("id" STRING(36), name STRING, UNIQUE ("id", name)`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_INDEX_INVALID", input: `CREATE INDEX NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_INDEX_IF_INVALID", input: `CREATE INDEX IF;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_INDEX_IF_NOT_INVALID", input: `CREATE INDEX IF NOT;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedPeekToken, }, { name: "failure,CREATE_INDEX_IF_NOT_EXISTS_INVALID", input: `CREATE INDEX IF NOT EXISTS;`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_INDEX_index_name_INVALID", input: `CREATE INDEX users_idx_username NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_INDEX_index_name_ON_INVALID", input: `CREATE INDEX users_idx_username ON NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_INDEX_index_name_ON_table_name_INVALID", input: `CREATE INDEX users_idx_username ON users NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_INDEX_index_name_ON_table_name_USING_INVALID", input: `CREATE INDEX users_idx_username ON users USING NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_INDEX_index_name_ON_table_name_USING_method_INVALID", input: `CREATE INDEX users_idx_username ON users USING btree NOT`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, { name: "failure,CREATE_INDEX_index_name_ON_table_name_USING_method_OPEN_INVALID", input: `CREATE INDEX users_idx_username ON users USING btree (NOT)`, - wantErr: ddl.ErrUnexpectedToken, + wantErr: ddl.ErrUnexpectedCurrentToken, }, } @@ -499,7 +494,7 @@ func TestParser_parseColumn(t *testing.T) { t.Parallel() _, _, err := NewParser(NewLexer(`NOT`)).parseColumn(&Ident{Name: "table_name", QuotationMark: `"`, Raw: `"table_name"`}) - require.ErrorIs(t, err, ddl.ErrUnexpectedToken) + require.ErrorIs(t, err, ddl.ErrUnexpectedCurrentToken) }) t.Run("failure,parseDataType", func(t *testing.T) { @@ -510,7 +505,7 @@ func TestParser_parseColumn(t *testing.T) { p.nextToken() p.nextToken() _, _, err := p.parseColumn(&Ident{Name: "table_name", QuotationMark: `"`, Raw: `"table_name"`}) - require.ErrorIs(t, err, ddl.ErrUnexpectedToken) + require.ErrorIs(t, err, ddl.ErrUnexpectedCurrentToken) }) } @@ -539,7 +534,7 @@ func TestParser_parseExpr(t *testing.T) { p.nextToken() p.nextToken() _, err := p.parseExpr() - require.ErrorIs(t, err, ddl.ErrUnexpectedToken) + require.ErrorIs(t, err, ddl.ErrUnexpectedCurrentToken) }) t.Run("failure,invalid2", func(t *testing.T) { @@ -549,7 +544,7 @@ func TestParser_parseExpr(t *testing.T) { p.nextToken() p.nextToken() _, err := p.parseExpr() - require.ErrorIs(t, err, ddl.ErrUnexpectedToken) + require.ErrorIs(t, err, ddl.ErrUnexpectedCurrentToken) }) } @@ -563,6 +558,6 @@ func TestParser_parseDataType(t *testing.T) { p.nextToken() p.nextToken() _, err := p.parseDataType() - require.ErrorIs(t, err, ddl.ErrUnexpectedToken) + require.ErrorIs(t, err, ddl.ErrUnexpectedCurrentToken) }) }