Skip to content
Closed
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
1 change: 1 addition & 0 deletions pkg/sqlcmd/batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func TestBatchNext(t *testing.T) {
{"exit_1", []string{"exit_1"}, nil, "-"},
{"print ('me\n!!me')", []string{"print ('me" + SqlcmdEol + "!!me')"}, nil, "-"},
{"/*comment\n!!me*/", []string{"/*comment" + SqlcmdEol + "!!me*/"}, nil, "-"},
{"select 1\nGO\t\t", []string{"select 1"}, []string{"GO"}, "-"},
}
for _, test := range tests {
b := NewBatch(sp(test.s, "\n"), newCommands())
Expand Down
2 changes: 1 addition & 1 deletion pkg/sqlcmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func errorDisabled(s *Sqlcmd, args []string, line uint) error {
}

func batchTerminatorRegex(terminator string) string {
return fmt.Sprintf(`(?im)^[\t ]*?%s(?:[ ]+(.*$)|$)`, regexp.QuoteMeta(terminator))
return fmt.Sprintf(`(?im)^[\t ]*?%s(?:[\t ]+(.*$)|$)`, regexp.QuoteMeta(terminator))
}

// SetBatchTerminator attempts to set the batch terminator to the given value
Expand Down
8 changes: 8 additions & 0 deletions pkg/sqlcmd/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ func TestCommandParsing(t *testing.T) {
{`:XML ON `, "XML", []string{`ON `}},
{`:RESET`, "RESET", []string{""}},
{`RESET`, "RESET", []string{""}},
{"GO", "GO", []string{""}},
{"GO\t\t", "GO", []string{""}},
{"go\t5", "GO", []string{"5"}},
{" \tGO \t 5", "GO", []string{"5"}},
}

for _, test := range commands {
Expand Down Expand Up @@ -130,6 +134,10 @@ func TestCustomBatchSeparator(t *testing.T) {
assert.Equal(t, "GO", cmd.name, "command name")
assert.Equal(t, "5", strings.TrimSpace(args[0]), "go argument")
}
cmd, args = c.matchCommand("me!\t5")
if assert.NotNil(t, cmd, "matchCommand didn't find custom batch separator followed by a tab") {
assert.Equal(t, "5", strings.TrimSpace(args[0]), "go argument")
}
}
}

Expand Down