Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/go-i18n.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Snyder <nickdsnyder@gmail.com>2018-09-24 09:19:42 +0300
committerGitHub <noreply@github.com>2018-09-24 09:19:42 +0300
commitb8eb0d0a755e01f373c35ea14ec80a32b258079b (patch)
treeb63e71b54750b4ceac993ceb0c36067b2f357ffa
parent04f547cc50da4c144c5fdfd4495aef143637a236 (diff)
more Localizer tests (#127)
-rw-r--r--v2/i18n/localizer_test.go45
1 files changed, 43 insertions, 2 deletions
diff --git a/v2/i18n/localizer_test.go b/v2/i18n/localizer_test.go
index 9df62f5..b7024b7 100644
--- a/v2/i18n/localizer_test.go
+++ b/v2/i18n/localizer_test.go
@@ -473,6 +473,47 @@ func TestLocalizer_Localize(t *testing.T) {
},
expectedLocalized: "Hello!",
},
+ {
+ name: "test slow path default message",
+ defaultLanguage: language.Spanish,
+ messages: map[language.Tag][]*Message{
+ language.English: {{
+ ID: "Goodbye",
+ Other: "Goodbye!",
+ }},
+ language.AmericanEnglish: {{
+ ID: "Goodbye",
+ Other: "Goodbye!",
+ }},
+ },
+ acceptLangs: []string{"en-US"},
+ conf: &LocalizeConfig{
+ DefaultMessage: &Message{
+ ID: "Hello",
+ Other: "Hola!",
+ },
+ },
+ expectedLocalized: "Hola!",
+ },
+ {
+ name: "test slow path no message",
+ defaultLanguage: language.Spanish,
+ messages: map[language.Tag][]*Message{
+ language.English: {{
+ ID: "Goodbye",
+ Other: "Goodbye!",
+ }},
+ language.AmericanEnglish: {{
+ ID: "Goodbye",
+ Other: "Goodbye!",
+ }},
+ },
+ acceptLangs: []string{"en-US"},
+ conf: &LocalizeConfig{
+ MessageID: "Hello",
+ },
+ expectedErr: &messageNotFoundErr{messageID: "Hello"},
+ },
}
for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
@@ -483,10 +524,10 @@ func TestLocalizer_Localize(t *testing.T) {
localizer := NewLocalizer(bundle, testCase.acceptLangs...)
localized, err := localizer.Localize(testCase.conf)
if !reflect.DeepEqual(err, testCase.expectedErr) {
- t.Errorf("expected %#v; got %#v", testCase.expectedErr, err)
+ t.Errorf("expected error %#v; got %#v", testCase.expectedErr, err)
}
if localized != testCase.expectedLocalized {
- t.Errorf("expected %q; got %q", testCase.expectedLocalized, localized)
+ t.Errorf("expected localized string %q; got %q", testCase.expectedLocalized, localized)
}
})
}