2023-11-12 22:32:34 +00:00
|
|
|
package domain_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2023-12-24 01:54:04 +00:00
|
|
|
"source.toby3d.me/toby3d/home/internal/common"
|
2023-11-12 22:32:34 +00:00
|
|
|
"source.toby3d.me/toby3d/home/internal/domain"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestLanguage_Lang(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
for name, tc := range map[string]struct {
|
2023-11-12 23:12:37 +00:00
|
|
|
input string
|
2023-11-12 22:32:34 +00:00
|
|
|
expect string
|
|
|
|
}{
|
2023-12-24 01:54:04 +00:00
|
|
|
"2letter": {"en", "en"},
|
|
|
|
"3letter": {"eng", "en"},
|
|
|
|
"region": {"en-US", "en"},
|
|
|
|
common.Und: {"", ""},
|
2023-11-12 22:32:34 +00:00
|
|
|
} {
|
|
|
|
name, tc := name, tc
|
|
|
|
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
if actual := domain.NewLanguage(tc.input).Lang(); actual != tc.expect {
|
|
|
|
t.Errorf("Lang() = %s, want %s", actual, tc.expect)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLanguage_Code(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
for name, tc := range map[string]struct {
|
2023-11-12 23:12:37 +00:00
|
|
|
input string
|
2023-11-12 22:32:34 +00:00
|
|
|
expect string
|
|
|
|
}{
|
2023-12-24 01:54:04 +00:00
|
|
|
"2letter": {"en", "en"},
|
|
|
|
"3letter": {"eng", "en"},
|
|
|
|
"region": {"en-US", "en-US"},
|
|
|
|
common.Und: {"", ""},
|
2023-11-12 22:32:34 +00:00
|
|
|
} {
|
|
|
|
name, tc := name, tc
|
|
|
|
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
if actual := domain.NewLanguage(tc.input).Code(); actual != tc.expect {
|
|
|
|
t.Errorf("Code() = %s, want %s", actual, tc.expect)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLanguage_Dir(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
for name, tc := range map[string]struct {
|
2023-11-12 23:12:37 +00:00
|
|
|
input string
|
2023-11-12 22:32:34 +00:00
|
|
|
expect string
|
|
|
|
}{
|
2023-12-24 01:54:04 +00:00
|
|
|
"2letter": {"en", "ltr"},
|
|
|
|
"rtl": {"ur", "rtl"},
|
|
|
|
"3letter": {"eng", "ltr"},
|
|
|
|
"region": {"en-US", "ltr"},
|
|
|
|
common.Und: {"", ""},
|
2023-11-12 22:32:34 +00:00
|
|
|
} {
|
|
|
|
name, tc := name, tc
|
|
|
|
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
if actual := domain.NewLanguage(tc.input).Dir(); actual != tc.expect {
|
|
|
|
t.Errorf("Dir() = %s, want %s", actual, tc.expect)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLanguage_Name(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
for name, tc := range map[string]struct {
|
2023-11-12 23:12:37 +00:00
|
|
|
input string
|
2023-11-12 22:32:34 +00:00
|
|
|
expect string
|
|
|
|
}{
|
2023-11-12 23:12:37 +00:00
|
|
|
"localized": {"ru", "русский"},
|
|
|
|
"2letter": {"en", "english"},
|
|
|
|
"3letter": {"eng", "english"},
|
|
|
|
"region": {"en-US", "american english"},
|
2023-12-24 01:54:04 +00:00
|
|
|
common.Und: {"", ""},
|
2023-11-12 22:32:34 +00:00
|
|
|
} {
|
|
|
|
name, tc := name, tc
|
|
|
|
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
if actual := domain.NewLanguage(tc.input).Name(); actual != tc.expect {
|
|
|
|
t.Errorf("Name() = %s, want %s", actual, tc.expect)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|