forked from enescakir/emoji
-
Notifications
You must be signed in to change notification settings - Fork 0
/
emoji_test.go
153 lines (136 loc) · 3.77 KB
/
emoji_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
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
package emoji
import (
"testing"
)
func TestEmoji(t *testing.T) {
tt := []struct {
input Emoji
expected string
}{
{input: GrinningFace, expected: "\U0001F600"},
{input: EyeInSpeechBubble, expected: "\U0001F441\uFE0F\u200D\U0001F5E8\uFE0F"},
{input: ManGenie, expected: "\U0001F9DE\u200D\u2642\uFE0F"},
{input: Badger, expected: "\U0001F9A1"},
{input: FlagForTurkey, expected: "\U0001F1F9\U0001F1F7"},
}
for i, tc := range tt {
got := tc.input.String()
if got != tc.expected {
t.Fatalf("test case %v fail: got: %v, expected: %v", i+1, got, tc.expected)
}
}
}
func TestEmojiWithTone(t *testing.T) {
tt := []struct {
input EmojiWithTone
tone Tone
expected string
}{
{input: WavingHand, tone: Tone(""), expected: "\U0001F44B"},
{input: WavingHand, tone: Default, expected: "\U0001F44B"},
{input: WavingHand, tone: Light, expected: "\U0001F44B\U0001F3FB"},
{input: WavingHand, tone: MediumLight, expected: "\U0001F44B\U0001F3FC"},
{input: WavingHand, tone: Medium, expected: "\U0001F44B\U0001F3FD"},
{input: WavingHand, tone: MediumDark, expected: "\U0001F44B\U0001F3FE"},
{input: WavingHand, tone: Dark, expected: "\U0001F44B\U0001F3FF"},
}
for i, tc := range tt {
got := tc.input.Tone(tc.tone)
if got != tc.expected {
t.Fatalf("test case %v fail: got: %v, expected: %v", i+1, got, tc.expected)
}
}
}
func TestEmojiWithTones(t *testing.T) {
tt := []struct {
input EmojiWithTone
tones []Tone
expected string
}{
{input: WomanAndManHoldingHands, tones: []Tone{}, expected: "\U0001f46b"},
{input: WomanAndManHoldingHands, tones: []Tone{MediumLight}, expected: "\U0001f46b\U0001F3FC"},
{input: WomanAndManHoldingHands, tones: []Tone{Medium, Dark}, expected: "\U0001f469\U0001F3FD\u200d\U0001f91d\u200d\U0001f468\U0001F3FF"},
}
for i, tc := range tt {
got := tc.input.Tone(tc.tones...)
if got != tc.expected {
t.Fatalf("test case %v fail: got: %v, expected: %v", i+1, got, tc.expected)
}
}
}
func TestCountryFlag(t *testing.T) {
tt := []struct {
input string
expected Emoji
}{
{input: "tr", expected: FlagForTurkey},
{input: "TR", expected: FlagForTurkey},
{input: "us", expected: FlagForUnitedStates},
{input: "gb", expected: FlagForUnitedKingdom},
}
for i, tc := range tt {
got, err := CountryFlag(tc.input)
if err != nil {
t.Fatalf("test case %v fail: %v", i+1, err)
}
if got != tc.expected {
t.Fatalf("test case %v fail: got: %v, expected: %v", i+1, got, tc.expected)
}
}
}
func TestCountryFlagError(t *testing.T) {
tt := []struct {
input string
fail bool
}{
{input: "tr", fail: false},
{input: "a", fail: true},
{input: "tur", fail: true},
}
for i, tc := range tt {
_, err := CountryFlag(tc.input)
if (err != nil) != tc.fail {
t.Fatalf("test case %v fail: %v", i+1, err)
}
}
}
func TestNewEmojiTone(t *testing.T) {
tt := []struct {
input []string
expected EmojiWithTone
}{
{input: nil, expected: EmojiWithTone{}},
{input: []string{}, expected: EmojiWithTone{}},
{input: []string{"\U0001f64b@"}, expected: PersonRaisingHand},
{
input: []string{"\U0001f46b@", "\U0001f469@\u200d\U0001f91d\u200d\U0001f468@"},
expected: WomanAndManHoldingHands,
},
}
for i, tc := range tt {
got := newEmojiWithTone(tc.input...)
if got != tc.expected {
t.Fatalf("test case %v fail: got: %v, expected: %v", i+1, got, tc.expected)
}
}
}
func BenchmarkEmoji(b *testing.B) {
for n := 0; n < b.N; n++ {
_ = WavingHand.String()
}
}
func BenchmarkEmojiWithTone(b *testing.B) {
for n := 0; n < b.N; n++ {
_ = WavingHand.Tone(Medium)
}
}
func BenchmarkEmojiWithToneTwo(b *testing.B) {
for n := 0; n < b.N; n++ {
_ = WomanAndManHoldingHands.Tone(Medium, Dark)
}
}
func BenchmarkCountryFlag(b *testing.B) {
for n := 0; n < b.N; n++ {
_, _ = CountryFlag("tr")
}
}