2016-03-31 03:09:35 +00:00
|
|
|
// © 2013 the CatBase Authors under the WTFPL. See AUTHORS for the list of authors.
|
|
|
|
|
|
|
|
package leftpad
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/velour/catbase/bot"
|
2016-04-01 14:20:03 +00:00
|
|
|
"github.com/velour/catbase/bot/msg"
|
|
|
|
"github.com/velour/catbase/bot/user"
|
2016-03-31 03:09:35 +00:00
|
|
|
"github.com/velour/catbase/plugins/counter"
|
|
|
|
)
|
|
|
|
|
2016-04-01 14:20:03 +00:00
|
|
|
func makeMessage(payload string) msg.Message {
|
2016-03-31 03:09:35 +00:00
|
|
|
isCmd := strings.HasPrefix(payload, "!")
|
|
|
|
if isCmd {
|
|
|
|
payload = payload[1:]
|
|
|
|
}
|
2016-04-01 14:20:03 +00:00
|
|
|
return msg.Message{
|
|
|
|
User: &user.User{Name: "tester"},
|
2016-03-31 03:09:35 +00:00
|
|
|
Channel: "test",
|
|
|
|
Body: payload,
|
|
|
|
Command: isCmd,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func makePlugin(t *testing.T) (*LeftpadPlugin, *bot.MockBot) {
|
|
|
|
mb := bot.NewMockBot()
|
|
|
|
counter.New(mb)
|
|
|
|
p := New(mb)
|
|
|
|
assert.NotNil(t, p)
|
|
|
|
return p, mb
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLeftpad(t *testing.T) {
|
|
|
|
p, mb := makePlugin(t)
|
|
|
|
p.Message(makeMessage("!leftpad test 8 test"))
|
|
|
|
assert.Contains(t, mb.Messages[0], "testtest")
|
|
|
|
assert.Len(t, mb.Messages, 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBadNumber(t *testing.T) {
|
|
|
|
p, mb := makePlugin(t)
|
|
|
|
p.Message(makeMessage("!leftpad test fuck test"))
|
|
|
|
assert.Contains(t, mb.Messages[0], "Invalid")
|
|
|
|
assert.Len(t, mb.Messages, 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNotCommand(t *testing.T) {
|
|
|
|
p, mb := makePlugin(t)
|
|
|
|
p.Message(makeMessage("leftpad test fuck test"))
|
|
|
|
assert.Len(t, mb.Messages, 0)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNotPadding(t *testing.T) {
|
|
|
|
p, mb := makePlugin(t)
|
|
|
|
p.Message(makeMessage("!lololol"))
|
|
|
|
assert.Len(t, mb.Messages, 0)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestHelp(t *testing.T) {
|
|
|
|
p, mb := makePlugin(t)
|
|
|
|
p.Help("channel", []string{})
|
|
|
|
assert.Len(t, mb.Messages, 0)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBotMessage(t *testing.T) {
|
|
|
|
p, _ := makePlugin(t)
|
|
|
|
assert.False(t, p.BotMessage(makeMessage("test")))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestEvent(t *testing.T) {
|
|
|
|
p, _ := makePlugin(t)
|
|
|
|
assert.False(t, p.Event("dummy", makeMessage("test")))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRegisterWeb(t *testing.T) {
|
|
|
|
p, _ := makePlugin(t)
|
|
|
|
assert.Nil(t, p.RegisterWeb())
|
|
|
|
}
|