Exemple #1
0
func TestInterval(t *testing.T) {
	expect := map[float64]string{
		-1e-30: "outside",
		0:      "inside",
		.5:     "inside",
		.99999: "inside",
		1:      "outside",
	}

	contents := map[string]string{
		"plurals:t0:range(0,1)": "inside",
		"plurals:t0:default":    "outside",
	}

	code := "l6"

	ginta.Register(simple.New().AddLanguage(code, code, contents))

	if p, err := parse([]string{"t0"}); err == nil {
		for key, val := range expect {
			if str := p.Converter().Convert(ginta.Locale(code), key).(string); str != val {
				t.Error(key, val, str)
			}
		}
	} else {
		t.Error(p, err)
	}
}
Exemple #2
0
func TestSimple(t *testing.T) {
	ginta.Register(New().AddLanguage("l1", "Language 1", l1Map).AddLanguage("l2", "Language 2", l2Map))

	lang1 := ginta.Locale("l1")
	lang2 := ginta.Locale("l2")

	if str, err := lang1.GetResource(e1); err != nil || str != hello {
		t.Error(str, err)
	}

	if str, err := lang1.GetResource(e2); err == nil {
		t.Error(str, err)
	}

	if str, err := lang2.GetResource(e1); err != nil || str != feature {
		t.Error(str, err)
	}

	if str, err := lang2.GetResource(e2); err != nil || str != missing {
		t.Error(str, err)
	}
}
Exemple #3
0
func doTest(t *testing.T, expect map[int64]string, contents map[string]string, code string) {
	ginta.Register(simple.New().AddLanguage(code, code, contents))

	if p, err := parse([]string{"t0"}); err == nil {
		for key, val := range expect {
			if str := p.Converter().Convert(ginta.Locale(code), key).(string); str != val {
				t.Error(key, val, str)
			}
		}
	} else {
		t.Error(p, err)
	}
}
Exemple #4
0
func TestInputTypes(t *testing.T) {
	expect := []interface{}{
		inter{},
		int(1),
		int8(2),
		int16(3),
		int32(4),
		int64(5),
		uint(6),
		uint8(7),
		uint16(8),
		uint32(9),
		uint64(10),
		float32(11),
		float64(12),
	}

	ginta.Register(simple.New().AddLanguage("lx", "Language 3", map[string]string{
		"plurals:t0:eq1":  "1",
		"plurals:t0:eq2":  "2",
		"plurals:t0:eq3":  "3",
		"plurals:t0:eq4":  "4",
		"plurals:t0:eq5":  "5",
		"plurals:t0:eq6":  "6",
		"plurals:t0:eq7":  "7",
		"plurals:t0:eq8":  "8",
		"plurals:t0:eq9":  "9",
		"plurals:t0:eq10": "10",
		"plurals:t0:eq11": "11",
		"plurals:t0:eq12": "12",
		"plurals:t0:eq0":  "0",
	}))

	if p, err := parse([]string{"t0"}); err == nil {
		var b bytes.Buffer
		for _, val := range expect {
			str := p.Converter().Convert(ginta.Locale("lx"), val).(string)
			b.WriteString(str)
		}

		if b.String() != "0123456789101112" {
			t.Error(b.String())
		}
	} else {
		t.Error(p, err)
	}
}
Exemple #5
0
func TestLongWithSubstitutions(t *testing.T) {
	de()
	format := dateFormatType(DateTimeFormat)
	input, err := format.Compile([]string{OptionLong})

	if err != nil {
		t.Error(err)
	}

	if input.Converter() == nil {
		t.Error("No converter function")
	}

	example := time.Date(2013, 5, 22, 22, 07, 12, 0, time.UTC)

	if conv := input.Converter().Convert(ginta.Locale("de"), example); conv != "Mittwoch, 22. Mai 2013, um 22:07" {
		t.Error(conv)
	}
}
Exemple #6
0
func TestSimpleDate(t *testing.T) {
	en()
	format := dateFormatType(DateFormat)
	input, err := format.Compile([]string{})

	if err != nil {
		t.Error(err)
	}

	if input.Converter() == nil {
		t.Error("No converter function")
	}

	example := time.Date(2013, 5, 20, 17, 25, 29, 0, time.UTC)

	if conv := input.Converter().Convert(ginta.Locale("en"), example); conv != "May 20, 2013" {
		t.Error(conv)
	}
}
Exemple #7
0
func TestOneTwoThree(t *testing.T) {
	expect := map[int64]string{
		1: "one",
		2: "two",
		3: "three",
	}

	ginta.Register(simple.New().AddLanguage("l1", "Language 1", map[string]string{
		"plurals:t0:eq1": "one",
		"plurals:t0:eq2": "two",
		"plurals:t0:eq3": "three",
	}))

	if p, err := parse([]string{"t0"}); err == nil {
		for key, val := range expect {
			if str := p.Converter().Convert(ginta.Locale("l1"), key).(string); str != val {
				t.Error(key, val, str)
			}
		}
	} else {
		t.Error(p, err)
	}
}
Exemple #8
0
func TestDescendDirTree(t *testing.T) {
	dir := prepare("t3", t)
	defer scrub(dir, t)

	expect := map[string]string{
		"test:err_something_went_wrong": "General Error",
		"test:err_file_not_found":       "Its gone!",
		"test:err_no_space_left":        "No space left on device",
		"a:longer:path:greeting":        "Hello World",
		"internal:DisplayName":          "English",
	}

	ginta.Register(New(dir))
	locale := ginta.Locale("en")

	for key, expectedVal := range expect {
		if actualVal, err := locale.GetResource(key); err != nil {
			t.Error(err)
		} else if expectedVal != actualVal {
			t.Errorf("Expected %s but got %s", expectedVal, actualVal)
		}
	}
}