From ae3a4eee5207064322eec74d62fee2f362ae7f32 Mon Sep 17 00:00:00 2001 From: svohr Date: Mon, 20 Feb 2017 11:57:12 -0800 Subject: [PATCH 1/2] Fixed tea regex to fix bad matches that ended in iced Added a test based on skiesel's quote that triggered it. --- plugins/counter/counter.go | 2 +- plugins/counter/counter_test.go | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/plugins/counter/counter.go b/plugins/counter/counter.go index 64b78a3..be83296 100644 --- a/plugins/counter/counter.go +++ b/plugins/counter/counter.go @@ -136,7 +136,7 @@ func (p *CounterPlugin) Message(message msg.Message) bool { return false } - if tea, _ := regexp.MatchString("(?i)^tea\\. [0-9A-Za-z_ ]*\\. (hot)|(iced)\\.?$", message.Body); tea { + if tea, _ := regexp.MatchString("(?i)^tea\\. [0-9A-Za-z_ ]*\\. ((hot)|(iced))\\.?$", message.Body); tea { item, err := GetItem(p.DB, nick, "🍵") if err != nil { log.Printf("Error finding item %s.%s: %s.", nick, "🍵", err) diff --git a/plugins/counter/counter_test.go b/plugins/counter/counter_test.go index 1ac2bb3..4911c92 100644 --- a/plugins/counter/counter_test.go +++ b/plugins/counter/counter_test.go @@ -60,6 +60,16 @@ func TestTeaUnrelated(t *testing.T) { assert.Equal(t, 0, item.Count) } +func TestTeaSkieselQuote(t *testing.T) { + mb := bot.NewMockBot() + c := New(mb) + assert.NotNil(t, c) + c.Message(makeMessage("blah, this is a whole page of explanation where \"we did local search and used a tabu list\" would have sufficed")) + item, err := GetItem(mb.DB(), "tester", "🍵") + assert.Nil(t, err) + assert.Equal(t, 0, item.Count) +} + func TestResetMe(t *testing.T) { mb := bot.NewMockBot() c := New(mb) From 39d5dec69413fb723f5912d29a08962cbaef45e3 Mon Sep 17 00:00:00 2001 From: svohr Date: Mon, 20 Feb 2017 12:19:49 -0800 Subject: [PATCH 2/2] =?UTF-8?q?Updated=20tea=20test=20to=20replace=20?= =?UTF-8?q?=F0=9F=8D=B5=20with=20:tea:?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/counter/counter_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/counter/counter_test.go b/plugins/counter/counter_test.go index 4911c92..b0b233a 100644 --- a/plugins/counter/counter_test.go +++ b/plugins/counter/counter_test.go @@ -32,7 +32,7 @@ func TestTeaEarlGreyHot(t *testing.T) { assert.NotNil(t, c) c.Message(makeMessage("Tea. Earl Grey. Hot.")) c.Message(makeMessage("Tea. Earl Grey. Hot.")) - item, err := GetItem(mb.DB(), "tester", "🍵") + item, err := GetItem(mb.DB(), "tester", ":tea:") assert.Nil(t, err) assert.Equal(t, 2, item.Count) } @@ -44,7 +44,7 @@ func TestTeaGreenHot(t *testing.T) { c.Message(makeMessage("Tea. Green. Hot.")) c.Message(makeMessage("Tea. Green. Hot")) c.Message(makeMessage("Tea. Green. Iced.")) - item, err := GetItem(mb.DB(), "tester", "🍵") + item, err := GetItem(mb.DB(), "tester", ":tea:") assert.Nil(t, err) assert.Equal(t, 3, item.Count) } @@ -55,7 +55,7 @@ func TestTeaUnrelated(t *testing.T) { assert.NotNil(t, c) c.Message(makeMessage("Tea.")) c.Message(makeMessage("Tea. It's great.")) - item, err := GetItem(mb.DB(), "tester", "🍵") + item, err := GetItem(mb.DB(), "tester", ":tea:") assert.Nil(t, err) assert.Equal(t, 0, item.Count) } @@ -65,7 +65,7 @@ func TestTeaSkieselQuote(t *testing.T) { c := New(mb) assert.NotNil(t, c) c.Message(makeMessage("blah, this is a whole page of explanation where \"we did local search and used a tabu list\" would have sufficed")) - item, err := GetItem(mb.DB(), "tester", "🍵") + item, err := GetItem(mb.DB(), "tester", ":tea:") assert.Nil(t, err) assert.Equal(t, 0, item.Count) }