Skip to content

Commit

Permalink
Fix export emojize for use with the transform package etc. (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyokomi committed Feb 19, 2023
1 parent 6bdd002 commit c37c650
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
5 changes: 3 additions & 2 deletions emoji.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ func NormalizeShortCode(shortCode string) string {
// regular expression that matches :flag-[countrycode]:
var flagRegexp = regexp.MustCompile(":flag-([a-z]{2}):")

func emojize(x string) string {
// Emojize Converts the string passed as an argument to a emoji. For unsupported emoji, the string passed as an argument is returned as is.
func Emojize(x string) string {
str, ok := emojiCode()[x]
if ok {
return str + ReplacePadding
Expand Down Expand Up @@ -83,7 +84,7 @@ func replaseEmoji(input *bytes.Buffer) string {
case unicode.IsSpace(i):
return emoji.String()
case i == ':':
return emojize(emoji.String())
return Emojize(emoji.String())
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions emoji_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ const (
plusOne = ":+1:"
)

var testFText = "test " + emojize(beerKey) + beerText
var testText = emojize(beerKey) + beerText
var testFText = "test " + Emojize(beerKey) + beerText
var testText = Emojize(beerKey) + beerText

func TestFlag(t *testing.T) {
f := emojize(flag)
f := Emojize(flag)
expected := "\U0001f1fA\U0001f1f8"
if f != expected {
t.Error("emojize ", f, "!=", expected)
}
}

func TestPlusOne(t *testing.T) {
f := emojize(plusOne)
f := Emojize(plusOne)
expected := "\U0001f44d "
if f != expected {
t.Error("emojize ", f, "!=", expected)
Expand All @@ -42,7 +42,7 @@ func TestMultiColons(t *testing.T) {
t.Error("Fprint ", err)
}

testCase := "A " + emojize(":smile:") + " and another: " + emojize(":smile:")
testCase := "A " + Emojize(":smile:") + " and another: " + Emojize(":smile:")
if buf.String() != testCase {
t.Error("Fprint ", buf.String(), "!=", testCase)
}
Expand All @@ -55,7 +55,7 @@ func TestContinuityColons(t *testing.T) {
t.Error("Fprint ", err)
}

testCase := ":" + emojize(":smile:")
testCase := ":" + Emojize(":smile:")
if buf.String() != testCase {
t.Error("Fprint ", buf.String(), "!=", testCase)
}
Expand Down

0 comments on commit c37c650

Please sign in to comment.