41 lines
948 B
Go
41 lines
948 B
Go
package bot
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestParse(t *testing.T) {
|
|
cases := []struct {
|
|
in string
|
|
command string
|
|
args []string
|
|
}{
|
|
{"/status", "/status", []string{}},
|
|
{"/Status@meu_bot", "/status", []string{}},
|
|
{" /ativarusuario 42 ", "/ativarusuario", []string{"42"}},
|
|
{"oi", "", nil},
|
|
{"", "", nil},
|
|
}
|
|
for _, c := range cases {
|
|
command, args := parse(c.in)
|
|
if command != c.command {
|
|
t.Errorf("parse(%q) comando = %q, esperado %q", c.in, command, c.command)
|
|
}
|
|
if c.args != nil && !reflect.DeepEqual(args, c.args) {
|
|
t.Errorf("parse(%q) args = %v, esperado %v", c.in, args, c.args)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestParseID(t *testing.T) {
|
|
if id, ok := parseID([]string{"42"}); !ok || id != 42 {
|
|
t.Errorf("parseID(42) = %d, %v", id, ok)
|
|
}
|
|
for _, invalid := range [][]string{nil, {"abc"}, {"-1"}, {"1", "2"}} {
|
|
if _, ok := parseID(invalid); ok {
|
|
t.Errorf("parseID(%v) deveria falhar", invalid)
|
|
}
|
|
}
|
|
}
|