-
Notifications
You must be signed in to change notification settings - Fork 2
/
iso6391_test.go
181 lines (131 loc) · 3.43 KB
/
iso6391_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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
package iso6391
import (
"testing"
)
func TestFromCode(t *testing.T) {
lang := FromCode("en")
if lang.Name != "English" || lang.NativeName != "English" {
t.Fatalf("Expected English, but was: %v", lang)
}
lang = FromCode("zh")
if lang.Name != "Chinese" || lang.NativeName != "中文" {
t.Fatalf("Expected Chinese, but was: %v", lang)
}
lang = FromCode("xx")
if lang.Name != "" || lang.NativeName != "" {
t.Fatalf("Expected no valid language, but was: %v", lang)
}
lang = FromCode("an")
if lang.Name != "Aragonese" || lang.NativeName != "Aragonés" {
t.Fatalf("Expected Aragonese, but was: %v", lang)
}
}
func TestFromName(t *testing.T) {
lang := FromName("English")
if lang.Code != "en" || lang.NativeName != "English" {
t.Fatalf("Expected English, but was: %v", lang)
}
lang = FromName("Chinese")
if lang.Code != "zh" || lang.NativeName != "中文" {
t.Fatalf("Expected Chinese, but was: %v", lang)
}
lang = FromName("Neverheardof")
if lang.Code != "" || lang.NativeName != "" {
t.Fatalf("Expected no valid language, but was: %v", lang)
}
}
func TestFromNativeName(t *testing.T) {
lang := FromNativeName("English")
if lang.Code != "en" || lang.Name != "English" {
t.Fatalf("Expected English, but was: %v", lang)
}
lang = FromNativeName("中文")
if lang.Code != "zh" || lang.Name != "Chinese" {
t.Fatalf("Expected Chinese, but was: %v", lang)
}
lang = FromNativeName("Neverheardof")
if lang.Code != "" || lang.Name != "" {
t.Fatalf("Expected no valid language, but was: %v", lang)
}
}
func TestName(t *testing.T) {
name := Name("en")
if name != "English" {
t.Fatalf("Expected English, but was: %v", name)
}
name = Name("xx")
if name != "" {
t.Fatalf("Expected no valid name, but was: %v", name)
}
}
func TestNativeName(t *testing.T) {
name := NativeName("zh")
if name != "中文" {
t.Fatalf("Expected Chinese, but was: %v", name)
}
name = NativeName("xx")
if name != "" {
t.Fatalf("Expected no valid native name, but was: %v", name)
}
}
func TestCodeForName(t *testing.T) {
code := CodeForName("English")
if code != "en" {
t.Fatalf("Expected English, but was: %v", code)
}
code = CodeForName("Chinese")
if code != "zh" {
t.Fatalf("Expected Chinese, but was: %v", code)
}
code = CodeForName("Neverheardof")
if code != "" {
t.Fatalf("Expected no valid code, but was: %v", code)
}
}
func TestCodeForNativeName(t *testing.T) {
code := CodeForNativeName("English")
if code != "en" {
t.Fatalf("Expected English, but was: %v", code)
}
code = CodeForNativeName("中文")
if code != "zh" {
t.Fatalf("Expected Chinese, but was: %v", code)
}
code = CodeForNativeName("Neverheardof")
if code != "" {
t.Fatalf("Expected no valid code, but was: %v", code)
}
}
func TestValidCode(t *testing.T) {
if !ValidCode("en") {
t.Fatal("Code must be valid")
}
if !ValidCode("zh") {
t.Fatal("Code must be valid")
}
if ValidCode("xx") {
t.Fatal("Code must be invalid")
}
}
func TestValidName(t *testing.T) {
if !ValidName("English") {
t.Fatal("Name must be valid")
}
if !ValidName("Chinese") {
t.Fatal("Name must be valid")
}
if ValidName("Neverheardof") {
t.Fatal("Name must be invalid")
}
}
func TestValidNativeName(t *testing.T) {
if !ValidNativeName("English") {
t.Fatal("Native name must be valid")
}
if !ValidNativeName("中文") {
t.Fatal("Native name must be valid")
}
if ValidNativeName("Neverheardof") {
t.Fatal("Native name must be invalid")
}
}