forked from bluesky-social/indigo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeyword_labeler_test.go
53 lines (46 loc) · 1.42 KB
/
keyword_labeler_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
package labeler
import (
"fmt"
"reflect"
"testing"
bsky "github.com/bluesky-social/indigo/api/bsky"
)
func TestKeywordFilter(t *testing.T) {
var kl = KeywordLabeler{Value: "rude", Keywords: []string{"🍆", "sex"}}
postCases := []struct {
record bsky.FeedPost
expected []string
}{
{bsky.FeedPost{Text: "boring inoffensive tweet"}, []string{}},
{bsky.FeedPost{Text: "I love Aubergine 🍆"}, []string{"rude"}},
{bsky.FeedPost{Text: "SeXyTiMe"}, []string{"rude"}},
}
for _, c := range postCases {
vals := kl.LabelPost(c.record)
if !reflect.DeepEqual(vals, c.expected) {
t.Log(fmt.Sprintf("labels expected:%s got:%s", c.expected, vals))
t.Fail()
}
}
desc := "yadda yadda"
descRude := "yadda yadda 🍆"
name := "Robyn Hood"
nameSexy := "Sexy Robyn Hood"
profileCases := []struct {
record bsky.ActorProfile
expected []string
}{
{bsky.ActorProfile{DisplayName: &name}, []string{}},
{bsky.ActorProfile{DisplayName: &name, Description: &desc}, []string{}},
{bsky.ActorProfile{DisplayName: &name, Description: &descRude}, []string{"rude"}},
{bsky.ActorProfile{DisplayName: &nameSexy}, []string{"rude"}},
{bsky.ActorProfile{DisplayName: &nameSexy, Description: &descRude}, []string{"rude"}},
}
for _, c := range profileCases {
vals := kl.LabelProfile(c.record)
if !reflect.DeepEqual(vals, c.expected) {
t.Log(fmt.Sprintf("labels expected:%s got:%s", c.expected, vals))
t.Fail()
}
}
}