emoji_test.go (view raw)
1package emoji
2
3import (
4 "testing"
5)
6
7func TestEmoji(t *testing.T) {
8 tt := []struct {
9 input Emoji
10 expected string
11 }{
12 {input: GrinningFace, expected: "\U0001F600"},
13 {input: EyeInSpeechBubble, expected: "\U0001F441\uFE0F\u200D\U0001F5E8\uFE0F"},
14 {input: ManGenie, expected: "\U0001F9DE\u200D\u2642\uFE0F"},
15 {input: Badger, expected: "\U0001F9A1"},
16 {input: FlagForTurkey, expected: "\U0001F1F9\U0001F1F7"},
17 }
18
19 for i, tc := range tt {
20 got := tc.input.String()
21 if got != tc.expected {
22 t.Fatalf("test case %v fail: got: %v, expected: %v", i+1, got, tc.expected)
23 }
24 }
25}
26
27func TestEmojiWithTone(t *testing.T) {
28 tt := []struct {
29 input EmojiWithTone
30 tone Tone
31 expected string
32 }{
33 {input: WavingHand, tone: Tone(""), expected: "\U0001F44B"},
34 {input: WavingHand, tone: Default, expected: "\U0001F44B"},
35 {input: WavingHand, tone: Light, expected: "\U0001F44B\U0001F3FB"},
36 {input: WavingHand, tone: MediumLight, expected: "\U0001F44B\U0001F3FC"},
37 {input: WavingHand, tone: Medium, expected: "\U0001F44B\U0001F3FD"},
38 {input: WavingHand, tone: MediumDark, expected: "\U0001F44B\U0001F3FE"},
39 {input: WavingHand, tone: Dark, expected: "\U0001F44B\U0001F3FF"},
40 }
41
42 for i, tc := range tt {
43 got := tc.input.Tone(tc.tone)
44 if got != tc.expected {
45 t.Fatalf("test case %v fail: got: %v, expected: %v", i+1, got, tc.expected)
46 }
47 }
48}
49
50func TestEmojiWithTones(t *testing.T) {
51 tt := []struct {
52 input EmojiWithTone
53 tones []Tone
54 expected string
55 }{
56 {input: WomanAndManHoldingHands, tones: []Tone{}, expected: "\U0001f46b"},
57 {input: WomanAndManHoldingHands, tones: []Tone{MediumLight}, expected: "\U0001f46b\U0001F3FC"},
58 {input: WomanAndManHoldingHands, tones: []Tone{Medium, Dark}, expected: "\U0001f469\U0001F3FD\u200d\U0001f91d\u200d\U0001f468\U0001F3FF"},
59 }
60
61 for i, tc := range tt {
62 got := tc.input.Tone(tc.tones...)
63 if got != tc.expected {
64 t.Fatalf("test case %v fail: got: %v, expected: %v", i+1, got, tc.expected)
65 }
66 }
67}
68
69func TestCountryFlag(t *testing.T) {
70 tt := []struct {
71 input string
72 expected Emoji
73 }{
74 {input: "tr", expected: FlagForTurkey},
75 {input: "TR", expected: FlagForTurkey},
76 {input: "us", expected: FlagForUnitedStates},
77 {input: "gb", expected: FlagForUnitedKingdom},
78 }
79
80 for i, tc := range tt {
81 got, err := CountryFlag(tc.input)
82 if err != nil {
83 t.Fatalf("test case %v fail: %v", i+1, err)
84 }
85 if got != tc.expected {
86 t.Fatalf("test case %v fail: got: %v, expected: %v", i+1, got, tc.expected)
87 }
88 }
89}
90
91func TestCountryFlagError(t *testing.T) {
92 tt := []struct {
93 input string
94 fail bool
95 }{
96 {input: "tr", fail: false},
97 {input: "a", fail: true},
98 {input: "tur", fail: true},
99 }
100
101 for i, tc := range tt {
102 _, err := CountryFlag(tc.input)
103 if (err != nil) != tc.fail {
104 t.Fatalf("test case %v fail: %v", i+1, err)
105 }
106 }
107}
108
109func TestNewEmojiTone(t *testing.T) {
110 tt := []struct {
111 input []string
112 expected EmojiWithTone
113 }{
114 {input: nil, expected: EmojiWithTone{}},
115 {input: []string{}, expected: EmojiWithTone{}},
116 {input: []string{"\U0001f64b@"}, expected: PersonRaisingHand},
117 {
118 input: []string{"\U0001f46b@", "\U0001f469@\u200d\U0001f91d\u200d\U0001f468@"},
119 expected: WomanAndManHoldingHands,
120 },
121 }
122
123 for i, tc := range tt {
124 got := newEmojiWithTone(tc.input...)
125 if got != tc.expected {
126 t.Fatalf("test case %v fail: got: %v, expected: %v", i+1, got, tc.expected)
127 }
128 }
129}
130
131func BenchmarkEmoji(b *testing.B) {
132 for n := 0; n < b.N; n++ {
133 _ = WavingHand.String()
134 }
135}
136
137func BenchmarkEmojiWithTone(b *testing.B) {
138 for n := 0; n < b.N; n++ {
139 _ = WavingHand.Tone(Medium)
140 }
141}
142
143func BenchmarkEmojiWithToneTwo(b *testing.B) {
144 for n := 0; n < b.N; n++ {
145 _ = WomanAndManHoldingHands.Tone(Medium, Dark)
146 }
147}
148
149func BenchmarkCountryFlag(b *testing.B) {
150 for n := 0; n < b.N; n++ {
151 _, _ = CountryFlag("tr")
152 }
153}