catbase/plugins/couldashouldawoulda/csw_test.go

135 lines
3.4 KiB
Go
Raw Normal View History

2018-06-16 21:25:33 +00:00
// © 2013 the CatBase Authors under the WTFPL. See AUTHORS for the list of authors.
package couldashouldawoulda
import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/velour/catbase/bot"
"github.com/velour/catbase/bot/msg"
"github.com/velour/catbase/bot/user"
)
2019-02-05 20:02:15 +00:00
func makeMessage(payload string) (bot.Kind, msg.Message) {
2018-06-16 21:25:33 +00:00
isCmd := strings.HasPrefix(payload, "!")
if isCmd {
payload = payload[1:]
}
2019-02-05 20:02:15 +00:00
return bot.Message, msg.Message{
2018-06-16 21:25:33 +00:00
User: &user.User{Name: "tester"},
Channel: "test",
Body: payload,
Command: isCmd,
}
}
func Test0(t *testing.T) {
mb := bot.NewMockBot()
c := New(mb)
assert.NotNil(t, c)
2019-02-05 20:02:15 +00:00
res := c.message(makeMessage("!should I drink a beer?"))
2018-06-16 21:25:33 +00:00
assert.Len(t, mb.Messages, 1)
assert.True(t, res)
possibilities := []string{"Yes.", "No.", "Maybe.", "For fucks sake, how should I know?"}
match := false
for _, possibility := range possibilities {
if strings.Contains(mb.Messages[0], possibility) {
match = true
break
}
}
assert.True(t, match)
}
func Test1(t *testing.T) {
mb := bot.NewMockBot()
c := New(mb)
assert.NotNil(t, c)
2019-02-05 20:02:15 +00:00
res := c.message(makeMessage("!should I drink a beer or a bourbon?"))
2018-06-16 21:25:33 +00:00
assert.Len(t, mb.Messages, 1)
assert.True(t, res)
possibilities := []string{"The former.", "The latter.", "Obviously the former.", "Clearly the latter.", "Can't it be both?"}
match := false
for _, possibility := range possibilities {
if strings.Contains(mb.Messages[0], possibility) {
match = true
break
}
}
assert.True(t, match)
}
func Test2(t *testing.T) {
mb := bot.NewMockBot()
c := New(mb)
assert.NotNil(t, c)
2019-02-05 20:02:15 +00:00
res := c.message(makeMessage("!could I drink a beer or a bourbon?"))
2018-06-16 21:25:33 +00:00
assert.Len(t, mb.Messages, 1)
assert.True(t, res)
possibilities := []string{"Yes.", "No.", "Maybe.", "For fucks sake, how should I know?"}
match := false
for _, possibility := range possibilities {
if strings.Contains(mb.Messages[0], possibility) {
match = true
break
}
}
assert.True(t, match)
}
func Test3(t *testing.T) {
mb := bot.NewMockBot()
c := New(mb)
assert.NotNil(t, c)
2019-02-05 20:02:15 +00:00
res := c.message(makeMessage("!would I die if I drank too much bourbon?"))
2018-06-16 21:25:33 +00:00
assert.Len(t, mb.Messages, 1)
assert.True(t, res)
possibilities := []string{"Yes.", "No.", "Maybe.", "For fucks sake, how should I know?"}
match := false
for _, possibility := range possibilities {
if strings.Contains(mb.Messages[0], possibility) {
match = true
break
}
}
assert.True(t, match)
}
func Test4(t *testing.T) {
mb := bot.NewMockBot()
c := New(mb)
assert.NotNil(t, c)
2019-02-05 20:02:15 +00:00
res := c.message(makeMessage("!would I die or be sick if I drank all the bourbon?"))
2018-06-16 21:25:33 +00:00
assert.Len(t, mb.Messages, 1)
assert.True(t, res)
possibilities := []string{"The former.", "The latter.", "Obviously the former.", "Clearly the latter.", "Can't it be both?"}
match := false
for _, possibility := range possibilities {
if strings.Contains(mb.Messages[0], possibility) {
match = true
break
}
}
assert.True(t, match)
}
func Test5(t *testing.T) {
mb := bot.NewMockBot()
c := New(mb)
assert.NotNil(t, c)
2019-02-05 20:02:15 +00:00
res := c.message(makeMessage("!should I have another beer or bourbon or tequila?"))
2018-06-16 21:25:33 +00:00
assert.Len(t, mb.Messages, 1)
assert.True(t, res)
possibilities := []string{"I'd say option", "You'd be an idiot not to choose the"}
match := false
for _, possibility := range possibilities {
if strings.Contains(mb.Messages[0], possibility) {
match = true
break
}
}
assert.True(t, match)
}