Skip to content
Snippets Groups Projects
Commit 4baed953 authored by Pavel Antonov's avatar Pavel Antonov :asterisk:
Browse files

Merge branch 'feature/PRXS-2648-LocalizedSync' into 'master'

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

See merge request perxis/perxis-go!286
parents 399a9731 8701e67f
No related branches found
No related tags found
No related merge requests found
......@@ -27,6 +27,10 @@ func (locale *Locale) IsDefault() bool {
return locale.ID == DefaultID
}
func (locale *Locale) Equal(other *Locale) bool {
return locale == other || locale != nil && other != nil && *locale == *other
}
// Возвращает язык локали, например "en", "ru"
func (locale *Locale) GetLanguage() string {
lang, err := language.Parse(locale.Code)
......
......@@ -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