12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- package domain
- import (
- "fmt"
- "testing"
- "github.com/nicksnyder/go-i18n/v2/i18n"
- "golang.org/x/text/language"
- )
- /*
- TestMakeErrorHappy tests localization of a known error.
- */
- func TestMakeErrorHappy(t *testing.T) {
- frNoError := i18n.Message{
- ID: NoError.ID,
- Other: "Pas d'erreur",
- }
- bundle := &i18n.Bundle{DefaultLanguage: language.English}
- bundle.AddMessages(language.English, &NoError)
- bundle.AddMessages(language.French, &frNoError)
- type testPass struct {
- tag string
- error i18n.Message
- details string
- expected string
- }
- passes := []testPass{
- {language.English.String(), NoError, "", NoError.Other},
- {language.English.String(), NoError, "details", NoError.Other + ": details"},
- {language.French.String(), frNoError, "", frNoError.Other},
- {language.French.String(), frNoError, "details", frNoError.Other + ": details"},
- }
- for _, pass := range passes {
- var subTestName string
- if pass.details == "" {
- subTestName = fmt.Sprintf("%s/<no details>", pass.tag)
- } else {
- subTestName = fmt.Sprintf("%s/%s", pass.tag, pass.details)
- }
- t.Run(subTestName, func(t *testing.T) {
- localizer := i18n.NewLocalizer(bundle, pass.tag)
- err := MakeError(localizer, pass.error.ID, pass.details)
- expected := pass.expected
- if err.Error() != expected {
- t.Errorf("Localized \"%s\" version (%v) does not match expected value (%v)\n",
- pass.tag, err.Error(), expected)
- }
- })
- }
- }
|