Created
April 7, 2017 06:23
-
-
Save kaneshin/088b17b14f082513145a820d1003e8dd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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