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 BenchmarkEmoji(b *testing.B) {
110 for n := 0; n < b.N; n++ {
111 _ = WavingHand.String()
112 }
113}
114
115func BenchmarkEmojiWithTone(b *testing.B) {
116 for n := 0; n < b.N; n++ {
117 _ = WavingHand.Tone(Medium)
118 }
119}
120
121func BenchmarkEmojiWithToneTwo(b *testing.B) {
122 for n := 0; n < b.N; n++ {
123 _ = WomanAndManHoldingHands.Tone(Medium, Dark)
124 }
125}
126
127func BenchmarkCountryFlag(b *testing.B) {
128 for n := 0; n < b.N; n++ {
129 _, _ = CountryFlag("tr")
130 }
131}