diff options
author | Anthony HAMON <anthony.hamon@iadvize.com> | 2018-08-20 08:53:13 +0200 |
---|---|---|
committer | Anthony HAMON <anthony.hamon@iadvize.com> | 2018-08-20 09:02:57 +0200 |
commit | 3c0fb9b32461ae2fe4e71eeeda95583bd64a812a (patch) | |
tree | d9a152c8efc229dde71ccb9ad696224a68417ef7 /pkg | |
parent | 64cf8f5b107a310e6729b68ba8d7638effd3966d (diff) |
add tests to i18n package
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/i18n/i18n_test.go | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/pkg/i18n/i18n_test.go b/pkg/i18n/i18n_test.go new file mode 100644 index 000000000..3fec62456 --- /dev/null +++ b/pkg/i18n/i18n_test.go @@ -0,0 +1,86 @@ +package i18n + +import ( + "os" + "testing" + + "github.com/nicksnyder/go-i18n/v2/i18n" + + "github.com/Sirupsen/logrus" + "github.com/stretchr/testify/assert" +) + +func TestNewLocalizer(t *testing.T) { + type scenario struct { + setup func() + test func(*Localizer, error) + teardown func() + } + + LCALL := os.Getenv("LC_ALL") + LANG := os.Getenv("LANG") + + scenarios := []scenario{ + { + func() { + os.Setenv("LC_ALL", "") + os.Setenv("LANG", "") + }, + func(l *Localizer, err error) { + assert.EqualValues(t, "C", l.GetLanguage()) + }, + func() { + os.Setenv("LC_ALL", LCALL) + os.Setenv("LANG", LANG) + }, + }, + { + func() { + os.Setenv("LC_ALL", "whatever") + os.Setenv("LANG", "whatever") + }, + func(l *Localizer, err error) { + assert.NoError(t, err) + + assert.EqualValues(t, "whatever", l.GetLanguage()) + assert.Equal(t, "Diff", l.Localize(&i18n.LocalizeConfig{ + DefaultMessage: &i18n.Message{ + ID: "DiffTitle", + }, + })) + assert.Equal(t, "Diff", l.SLocalize("DiffTitle")) + assert.Equal(t, "Are you sure you want delete the branch test ?", l.TemplateLocalize("DeleteBranchMessage", Teml{"selectedBranchName": "test"})) + }, + func() { + os.Setenv("LC_ALL", LCALL) + os.Setenv("LANG", LANG) + }, + }, + { + func() { + os.Setenv("LC_ALL", "nl") + }, + func(l *Localizer, err error) { + assert.NoError(t, err) + + assert.EqualValues(t, "nl", l.GetLanguage()) + assert.Equal(t, "Diff", l.Localize(&i18n.LocalizeConfig{ + DefaultMessage: &i18n.Message{ + ID: "DiffTitle", + }, + })) + assert.Equal(t, "Diff", l.SLocalize("DiffTitle")) + assert.Equal(t, "Weet je zeker dat je test branch wil verwijderen?", l.TemplateLocalize("DeleteBranchMessage", Teml{"selectedBranchName": "test"})) + }, + func() { + os.Setenv("LC_ALL", LCALL) + }, + }, + } + + for _, s := range scenarios { + s.setup() + s.test(NewLocalizer(logrus.New())) + s.teardown() + } +} |