-
Notifications
You must be signed in to change notification settings - Fork 1
/
discordgoi18n_test.go
99 lines (85 loc) · 2.26 KB
/
discordgoi18n_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
package discordgoi18n
import (
"testing"
"github.com/bwmarrin/discordgo"
"github.com/stretchr/testify/assert"
)
func TestFacade(t *testing.T) {
var expectedFile, expectedKey = "File", "Key"
var expectedValues Vars
var called bool
mock := newMock()
mock.SetDefaultFunc = func(locale discordgo.Locale) {
assert.Equal(t, discordgo.Italian, locale)
called = true
}
mock.LoadBundleFunc = func(locale discordgo.Locale, file string) error {
assert.Equal(t, discordgo.French, locale)
assert.Equal(t, expectedFile, file)
called = true
return nil
}
mock.GetFunc = func(locale discordgo.Locale, key string, values Vars) string {
assert.Equal(t, discordgo.ChineseCN, locale)
assert.Equal(t, expectedValues, values)
assert.Equal(t, expectedKey, key)
called = true
return ""
}
mock.GetDefaultFunc = func(key string, values Vars) string {
assert.Equal(t, expectedValues, values)
assert.Equal(t, expectedKey, key)
called = true
return ""
}
mock.GetLocalizationsFunc = func(key string, values Vars) *map[discordgo.Locale]string {
assert.Equal(t, expectedValues, values)
assert.Equal(t, expectedKey, key)
called = true
return nil
}
instance = mock
called = false
SetDefault(discordgo.Italian)
assert.True(t, called)
called = false
assert.NoError(t, LoadBundle(discordgo.French, expectedFile))
assert.True(t, called)
called = false
expectedValues = make(Vars)
Get(discordgo.ChineseCN, expectedKey)
assert.True(t, called)
called = false
expectedValues = Vars{
"Hi": "There",
}
Get(discordgo.ChineseCN, expectedKey, expectedValues)
assert.True(t, called)
called = false
expectedValues = Vars{
"Hi": "There",
"Bye": "See u",
}
Get(discordgo.ChineseCN, expectedKey, Vars{"Hi": "There"}, Vars{"Bye": "See u"})
assert.True(t, called)
called = false
expectedValues = make(Vars)
GetDefault(expectedKey)
assert.True(t, called)
called = false
expectedValues = Vars{
"Hi": "There",
}
GetDefault(expectedKey, expectedValues)
assert.True(t, called)
called = false
expectedValues = Vars{
"Hi": "There",
"Bye": "See u",
}
GetDefault(expectedKey, Vars{"Hi": "There"}, Vars{"Bye": "See u"})
assert.True(t, called)
called = false
GetLocalizations(expectedKey, Vars{"Hi": "There"}, Vars{"Bye": "See u"})
assert.True(t, called)
}