-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathsequence_test.go
104 lines (94 loc) · 2.24 KB
/
sequence_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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package slack_test
import (
"testing"
slack "github.com/lestrrat-go/slack"
"github.com/stretchr/testify/assert"
)
func TestParseControlSequence(t *testing.T) {
data := []struct {
Text string
Error bool
Expected slack.ControlSequence
}{
{
Text: `<@U12345678|bob>`,
Expected: &slack.UserLink{ID: `@U12345678`, Username: `bob`},
},
{
Text: `<foo|bar`,
Error: true,
},
}
for _, testcase := range data {
t.Run(testcase.Text, func(t *testing.T) {
l, err := slack.ParseControlSequence(testcase.Text)
if testcase.Error {
if !assert.Error(t, err, `should fail to parse sequence`) {
return
}
return
}
if !assert.NoError(t, err, `failed to parse sequences`) {
return
}
if !assert.Equal(t, testcase.Expected, l, `sequences should match`) {
return
}
})
}
}
func TestExtractControlSequences(t *testing.T) {
data := []struct {
Text string
Error bool
Expected []slack.ControlSequence
}{
{
Text: `Why not join <#C024BE7LR|general>?`,
Expected: []slack.ControlSequence{
&slack.ChannelLink{ID: `#C024BE7LR`, Channel: `general`},
},
},
{
Text: `Hey <@U024BE7LH|bob>, did you see my file?`,
Expected: []slack.ControlSequence{
&slack.UserLink{ID: `@U024BE7LH`, Username: `bob`},
},
},
{
Text: `This message contains a URL <http://foo.com/>`,
Expected: []slack.ControlSequence{
&slack.ExternalLink{URL: `http://foo.com/`, Text: `http://foo.com/`},
},
},
{
Text: `So does this one: <http://www.foo.com|www.foo.com>`,
Expected: []slack.ControlSequence{
&slack.ExternalLink{URL: `http://www.foo.com`, Text: `www.foo.com`},
},
},
{
Text: `<mailto:[email protected]|Bob>`,
Expected: []slack.ControlSequence{
&slack.ExternalLink{URL: `mailto:[email protected]`, Text: `Bob`},
},
},
}
for _, testcase := range data {
t.Run(testcase.Text, func(t *testing.T) {
l, err := slack.ExtractControlSequences(testcase.Text)
if testcase.Error {
if !assert.Error(t, err, `should fail to extract sequences`) {
return
}
return
}
if !assert.NoError(t, err, `failed to extract sequences`) {
return
}
if !assert.Equal(t, testcase.Expected, l, `sequences should match`) {
return
}
})
}
}