summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2018-07-24 15:57:46 +0200
committerDimitri Sokolyuk <demon@dim13.org>2018-07-24 15:57:46 +0200
commit5e4abe0d17cb3a6bc94106936397a410129a24e5 (patch)
treeb5c2bc0f4e69e4b9366edb35477119867569141f
parentbef0c7d77e17141db87f5ef24dc59941a13c94f5 (diff)
collect in one place
-rw-r--r--flood.go11
-rw-r--r--flood_test.go23
-rw-r--r--main.go11
-rw-r--r--main_test.go26
4 files changed, 34 insertions, 37 deletions
diff --git a/flood.go b/flood.go
index c741bd6..dd1540f 100644
--- a/flood.go
+++ b/flood.go
@@ -4,6 +4,7 @@ import (
"math"
"sort"
"strings"
+ "unicode"
"unicode/utf8"
)
@@ -45,3 +46,13 @@ func commonWord(v []string) int {
sort.Sort(sort.Reverse(sort.IntSlice(l)))
return l[0]
}
+
+func noSpaceCompare(a, b string) bool {
+ dropSpaces := func(r rune) rune {
+ if unicode.IsSpace(r) {
+ return -1
+ }
+ return r
+ }
+ return strings.Map(dropSpaces, a) == strings.Map(dropSpaces, b)
+}
diff --git a/flood_test.go b/flood_test.go
index 175779d..8fc0194 100644
--- a/flood_test.go
+++ b/flood_test.go
@@ -25,3 +25,26 @@ func TestFlood(t *testing.T) {
})
}
}
+
+func TestNoSpaceCompare(t *testing.T) {
+ testCases := []struct {
+ a, b string
+ ok bool
+ }{
+ {"", "", true},
+ {"x", "", false},
+ {"", "x", false},
+ {"x ", "x", true},
+ {" x", "x", true},
+ {"x x", "xx", true},
+ {"x x x", "x", false},
+ }
+ for _, tc := range testCases {
+ t.Run(tc.a+"?"+tc.b, func(t *testing.T) {
+ ok := noSpaceCompare(tc.a, tc.b)
+ if ok != tc.ok {
+ t.Errorf("got %v; want %v", ok, tc.ok)
+ }
+ })
+ }
+}
diff --git a/main.go b/main.go
index 9cf4fd4..3376b01 100644
--- a/main.go
+++ b/main.go
@@ -7,7 +7,6 @@ import (
"log"
"strings"
"time"
- "unicode"
irc "github.com/fluffle/goirc/client"
)
@@ -43,16 +42,6 @@ func (n *Notify) Write(p []byte) (int, error) {
return len(p), nil
}
-func noSpaceCompare(a, b string) bool {
- dropSpaces := func(r rune) rune {
- if unicode.IsSpace(r) {
- return -1
- }
- return r
- }
- return strings.Map(dropSpaces, a) == strings.Map(dropSpaces, b)
-}
-
func privmsg(room string) irc.HandlerFunc {
var (
last = make(map[string]string)
diff --git a/main_test.go b/main_test.go
deleted file mode 100644
index 51002d7..0000000
--- a/main_test.go
+++ /dev/null
@@ -1,26 +0,0 @@
-package main
-
-import "testing"
-
-func TestNoSpaceCompare(t *testing.T) {
- testCases := []struct {
- a, b string
- ok bool
- }{
- {"", "", true},
- {"x", "", false},
- {"", "x", false},
- {"x ", "x", true},
- {" x", "x", true},
- {"x x", "xx", true},
- {"x x x", "x", false},
- }
- for _, tc := range testCases {
- t.Run(tc.a+"?"+tc.b, func(t *testing.T) {
- ok := noSpaceCompare(tc.a, tc.b)
- if ok != tc.ok {
- t.Errorf("got %v; want %v", ok, tc.ok)
- }
- })
- }
-}