-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathfinders_test.go
89 lines (82 loc) · 2.76 KB
/
finders_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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package anno_test
import (
"testing"
"github.com/matryer/anno"
"github.com/matryer/is"
)
func TestURL(t *testing.T) {
is := is.New(t)
src := []byte("My website is https://downlist.io/ come and check it out - or go to http://www.codeandthat.com/ instead.")
matches, err := anno.URLs(src)
is.NoErr(err)
is.True(matches != nil)
is.Equal(len(matches), 2)
is.Equal(string(matches[0].Val), "https://downlist.io/")
is.Equal(matches[0].Start, 14)
is.Equal(matches[0].End(), 14+len(matches[0].Val))
is.Equal(matches[0].Kind, "url")
is.Equal(string(matches[1].Val), "http://www.codeandthat.com/")
is.Equal(matches[1].Start, 68)
is.Equal(matches[1].End(), 68+len(matches[1].Val))
is.Equal(matches[1].Kind, "url")
}
func TestEmail(t *testing.T) {
is := is.New(t)
src := []byte("Send me an email to please-reply@downlist.io if you like.")
matches, err := anno.Emails(src)
is.NoErr(err)
is.True(matches != nil)
is.Equal(len(matches), 1)
is.Equal(matches[0].Val, []byte("please-reply@downlist.io"))
is.Equal(matches[0].Start, 20)
is.Equal(matches[0].End(), 20+len(matches[0].Val))
is.Equal(matches[0].Kind, "email")
}
func TestMention(t *testing.T) {
is := is.New(t)
src := []byte("Call me @matryer on Twitter, or follow @downlistapp instead.")
matches, err := anno.Mentions(src)
is.NoErr(err)
is.True(matches != nil)
is.Equal(len(matches), 2)
is.Equal(matches[0].Val, []byte("@matryer"))
is.Equal(matches[0].Start, 8)
is.Equal(matches[0].End(), 8+len(matches[0].Val))
is.Equal(matches[0].Kind, "mention")
is.Equal(matches[1].Val, []byte("@downlistapp"))
is.Equal(matches[1].Start, 39)
is.Equal(matches[1].End(), 39+len(matches[1].Val))
is.Equal(matches[1].Kind, "mention")
}
func TestMention2(t *testing.T) {
is := is.New(t)
src := []byte("@matryer on Twitter, or follow @downlistapp instead.")
matches, err := anno.Mentions(src)
is.NoErr(err)
is.True(matches != nil)
is.Equal(len(matches), 2)
is.Equal(matches[0].Val, []byte("@matryer"))
is.Equal(matches[0].Start, 0)
is.Equal(matches[0].End(), len(matches[0].Val))
is.Equal(matches[0].Kind, "mention")
is.Equal(matches[1].Val, []byte("@downlistapp"))
is.Equal(matches[1].Start, 31)
is.Equal(matches[1].End(), 31+len(matches[1].Val))
is.Equal(matches[1].Kind, "mention")
}
func TestHashtag(t *testing.T) {
is := is.New(t)
src := []byte("I love programming in #golang - it's #lovely.")
matches, err := anno.Hashtags(src)
is.NoErr(err)
is.True(matches != nil)
is.Equal(len(matches), 2)
is.Equal(string(matches[0].Val), "#golang")
is.Equal(matches[0].Start, 22)
is.Equal(matches[0].End(), 22+len(matches[0].Val))
is.Equal(matches[0].Kind, "hashtag")
is.Equal(string(matches[1].Val), "#lovely")
is.Equal(matches[1].Start, 37)
is.Equal(matches[1].End(), 37+len(matches[1].Val))
is.Equal(matches[1].Kind, "hashtag")
}