Merge pull request #5425 from n0npax/improve-translations-test-coverage

improve translations test coverage
pull/5243/head^2
Thomas Strömberg 2019-10-17 14:50:12 -07:00 committed by GitHub
commit b89bfbe3d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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)
}
})
}
}