forked from urakozz/go-emoji
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser_test.go
53 lines (44 loc) · 1.19 KB
/
parser_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright 2015 Yury Kozyrev. License MIT.
// Proprietary license.
package emoji
import (
"testing"
"github.com/stretchr/testify/assert"
"strconv"
"regexp"
)
func TestInsert(t *testing.T) {
container := make(map[string]string)
parser := NewEmojiParser()
var text = "a #💩 #and #🍦 #😳"
var i = -1
replased := parser.ReplaceAllStringFunc(text, func(s string) string {
i++
key := "_$"+strconv.Itoa(i)+"_"
container[key] = s
return key
return strconv.Itoa(i)
})
assert.Equal(t, replased, "a #_$0_ #and #_$1_ #_$2_")
htmlEnt := parser.ToHtmlEntities(text)
assert.Equal(t, htmlEnt, "a #💩 #and #🍦 #😳")
htmlImg := parser.ToHtmlImages(text)
assertion := `a #<img
class="emoji"
draggable="false"
alt="💩"
src="https://twemoji.maxcdn.com/36x36/1f4a9.png"> #and #<img
class="emoji"
draggable="false"
alt="🍦"
src="https://twemoji.maxcdn.com/36x36/1f366.png"> #<img
class="emoji"
draggable="false"
alt="😳"
src="https://twemoji.maxcdn.com/36x36/1f633.png">`
assert.Equal(t, htmlImg, assertion)
recovered := regexp.MustCompile(`\_\$\d+\_`).ReplaceAllStringFunc(replased, func(s string) string {
return container[s]
})
assert.Equal(t, recovered, text)
}