Skip to content
Snippets Groups Projects
Commit 8701e67f authored by Semyon Krestyaninov's avatar Semyon Krestyaninov :dog2: Committed by Pavel Antonov
Browse files

Добавлен метод `Equal` для `locales.Locale`

parent 399a9731
No related branches found
No related tags found
No related merge requests found
...@@ -27,6 +27,10 @@ func (locale *Locale) IsDefault() bool { ...@@ -27,6 +27,10 @@ func (locale *Locale) IsDefault() bool {
return locale.ID == DefaultID return locale.ID == DefaultID
} }
func (locale *Locale) Equal(other *Locale) bool {
return locale == other || locale != nil && other != nil && *locale == *other
}
// Возвращает язык локали, например "en", "ru" // Возвращает язык локали, например "en", "ru"
func (locale *Locale) GetLanguage() string { func (locale *Locale) GetLanguage() string {
lang, err := language.Parse(locale.Code) lang, err := language.Parse(locale.Code)
......
...@@ -36,3 +36,46 @@ func TestLocale_GetLanguage(t *testing.T) { ...@@ -36,3 +36,46 @@ func TestLocale_GetLanguage(t *testing.T) {
}) })
} }
} }
func TestLocale_Equal(t *testing.T) {
tests := []struct {
locale *Locale
other *Locale
want bool
}{
{
locale: &Locale{Code: "ru-RU"},
other: &Locale{Code: "ru-RU"},
want: true,
},
{
locale: &Locale{Code: "ru-RU"},
other: &Locale{Code: "ru-RU", Fallback: "en-US"},
want: false,
},
{
locale: &Locale{Code: "ru-RU", Fallback: "en-US"},
other: &Locale{Code: "ru-RU"},
want: false,
},
{
locale: &Locale{Code: "ru-RU"},
other: nil,
want: false,
},
{
locale: nil,
other: &Locale{Code: "ru-RU"},
want: false,
},
{
locale: nil,
other: nil,
want: true,
},
}
for _, tt := range tests {
got := tt.locale.Equal(tt.other)
require.Equal(t, tt.want, got)
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment