Skip to content

Commit

Permalink
Forgot to also move the old regex replace impl in e946b96
Browse files Browse the repository at this point in the history
  • Loading branch information
Bios-Marcel committed Dec 29, 2021
1 parent fea51a6 commit 8bd4575
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
22 changes: 0 additions & 22 deletions query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package discordemojimap

import (
"fmt"
"regexp"
"sort"
"strings"
"testing"
)

Expand Down Expand Up @@ -123,23 +121,3 @@ func lionTest(t *testing.T, input string) {
t.Errorf("The matches were expected to contain 'lion_face'.")
}
}

var emojiCodeRegex = regexp.MustCompile("(?s):[a-zA-Z0-9_]+:")

// oldRegexReplace all emoji sequences contained in the discord emoji map with their
// respective emojis.
func oldRegexReplace(input string) string {
// Return the input as-is if it has less than a pair of colons.
if len(input) <= 2 {
return input
}

return emojiCodeRegex.ReplaceAllStringFunc(input, func(match string) string {
emojified, contains := EmojiMap[strings.ToLower(match[1:len(match)-1])]
if !contains {
return match
}

return emojified
})
}
21 changes: 21 additions & 0 deletions replacer_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package discordemojimap

import (
"regexp"
"strings"
"testing"
)
Expand Down Expand Up @@ -57,6 +58,26 @@ var inputVariations = [][2]string{
{"two valid emoji sequence with word inbetween", ":sunglasses: hello :sunglasses:"},
}

var emojiCodeRegex = regexp.MustCompile("(?s):[a-zA-Z0-9_]+:")

// oldRegexReplace all emoji sequences contained in the discord emoji map with their
// respective emojis.
func oldRegexReplace(input string) string {
// Return the input as-is if it has less than a pair of colons.
if len(input) <= 2 {
return input
}

return emojiCodeRegex.ReplaceAllStringFunc(input, func(match string) string {
emojified, contains := EmojiMap[strings.ToLower(match[1:len(match)-1])]
if !contains {
return match
}

return emojified
})
}

func TestNewReplaceAndOldReplaceBehaveTheSame(t *testing.T) {
for _, test := range inputVariations {
a := oldRegexReplace(test[1])
Expand Down

0 comments on commit 8bd4575

Please sign in to comment.