all repos — emoji @ 7a759e4eca7cd14139fb3ccb79caacccb8c47cbb

A minimalistic emoji package for Go (golang)

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: FlagsForFlagTurkey, 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).String()
 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 TestEmojiWithToneTwo(t *testing.T) {
 51	tt := []struct {
 52		input    EmojiWithTone
 53		tones    []Tone
 54		expected string
 55	}{
 56		{input: WomanAndManHoldingHandsWithTwoTone, tones: []Tone{}, expected: "\U0001F469\u200D\U0001F91D\u200D\U0001F468"},
 57		{input: WomanAndManHoldingHandsWithTwoTone, tones: []Tone{MediumLight}, expected: "\U0001F469\U0001F3FC\u200D\U0001F91D\u200D\U0001F468\U0001F3FC"},
 58		{input: WomanAndManHoldingHandsWithTwoTone, 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...).String()
 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: FlagsForFlagTurkey},
 75		{input: "TR", expected: FlagsForFlagTurkey},
 76		{input: "us", expected: FlagsForFlagUnitedStates},
 77		{input: "gb", expected: FlagsForFlagUnitedKingdom},
 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}