Don't add any space around Emojis

This commit is contained in:
Bjørn Erik Pedersen 2016-05-09 22:59:49 +02:00
parent 608cfe62cf
commit 26906d8569
2 changed files with 20 additions and 18 deletions

View file

@ -15,8 +15,9 @@ package helpers
import ( import (
"bytes" "bytes"
"github.com/kyokomi/emoji"
"sync" "sync"
"github.com/kyokomi/emoji"
) )
var ( var (
@ -85,7 +86,7 @@ func initEmoji() {
emojiMap := emoji.CodeMap() emojiMap := emoji.CodeMap()
for k, v := range emojiMap { for k, v := range emojiMap {
emojis[k] = []byte(v + emoji.ReplacePadding) emojis[k] = []byte(v)
if len(k) > emojiMaxSize { if len(k) > emojiMaxSize {
emojiMaxSize = len(k) emojiMaxSize = len(k)

View file

@ -13,11 +13,12 @@
package helpers package helpers
import ( import (
"github.com/kyokomi/emoji"
"github.com/spf13/hugo/bufferpool"
"reflect" "reflect"
"strings" "strings"
"testing" "testing"
"github.com/kyokomi/emoji"
"github.com/spf13/hugo/bufferpool"
) )
func TestEmojiCustom(t *testing.T) { func TestEmojiCustom(t *testing.T) {
@ -25,24 +26,24 @@ func TestEmojiCustom(t *testing.T) {
input string input string
expect []byte expect []byte
}{ }{
{"A :smile: a day", []byte(emoji.Sprint("A :smile: a day"))}, {"A :smile: a day", []byte("A 😄 a day")},
{"A few :smile:s a day", []byte(emoji.Sprint("A few :smile:s a day"))}, {"A few :smile:s a day", []byte("A few 😄s a day")},
{"A :smile: and a :beer: makes the day for sure.", []byte(emoji.Sprint("A :smile: and a :beer: makes the day for sure."))}, {"A :smile: and a :beer: makes the day for sure.", []byte("A 😄 and a 🍺 makes the day for sure.")},
{"A :smile: and: a :beer:", []byte(emoji.Sprint("A :smile: and: a :beer:"))}, {"A :smile: and: a :beer:", []byte("A 😄 and: a 🍺")},
{"A :diamond_shape_with_a_dot_inside: and then some.", []byte(emoji.Sprint("A :diamond_shape_with_a_dot_inside: and then some."))}, {"A :diamond_shape_with_a_dot_inside: and then some.", []byte("A 💠 and then some.")},
{":smile:", []byte(emoji.Sprint(":smile:"))}, {":smile:", []byte("😄")},
{":smi", []byte(":smi")}, {":smi", []byte(":smi")},
{"A :smile:", []byte(emoji.Sprint("A :smile:"))}, {"A :smile:", []byte("A 😄")},
{":beer:!", []byte(emoji.Sprint(":beer:!"))}, {":beer:!", []byte("🍺!")},
{"::smile:", []byte(emoji.Sprint("::smile:"))}, {"::smile:", []byte(":😄")},
{":beer::", []byte(emoji.Sprint(":beer::"))}, {":beer::", []byte("🍺:")},
{" :beer: :", []byte(emoji.Sprint(" :beer: :"))}, {" :beer: :", []byte(" 🍺 :")},
{":beer: and :smile: and another :beer:!", []byte(emoji.Sprint(":beer: and :smile: and another :beer:!"))}, {":beer: and :smile: and another :beer:!", []byte("🍺 and 😄 and another 🍺!")},
{" :beer: : ", []byte(emoji.Sprint(" :beer: : "))}, {" :beer: : ", []byte(" 🍺 : ")},
{"No smilies for you!", []byte("No smilies for you!")}, {"No smilies for you!", []byte("No smilies for you!")},
{" The motto: no smiles! ", []byte(" The motto: no smiles! ")}, {" The motto: no smiles! ", []byte(" The motto: no smiles! ")},
{":hugo_is_the_best_static_gen:", []byte(":hugo_is_the_best_static_gen:")}, {":hugo_is_the_best_static_gen:", []byte(":hugo_is_the_best_static_gen:")},
{"은행 :smile: 은행", []byte(emoji.Sprint("은행 :smile: 은행"))}, {"은행 :smile: 은행", []byte("은행 😄 은행")},
} { } {
result := Emojify([]byte(this.input)) result := Emojify([]byte(this.input))