diff --git a/plugins/picker/picker.go b/plugins/picker/picker.go index 284f86e..53b5f4b 100644 --- a/plugins/picker/picker.go +++ b/plugins/picker/picker.go @@ -63,7 +63,7 @@ func (p *PickerPlugin) Message(message msg.Message) bool { 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 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") } - n := 0 + n := 1 var err error if subs[1] != "" { n, err = strconv.Atoi(subs[1]) diff --git a/plugins/picker/picker_test.go b/plugins/picker/picker_test.go index 661f5a7..0c2dd60 100644 --- a/plugins/picker/picker_test.go +++ b/plugins/picker/picker_test.go @@ -25,7 +25,7 @@ func makeMessage(payload string) msg.Message { } } -func TestReplacement(t *testing.T) { +func TestPick2(t *testing.T) { mb := bot.NewMockBot() c := New(mb) assert.NotNil(t, c) @@ -35,3 +35,12 @@ func TestReplacement(t *testing.T) { 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]) +}