catbase/plugins/couldashouldawoulda/csw_test.go

139 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"
2021-02-04 00:51:14 +00:00
2018-06-16 21:25:33 +00:00
"github.com/velour/catbase/bot"
"github.com/velour/catbase/bot/msg"
"github.com/velour/catbase/bot/user"
)
2021-02-04 00:51:14 +00:00
func makeMessage(payload string) bot.Request {
2018-06-16 21:25:33 +00:00
isCmd := strings.HasPrefix(payload, "!")
if isCmd {
payload = payload[1:]
}
2021-02-04 00:51:14 +00:00
return bot.Request{
Kind: bot.Message,
Msg: msg.Message{
User: &user.User{Name: "tester"},
Channel: "test",
Body: payload,
Command: isCmd,
},
2018-06-16 21:25:33 +00:00
}
}
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)
}