package jackbox import "testing" func TestDetectVote_ThisGame(t *testing.T) { tests := []struct { input string isVote bool voteType string ticker string }{ {"thisgame++", true, "up", ""}, {"thisgame--", true, "down", ""}, {"THISGAME++", true, "up", ""}, {"ThisGame--", true, "down", ""}, {"I love thisgame++ so much", true, "up", ""}, {"honestly thisgame-- was rough", true, "down", ""}, } for _, tt := range tests { isVote, voteType, ticker := DetectVote(tt.input) if isVote != tt.isVote || voteType != tt.voteType || ticker != tt.ticker { t.Errorf("DetectVote(%q) = (%v, %q, %q), want (%v, %q, %q)", tt.input, isVote, voteType, ticker, tt.isVote, tt.voteType, tt.ticker) } } } func TestDetectVote_Ticker(t *testing.T) { tests := []struct { input string isVote bool voteType string ticker string }{ {"QPL3++", true, "up", "QPL3"}, {"qpl3++", true, "up", "QPL3"}, {"TMP2--", true, "down", "TMP2"}, {"tmp2--", true, "down", "TMP2"}, {"DD++", true, "up", "DD"}, {"dd--", true, "down", "DD"}, {"YDKJ++", true, "up", "YDKJ"}, {"EW--", true, "down", "EW"}, {"let's go FBG4++", true, "up", "FBG4"}, {"TWEP++ is great", true, "up", "TWEP"}, } for _, tt := range tests { isVote, voteType, ticker := DetectVote(tt.input) if isVote != tt.isVote || voteType != tt.voteType || ticker != tt.ticker { t.Errorf("DetectVote(%q) = (%v, %q, %q), want (%v, %q, %q)", tt.input, isVote, voteType, ticker, tt.isVote, tt.voteType, tt.ticker) } } } func TestDetectVote_UnknownSymbol(t *testing.T) { tests := []string{ "ZZZZ++", "ABCD--", "XY++", "NOPE--", } for _, input := range tests { isVote, voteType, ticker := DetectVote(input) if isVote { t.Errorf("DetectVote(%q) = (%v, %q, %q), want (false, \"\", \"\")", input, isVote, voteType, ticker) } } } func TestDetectVote_NoVote(t *testing.T) { tests := []string{ "hello world", "this game is fun", "QPL3", "++QPL3", "", } for _, input := range tests { isVote, voteType, ticker := DetectVote(input) if isVote { t.Errorf("DetectVote(%q) = (%v, %q, %q), want (false, \"\", \"\")", input, isVote, voteType, ticker) } } } func TestDetectVote_ThisGameTakesPriority(t *testing.T) { // When a message contains both thisgame++ and a ticker, thisgame wins isVote, voteType, ticker := DetectVote("thisgame++ QPL3++") if !isVote || voteType != "up" || ticker != "" { t.Errorf("DetectVote with both patterns = (%v, %q, %q), want (true, \"up\", \"\")", isVote, voteType, ticker) } } func TestLookupTicker(t *testing.T) { tests := []struct { symbol string title string ok bool }{ {"QPL3", "Quiplash 3", true}, {"qpl3", "Quiplash 3", true}, {"DD", "Dirty Drawful", true}, {"EW", "Earwaxâ„¢", true}, {"TWEP", "The Wheel of Enormous Proportions", true}, {"ZZZZ", "", false}, {"", "", false}, } for _, tt := range tests { title, ok := LookupTicker(tt.symbol) if ok != tt.ok || title != tt.title { t.Errorf("LookupTicker(%q) = (%q, %v), want (%q, %v)", tt.symbol, title, ok, tt.title, tt.ok) } } }