mirror of https://github.com/velour/catbase.git
Proper handling of the default pick quantity
This commit is contained in:
parent
ce91370313
commit
96a887917a
|
@ -63,7 +63,7 @@ func (p *PickerPlugin) Message(message msg.Message) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
var pickerListPrologue = regexp.MustCompile(`^pick[ \t]+([0-9]*)[ \t]+\{[ \t]*`)
|
var pickerListPrologue = regexp.MustCompile(`^pick[ \t]+([0-9]*)[ \t]*\{[ \t]*`)
|
||||||
var pickerListItem = regexp.MustCompile(`^([^,]+),[ \t]*`)
|
var pickerListItem = regexp.MustCompile(`^([^,]+),[ \t]*`)
|
||||||
var pickerListFinalItem = regexp.MustCompile(`^([^,}]+),?[ \t]*\}[ \t]*`)
|
var pickerListFinalItem = regexp.MustCompile(`^([^,}]+),?[ \t]*\}[ \t]*`)
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ func (p *PickerPlugin) parse(body string) (int, []string, error) {
|
||||||
return 0, nil, errors.New("saddle up for a syntax error")
|
return 0, nil, errors.New("saddle up for a syntax error")
|
||||||
}
|
}
|
||||||
|
|
||||||
n := 0
|
n := 1
|
||||||
var err error
|
var err error
|
||||||
if subs[1] != "" {
|
if subs[1] != "" {
|
||||||
n, err = strconv.Atoi(subs[1])
|
n, err = strconv.Atoi(subs[1])
|
||||||
|
|
|
@ -25,7 +25,7 @@ func makeMessage(payload string) msg.Message {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestReplacement(t *testing.T) {
|
func TestPick2(t *testing.T) {
|
||||||
mb := bot.NewMockBot()
|
mb := bot.NewMockBot()
|
||||||
c := New(mb)
|
c := New(mb)
|
||||||
assert.NotNil(t, c)
|
assert.NotNil(t, c)
|
||||||
|
@ -35,3 +35,12 @@ func TestReplacement(t *testing.T) {
|
||||||
t.Fatalf("expected a successful choice, got %q", mb.Messages[0])
|
t.Fatalf("expected a successful choice, got %q", mb.Messages[0])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPickDefault(t *testing.T) {
|
||||||
|
mb := bot.NewMockBot()
|
||||||
|
c := New(mb)
|
||||||
|
assert.NotNil(t, c)
|
||||||
|
_ = c.Message(makeMessage("!pick { a}"))
|
||||||
|
assert.Len(t, mb.Messages, 1)
|
||||||
|
assert.Equal(t, `I've chosen "a" for you.`, mb.Messages[0])
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue