-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemoji_flags_test.go
86 lines (82 loc) · 1.35 KB
/
emoji_flags_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
package emojiflags
import (
"testing"
"unicode"
"unicode/utf8"
)
func Test_getFlag(t *testing.T) {
type args struct {
country string
}
tests := []struct {
name string
args args
expectedLen int
}{
{
"Should handle correct 3 characters input",
args{"VNM"},
3,
},
{
"Should handle correct 2 characters input",
args{"VN"},
3,
},
{
"Should return empty string if no 3 letters code found",
args{"BOB"},
0,
},
{
"Should return empty string if no 2 letters match found",
args{"AA"},
0,
},
{
"Should uppercase input",
args{"vnm"},
3,
},
{
"Could get England emoji",
args{"GB-ENG"},
7,
},
{
"Could get CIOC code",
args{"GER"},
3,
},
{
"Return empty string if code is empty",
args{""},
0,
},
{
"Could get England flag with short code",
args{"ENG"},
7,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := GetFlag(tt.args.country)
if !utf8.ValidString(got) {
t.Errorf("GetFlag() expected valid flag got %v", got)
}
if GetPrintableLength(got) != tt.expectedLen {
t.Errorf("expected length emoji of %v got %v", tt.expectedLen, GetPrintableLength(got))
}
})
}
}
func GetPrintableLength(s string) int {
res := 0
for i := range s {
if unicode.IsPrint(rune(s[i])) {
res++
}
}
return res
}