aboutsummaryrefslogtreecommitdiffstats
path: root/cache
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2019-03-03 15:23:20 +0100
committerMichael Muré <batolettre@gmail.com>2019-03-03 15:23:20 +0100
commit408654514ea813933f45d383d949611d138084e1 (patch)
treeb3d8db1596b7347fdcf39cfdc9614a3c09464b36 /cache
parent0e5550a27b7d9b8beb1418588ca5c9c12f4437c5 (diff)
downloadgit-bug-408654514ea813933f45d383d949611d138084e1.tar.gz
cache: make the title filter case insensitive
Diffstat (limited to 'cache')
-rw-r--r--cache/filter.go9
-rw-r--r--cache/filter_test.go34
2 files changed, 40 insertions, 3 deletions
diff --git a/cache/filter.go b/cache/filter.go
index fe6d200a..b6872508 100644
--- a/cache/filter.go
+++ b/cache/filter.go
@@ -55,10 +55,13 @@ func LabelFilter(label string) Filter {
}
}
-// TitleFilter return a Filter that match if the title contains the given pattern
-func TitleFilter(title string) Filter {
+// TitleFilter return a Filter that match if the title contains the given query
+func TitleFilter(query string) Filter {
return func(repo *RepoCache, excerpt *BugExcerpt) bool {
- return strings.Contains(excerpt.Title, title)
+ return strings.Contains(
+ strings.ToLower(excerpt.Title),
+ strings.ToLower(query),
+ )
}
}
diff --git a/cache/filter_test.go b/cache/filter_test.go
new file mode 100644
index 00000000..a47d2ad7
--- /dev/null
+++ b/cache/filter_test.go
@@ -0,0 +1,34 @@
+package cache
+
+import (
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestTitleFilter(t *testing.T) {
+ tests := []struct {
+ name string
+ title string
+ query string
+ match bool
+ }{
+ {name: "complete match", title: "hello world", query: "hello world", match: true},
+ {name: "partial match", title: "hello world", query: "hello", match: true},
+ {name: "no match", title: "hello world", query: "foo", match: false},
+ {name: "cased title", title: "Hello World", query: "hello", match: true},
+ {name: "cased query", title: "hello world", query: "Hello", match: true},
+
+ // Those following tests should work eventually but are left for a future iteration.
+
+ // {name: "cased accents", title: "ÑOÑO", query: "ñoño", match: true},
+ // {name: "natural language matching", title: "Århus", query: "Aarhus", match: true},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ filter := TitleFilter(tt.query)
+ excerpt := &BugExcerpt{Title: tt.title}
+ assert.Equal(t, tt.match, filter(nil, excerpt))
+ })
+ }
+}