aboutsummaryrefslogtreecommitdiff
path: root/i18n/locale_test.go
blob: 6887064e8753274762348ea9faab182fb2797304 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package i18n

import (
	"testing"
)

func TestLocale(t *testing.T) {
	l0 := supportedLocales("ja-JP;q")
	if len(l0) != 1 {
		t.Errorf("Expected number of locales \"1\", got %d", len(l0))
		t.Fail()
	}
	l1 := supportedLocales("en,de-AT; q=0.8,de;q=0.6,bg; q=0.4,en-US;q=0.2,sr;q=0.2")
	if len(l1) != 6 {
		t.Errorf("Expected number of locales \"6\", got %d", len(l1))
		t.Fail()
	}
	l2 := supportedLocales("en")
	if len(l2) != 1 {
		t.Errorf("Expected number of locales \"1\", got %d", len(l2))
		t.Fail()
	}
	l3 := supportedLocales("")
	if len(l3) != 0 {
		t.Errorf("Expected number of locales \"0\", got %d", len(l3))
		t.Fail()
	}
	l4 := ParseLocale("en_US")
	if l4.Lang != "en" || l4.Country != "US" {
		t.Errorf("Expected \"en\" and \"US\", got %s and %s", l4.Lang, l4.Country)
		t.Fail()
	}
	l5 := ParseLocale("en")
	if l5.Lang != "en" || l5.Country != "" {
		t.Errorf("Expected \"en\" and \"\", got %s and %s", l5.Lang, l5.Country)
		t.Fail()
	}

}