-
Notifications
You must be signed in to change notification settings - Fork 0
/
extract_test.go
74 lines (70 loc) · 2.34 KB
/
extract_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
72
73
74
package main
import (
"reflect"
"testing"
)
func TestExtractLinks(t *testing.T) {
tests := []struct {
name string
input string
want []entry
}{
{name: "1", input: `検索は https://google.com です`, want: []entry{{text: "https://google.com", start: 4, end: 22}}},
{name: "2", input: `https://google.com です`, want: []entry{{text: "https://google.com", start: 0, end: 18}}},
{name: "3", input: `https://google.com`, want: []entry{{text: "https://google.com", start: 0, end: 18}}},
}
for _, test := range tests {
result := extractLinks(test.input)
if len(result) != len(test.want) {
t.Fatalf("extract %d link(s)", len(test.want))
}
if !reflect.DeepEqual(result, test.want) {
t.Fatalf("want %v but got %v for test %v", test.want, result, test.name)
}
}
}
func TestExtractMentions(t *testing.T) {
tests := []struct {
name string
input string
want []entry
}{
{name: "1", input: `返事は @mattn へ`, want: []entry{{text: "mattn", start: 4, end: 10}}},
{name: "2", input: `返事は @mattn-- へ`, want: []entry{{text: "mattn", start: 4, end: 10}}},
{name: "3", input: `返事は @mattn.jp へ`, want: []entry{{text: "mattn.jp", start: 4, end: 13}}},
{name: "4", input: `返事は @@mattn へ`, want: []entry{{text: "mattn", start: 5, end: 11}}},
}
for _, test := range tests {
result := extractMentions(test.input)
if len(result) != len(test.want) {
t.Fatalf("extract %d link(s)", len(test.want))
}
if !reflect.DeepEqual(result, test.want) {
t.Fatalf("want %v but got %v for test %v", test.want, result, test.name)
}
}
}
func TestExtractTags(t *testing.T) {
tests := []struct {
name string
input string
want []entry
}{
{name: "1", input: `Hi, #Bluesky!`, want: []entry{{text: "Bluesky!", start: 4, end: 13}}},
{name: "2", input: `bsky から#テスト`, want: []entry{{text: "テスト", start: 7, end: 11}}},
{name: "3", input: `Emoji hashtags: #🦋 #🟦🈳 #🌌`, want: []entry{
{text: "🦋", start: 16, end: 18},
{text: "🟦🈳", start: 19, end: 22},
{text: "🌌", start: 23, end: 25},
}},
}
for _, test := range tests {
result := extractTags(test.input)
if len(result) != len(test.want) {
t.Fatalf("extract %d tag(s)", len(test.want))
}
if !reflect.DeepEqual(result, test.want) {
t.Fatalf("want %v but got %v for test %v", test.want, result, test.name)
}
}
}