Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions regression_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package sqltoken_test

import (
"testing"
"time"

"github.com/muir/sqltoken"
)

var stripSplitCases = []struct {
name string
input string
}{
{
name: "xopmigrations",
input: `
CREATE TABEL IF NOT EXISTS name_ids (
name_id bitint NOT NULL AUTO_INCREMENT,
name text NOT NULL,
index_span bool NOT NULL,
index_request bool NOT NULL,
status tinyint NOT NULL, -- 0
SHARD KEY (name),
PRIMARY KEY (name),
KEY (name_id)
);
`,
},
}

func TestRegressionStripSplit(t *testing.T) {
for _, tc := range stripSplitCases {
t.Run(tc.name, func(t *testing.T) {
done := make(chan struct{})
timer := time.AfterFunc(time.Second*2, func() {
t.Log("timeout!")
close(done)
t.FailNow()
})
go func() {
tokenized := sqltoken.TokenizeMySQL(tc.input)
t.Log("tokenized")
stripped := tokenized.Strip()
t.Log("stripped")
_ = stripped.CmdSplit()
t.Log("split")
timer.Stop()
close(done)
}()
<-done
})
}
}
3 changes: 1 addition & 2 deletions tokenize.go
Original file line number Diff line number Diff line change
Expand Up @@ -1164,7 +1164,7 @@ func (ts Tokens) Strip() Tokens {
}
c := make(Tokens, 0, len(ts))
var lastReal int
for i < len(ts) {
for ; i < len(ts); i++ {
// nolint:exhaustive
switch ts[i].Type {
case Comment:
Expand All @@ -1180,7 +1180,6 @@ func (ts Tokens) Strip() Tokens {
c = append(c, ts[i])
lastReal = len(c)
}
i++
}
c = c[:lastReal]
return c
Expand Down