add some tests to translate pkg

pull/5425/head
Marcin Niemira 2019-10-12 12:25:53 +11:00
parent 73bf396e4d
commit b237471a17
No known key found for this signature in database
GPG Key ID: 053E25BDC33ED6A3
1 changed files with 50 additions and 0 deletions

View File

@ -51,3 +51,53 @@ func TestSetPreferredLanguage(t *testing.T) {
}
}
func TestT(t *testing.T) {
var tests = []struct {
description, input, expected string
langDef, langPref language.Tag
translations map[string]interface{}
}{
{
description: "empty string not default language",
input: "",
expected: "",
langPref: language.English,
langDef: language.Lithuanian,
},
{
description: "empty string and default language",
input: "",
expected: "",
langPref: language.English,
langDef: language.English,
},
{
description: "existing translation",
input: "cat",
expected: "kot",
langPref: language.Lithuanian,
langDef: language.English,
translations: map[string]interface{}{"cat": "kot"},
},
{
description: "not existing translation",
input: "cat",
expected: "cat",
langPref: language.Lithuanian,
langDef: language.English,
translations: map[string]interface{}{"dog": "pies"},
},
}
for _, test := range tests {
t.Run(test.description, func(t *testing.T) {
defaultLanguage = test.langDef
preferredLanguage = test.langPref
Translations = test.translations
got := T(test.input)
if test.expected != got {
t.Errorf("T(%v) shoud return %v, but got: %v", test.input, test.expected, got)
}
})
}
}