-
Notifications
You must be signed in to change notification settings - Fork 0
/
i18n_test.go
40 lines (32 loc) · 904 Bytes
/
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
package i18n_test
import (
"reflect"
"testing"
"github.com/N1xx1/golang-i18n"
)
func assertEqual(t *testing.T, expected interface{}, actual interface{}) bool {
if !reflect.DeepEqual(expected, actual) {
t.Error("Expected ", expected, ", got ", actual)
return false
}
return true
}
func assertNil(t *testing.T, actual interface{}) bool {
if actual != nil {
t.Error("Expected nil, got ", actual)
return false
}
return true
}
func TestExampleFile(t *testing.T) {
T, err := i18n.Tfunc("./example_configuration.i18n")
assertNil(t, err)
assertEqual(t, "Hello World!", T("helloWorld"))
assertEqual(t, "There are 42 people", T("exampleCount", 42))
}
func TestGlobalT(t *testing.T) {
err := i18n.GlobalTfunc("./example_configuration.i18n")
assertNil(t, err)
assertEqual(t, "Hello World!", i18n.T("helloWorld"))
assertEqual(t, "There are 42 people", i18n.T("exampleCount", 42))
}