This repository was archived by the owner on Apr 7, 2024. It is now read-only.
forked from enescakir/emoji
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathparser_test.go
More file actions
183 lines (165 loc) · 4.63 KB
/
Copy pathparser_test.go
File metadata and controls
183 lines (165 loc) · 4.63 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
package emoji
import (
"fmt"
"testing"
)
func TestReplace(t *testing.T) {
tt := []struct {
input string
expected string
}{
{
input: "I am :man_technologist: from :flag_for_turkey:. Tests are :thumbs_up:",
expected: fmt.Sprintf("I am %v from %v. Tests are %v", ManTechnologist, FlagForTurkey, ThumbsUp),
},
{
input: "consecutive emojis :pizza::sushi::sweat:",
expected: fmt.Sprintf("consecutive emojis %v%v%v", Pizza, Sushi, DowncastFaceWithSweat),
},
{
input: ":accordion::anguished_face: \n woman :woman_golfing:",
expected: fmt.Sprintf("%v%v \n woman %v", Accordion, AnguishedFace, WomanGolfing),
},
{
input: "shared colon :angry_face_with_horns:anger_symbol:",
expected: fmt.Sprintf("shared colon %vanger_symbol:", AngryFaceWithHorns),
},
{
input: ":not_exist_emoji: not exist emoji",
expected: ":not_exist_emoji: not exist emoji",
},
{
input: ":dragon::",
expected: fmt.Sprintf("%v:", Dragon),
},
{
input: "::+1:",
expected: fmt.Sprintf(":%v", ThumbsUp),
},
{
input: "::anchor::",
expected: fmt.Sprintf(":%v:", Anchor),
},
{
input: ":anguished:::",
expected: fmt.Sprintf("%v::", AnguishedFace),
},
{
input: "too many colon::::closed_book:::: too many colon:",
expected: fmt.Sprintf("too many colon:::%v::: too many colon:", ClosedBook),
},
{
input: "emoji with space :angry face_with_horns:anger_symbol:",
expected: fmt.Sprintf("emoji with space :angry face_with_horns%v", AngerSymbol),
},
{
input: "flag testing :flag-tr: done",
expected: fmt.Sprintf("flag testing %v done", FlagForTurkey),
},
{
input: "not valid flags :flag-tra: :flag-t: testing",
expected: fmt.Sprintf("not valid flags :flag-tra: :flag-t: testing"),
},
{
input: "dummytext",
expected: "dummytext",
},
}
for i, tc := range tt {
t.Run(fmt.Sprintf("test #%d", i), func(t *testing.T) {
got := Replace(tc.input)
if got != tc.expected {
t.Fatalf("test case %v fail: got: %v, expected: %v", i+1, got, tc.expected)
}
})
}
}
func TestMap(t *testing.T) {
expected := len(emojiMap)
got := len(Map())
if got != expected {
t.Fatalf("test case fail: got: %v, expected: %v", got, expected)
}
}
func TestAppendAlias(t *testing.T) {
tt := []struct {
alias string
code string
err bool
}{
{alias: ":my_car:", code: "\U0001f3ce\ufe0f", err: false},
{alias: ":berserker:", code: "\U0001f621", err: false},
{alias: ":potato:", code: "\U0001f423", err: true},
{alias: ":not_valid alias:", code: "\U0001f423", err: true},
}
for i, tc := range tt {
err := AppendAlias(tc.alias, tc.code)
if (err != nil) != tc.err {
t.Fatalf("test case %v fail: got: %v, expected: %v", i+1, err, tc.err)
}
if exist := Exist(tc.alias); !exist && !tc.err {
t.Fatalf("test case %v fail: got: %v, expected: %v", i+1, !exist, exist)
}
}
}
func TestExist(t *testing.T) {
tt := []struct {
input string
expected bool
}{
{input: ":man_technologist:", expected: true},
{input: ":registered:", expected: true},
{input: ":robot_face:", expected: true},
{input: ":wave:", expected: true},
{input: ":sheaf_of_rice:", expected: true},
{input: ":random_emoji:", expected: false},
{input: ":test_emoji:", expected: false},
}
for i, tc := range tt {
got := Exist(tc.input)
if got != tc.expected {
t.Fatalf("test case %v fail: got: %v, expected: %v", i+1, got, tc.expected)
}
}
}
func TestFind(t *testing.T) {
tt := []struct {
input string
expected string
exist bool
}{
{input: ":man_technologist:", expected: ManTechnologist.String(), exist: true},
{input: ":robot_face:", expected: Robot.String(), exist: true},
{input: ":wave:", expected: WavingHand.String(), exist: true},
{input: ":sheaf_of_rice:", expected: SheafOfRice.String(), exist: true},
{input: ":random_emoji:", expected: "", exist: false},
{input: ":test_emoji:", expected: "", exist: false},
}
for i, tc := range tt {
t.Run(fmt.Sprintf("test #%d", i), func(t *testing.T) {
got, exist := Find(tc.input)
if got != tc.expected {
t.Fatalf("test case %v fail: got: %v, expected: %v", i+1, got, tc.expected)
}
if exist != tc.exist {
t.Fatalf("test case %v fail: got: %v, expected: %v", i+1, exist, tc.exist)
}
})
}
}
func BenchmarkReplace(b *testing.B) {
const message = "I am :man_technologist: from :flag_for_turkey:. Tests are :thumbs_up:"
b.Run("static", func(b *testing.B) {
b.ReportAllocs()
for n := 0; n < b.N; n++ {
_ = Replace(message)
}
})
b.Run("reusable", func(b *testing.B) {
b.ReportAllocs()
p := NewReplacer()
for n := 0; n < b.N; n++ {
_ = p.Replace(message)
}
})
}