-
Notifications
You must be signed in to change notification settings - Fork 0
/
iso6392_test.go
79 lines (72 loc) · 1.83 KB
/
iso6392_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
package iso639_2
import (
"testing"
)
func TestFromCode(t *testing.T) {
tests := []struct {
code string
expectedName string
}{
{"rus", "Russian"},
{"ru", "Russian"},
{"de", "German"},
{"ger", "German"},
{"aaa", ""}, // doesn't exist
}
for _, tt := range tests {
t.Run(tt.code, func(t *testing.T) {
actual := FromCode(tt.code)
if tt.expectedName == "" {
if actual != nil {
t.Errorf("FromCode() = %v, expected nil", actual)
}
} else if actual == nil || !sliceContainsString(actual.English, tt.expectedName) {
t.Errorf("FromCode() = %v, expected Language with english name %v", actual, tt.expectedName)
}
})
}
}
func TestFromEnglishName(t *testing.T) {
tests := []struct {
name string
expectedAlpha3 string
}{
{"Russian", "rus"},
{"German", "ger"},
{"Elvish", ""}, // doesn't exist (ouch)
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
actual := FromEnglishName(tt.name)
if tt.expectedAlpha3 == "" {
if actual != nil {
t.Errorf("FromCode() = %v, expected nil", actual)
}
} else if actual == nil || actual.Alpha3 != tt.expectedAlpha3 {
t.Errorf("FromCode() = %v, expected Language with Alpha3 %v", actual, tt.expectedAlpha3)
}
})
}
}
func TestFromFrenchName(t *testing.T) {
tests := []struct {
name string
expectedAlpha3 string
}{
{"russe", "rus"},
{"allemand", "ger"},
{"Klingon", ""}, // doesn't exist (ouch)
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
actual := FromFrenchName(tt.name)
if tt.expectedAlpha3 == "" {
if actual != nil {
t.Errorf("FromCode() = %v, expected nil", actual)
}
} else if actual == nil || actual.Alpha3 != tt.expectedAlpha3 {
t.Errorf("FromCode() = %v, expected Language with Alpha3 %v", actual, tt.expectedAlpha3)
}
})
}
}