Review: Added names to testcases and cleaned up.

This commit is contained in:
Patrick Connolly
2018-11-26 12:34:58 +08:00
parent adb02771c6
commit db6093b646

View File

@@ -7,22 +7,23 @@ import (
) )
func TestExtractTopicOrPurpose(t *testing.T) { func TestExtractTopicOrPurpose(t *testing.T) {
testcases := []struct { testcases := map[string]struct {
input string input string
wantChangeType string wantChangeType string
wantOutput string wantOutput string
}{ }{
{"@someone set channel topic: one liner", "topic", "one liner"}, "success - topic type": {"@someone set channel topic: foo bar", "topic", "foo bar"},
{"@someone set channel purpose: one liner", "purpose", "one liner"}, "success - purpose type": {"@someone set channel purpose: foo bar", "purpose", "foo bar"},
{"@someone set channel topic: multi\nliner", "topic", "multi\nliner"}, "success - one line": {"@someone set channel topic: foo bar", "topic", "foo bar"},
{"@someone cleared channel topic", "topic", ""}, "success - multi-line": {"@someone set channel topic: foo\nbar", "topic", "foo\nbar"},
{"some unmatched message", "unknown", ""}, "success - cleared": {"@someone cleared channel topic", "topic", ""},
"error - unhandled": {"some unmatched message", "unknown", ""},
} }
for _, tc := range testcases { for name, tc := range testcases {
gotChangeType, gotOutput := extractTopicOrPurpose(tc.input) gotChangeType, gotOutput := extractTopicOrPurpose(tc.input)
assert.Equal(t, tc.wantChangeType, gotChangeType) assert.Equal(t, tc.wantChangeType, gotChangeType, "This testcase failed: " + name)
assert.Equal(t, tc.wantOutput, gotOutput) assert.Equal(t, tc.wantOutput, gotOutput, "This testcase failed: " + name)
} }
} }