-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathi18n_test.go
53 lines (43 loc) · 1.43 KB
/
i18n_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
package i18n
import (
"fmt"
"testing"
)
type backend struct{}
func (b *backend) LoadTranslations() (translations []*Translation) { return translations }
func (b *backend) SaveTranslation(t *Translation) error { return nil }
func (b *backend) DeleteTranslation(t *Translation) error { return nil }
const BIGNUM = 10000
// run TestConcurrent* tests with -race flag would be better
func TestConcurrentReadWrite(t *testing.T) {
i18n := New(&backend{})
go func() {
for i := 0; i < BIGNUM; i++ {
i18n.AddTranslation(&Translation{Key: fmt.Sprintf("xx-%d", i), Locale: "xx", Value: fmt.Sprint(i)})
}
}()
for i := 0; i < BIGNUM; i++ {
i18n.T("xx", fmt.Sprintf("xx-%d", i))
}
}
func TestConcurrentDeleteWrite(t *testing.T) {
i18n := New(&backend{})
go func() {
for i := 0; i < BIGNUM; i++ {
i18n.AddTranslation(&Translation{Key: fmt.Sprintf("xx-%d", i), Locale: "xx", Value: fmt.Sprint(i)})
}
}()
for i := 0; i < BIGNUM; i++ {
i18n.DeleteTranslation(&Translation{Key: fmt.Sprintf("xx-%d", i), Locale: "xx", Value: fmt.Sprint(i)})
}
}
func TestFallbackLocale(t *testing.T) {
i18n := New(&backend{})
i18n.AddTranslation(&Translation{Key: "hello-world", Locale: "en-AU", Value: "Hello World"})
if i18n.Fallbacks("en-AU").T("en-UK", "hello-world") != "Hello World" {
t.Errorf("Should fallback en-UK to en-US")
}
if i18n.T("en-DE", "hello-world") != "hello-world" {
t.Errorf("Haven't setup any fallback")
}
}