Skip to content

Instantly share code, notes, and snippets.

@kaneshin
Created April 7, 2017 06:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaneshin/088b17b14f082513145a820d1003e8dd to your computer and use it in GitHub Desktop.
Save kaneshin/088b17b14f082513145a820d1003e8dd to your computer and use it in GitHub Desktop.
package slackutil
import (
"testing"
"github.com/stretchr/testify/assert"
)
func Test_Replacer(t *testing.T) {
r := NewReplacer(nil)
t.Run("ReplaceAllUsers", func(t *testing.T) {
tests := []struct {
s string
expected string
}{
{
s: "<@XXXXXXXXX|foobar>",
expected: "@foobar",
},
{
s: "<@XXXXXXXXX>",
expected: "XXXXXXXXX",
},
{
s: "bar <@XXXXXXXXX|foobar> baz",
expected: "bar @foobar baz",
},
{
s: "bar <#XXXXXXXXX|foobar> baz",
expected: "bar <#XXXXXXXXX|foobar> baz",
},
{
s: "bar <!subteam^XXXXXXXXX|foobar> baz",
expected: "bar <!subteam^XXXXXXXXX|foobar> baz",
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.s, func(t *testing.T) {
t.Parallel()
assert := assert.New(t)
assert.Equal(tt.expected, r.ReplaceAllUsers(tt.s))
})
}
})
t.Run("ReplaceAllChannels", func(t *testing.T) {
tests := []struct {
s string
expected string
}{
{
s: "<#XXXXXXXXX|foobar>",
expected: "#foobar",
},
{
s: "<#XXXXXXXXX>",
expected: "XXXXXXXXX",
},
{
s: "bar <@XXXXXXXXX|foobar> baz",
expected: "bar <@XXXXXXXXX|foobar> baz",
},
{
s: "bar <#XXXXXXXXX|foobar> baz",
expected: "bar #foobar baz",
},
{
s: "bar <!subteam^XXXXXXXXX|foobar> baz",
expected: "bar <!subteam^XXXXXXXXX|foobar> baz",
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.s, func(t *testing.T) {
t.Parallel()
assert := assert.New(t)
assert.Equal(tt.expected, r.ReplaceAllChannels(tt.s))
})
}
})
t.Run("ReplaceAllGroups", func(t *testing.T) {
tests := []struct {
s string
expected string
}{
{
s: "<!subteam^XXXXXXXXX|foobar>",
expected: "@foobar",
},
{
s: "<!subteam^XXXXXXXXX>",
expected: "XXXXXXXXX",
},
{
s: "bar <@XXXXXXXXX|foobar> baz",
expected: "bar <@XXXXXXXXX|foobar> baz",
},
{
s: "bar <#XXXXXXXXX|foobar> baz",
expected: "bar <#XXXXXXXXX|foobar> baz",
},
{
s: "bar <!subteam^XXXXXXXXX|foobar> baz",
expected: "bar @foobar baz",
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.s, func(t *testing.T) {
t.Parallel()
assert := assert.New(t)
assert.Equal(tt.expected, r.ReplaceAllGroups(tt.s))
})
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment