Add test for SplitCommandAndArgs
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
043738668b
commit
d3b95c693b
@ -102,6 +102,10 @@ func ContainsCommand(s, prefix, cmd string) bool {
|
||||
func SplitCommandAndArgs(s, prefix string) (cmd string, args []string) {
|
||||
s = strings.TrimSpace(s)
|
||||
|
||||
if !strings.HasPrefix(s, prefix) {
|
||||
return
|
||||
}
|
||||
|
||||
x := strings.Split(s, " ")
|
||||
|
||||
if len(x) > 1 {
|
||||
|
@ -53,3 +53,26 @@ func TestHasCommandCommand(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSplitComandAndArgs(t *testing.T) {
|
||||
tables := []struct {
|
||||
s string
|
||||
prefix string
|
||||
wantCmd string
|
||||
wantArgs []string
|
||||
}{
|
||||
{"!command x y", "!", "command", []string{"x", "y"}},
|
||||
{"!command", "!", "command", []string(nil)},
|
||||
{"hey man", "!", "", []string(nil)},
|
||||
}
|
||||
|
||||
for _, table := range tables {
|
||||
gotCmd, gotArgs := SplitCommandAndArgs(table.s, table.prefix)
|
||||
if gotCmd != table.wantCmd {
|
||||
t.Errorf("got: %s, want: %s", gotCmd, table.wantCmd)
|
||||
}
|
||||
if !reflect.DeepEqual(gotArgs, table.wantArgs) {
|
||||
t.Errorf("got: %+v, want: %+v", gotArgs, table.wantArgs)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user