-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathfilters_test.go
71 lines (67 loc) · 1.44 KB
/
filters_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package turtle
import (
"testing"
"github.com/google/go-cmp/cmp"
"github.com/hackebrot/go-repr/repr"
)
func TestFilter(t *testing.T) {
tests := []struct {
name string
f func(e *Emoji) bool
want []*Emoji
}{
{
name: "no matches",
f: func(e *Emoji) bool {
return e.Name == "nope"
},
want: nil,
},
{
name: "single match",
f: func(e *Emoji) bool {
for _, keyword := range e.Keywords {
if keyword == "developer" {
return true
}
}
return false
},
want: []*Emoji{
{
Name: "woman_technologist",
Category: "people",
Char: "👩💻",
Keywords: []string{"coder", "developer", "engineer", "programmer", "software", "woman", "human"},
},
},
},
{
name: "multiple matches",
f: func(e *Emoji) bool {
return e.Category == "animals_and_nature"
},
want: []*Emoji{
{
Name: "turtle",
Category: "animals_and_nature",
Char: "🐢",
Keywords: []string{"animal", "slow", "nature", "tortoise"},
},
{
Name: "dog",
Category: "animals_and_nature",
Char: "🐶",
Keywords: []string{"animal", "friend", "nature", "woof", "puppy", "pet", "faithful"},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := filter(testEmojis, tt.f); !cmp.Equal(got, tt.want) {
t.Errorf("filter() = %v, want %v", repr.Repr(got), repr.Repr(tt.want))
}
})
}
}