From cdb3bfe2a43fa2bba0ef94ff747cf2a5d9f66242 Mon Sep 17 00:00:00 2001 From: contact Date: Fri, 25 Feb 2022 10:31:41 +0000 Subject: [PATCH] irc: add isHighlight tests git-svn-id: file:///srv/svn/repo/suika/trunk@785 f0ae65fe-ee39-954e-97ec-027ff2717ef4 --- irc_test.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 irc_test.go diff --git a/irc_test.go b/irc_test.go new file mode 100644 index 0000000..76b3345 --- /dev/null +++ b/irc_test.go @@ -0,0 +1,34 @@ +package soju + +import ( + "testing" +) + +func TestIsHighlight(t *testing.T) { + nick := "SojuUser" + testCases := []struct { + name string + text string + hl bool + }{ + {"noContains", "hi there Soju User!", false}, + {"middle", "hi there SojuUser!", true}, + {"start", "SojuUser: how are you doing?", true}, + {"end", "maybe ask SojuUser", true}, + {"inWord", "but OtherSojuUserSan is a different nick", false}, + {"startWord", "and OtherSojuUser is another different nick", false}, + {"endWord", "and SojuUserSan is yet a different nick", false}, + {"underscore", "and SojuUser_san has nothing to do with me", false}, + {"zeroWidthSpace", "writing S\u200BojuUser shouldn't trigger a highlight", false}, + } + + for _, tc := range testCases { + tc := tc // capture range variable + t.Run(tc.name, func(t *testing.T) { + hl := isHighlight(tc.text, nick) + if hl != tc.hl { + t.Errorf("isHighlight(%q, %q) = %v, but want %v", tc.text, nick, hl, tc.hl) + } + }) + } +}