From f5437632f486b7d0a0a181c58f113c86d032b02c Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Mon, 24 Apr 2017 20:11:36 -0400 Subject: Upgrading server dependancies (#6215) --- .../nicksnyder/go-i18n/i18n/translations_test.go | 89 ++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 vendor/github.com/nicksnyder/go-i18n/i18n/translations_test.go (limited to 'vendor/github.com/nicksnyder/go-i18n/i18n/translations_test.go') diff --git a/vendor/github.com/nicksnyder/go-i18n/i18n/translations_test.go b/vendor/github.com/nicksnyder/go-i18n/i18n/translations_test.go new file mode 100644 index 000000000..86c580833 --- /dev/null +++ b/vendor/github.com/nicksnyder/go-i18n/i18n/translations_test.go @@ -0,0 +1,89 @@ +package i18n + +import ( + "testing" + + "github.com/nicksnyder/go-i18n/i18n/bundle" +) + +var bobMap = map[string]interface{}{"Person": "Bob"} +var bobStruct = struct{ Person string }{Person: "Bob"} + +var testCases = []struct { + id string + arg interface{} + want string +}{ + {"program_greeting", nil, "Hello world"}, + {"person_greeting", bobMap, "Hello Bob"}, + {"person_greeting", bobStruct, "Hello Bob"}, + + {"your_unread_email_count", 0, "You have 0 unread emails."}, + {"your_unread_email_count", 1, "You have 1 unread email."}, + {"your_unread_email_count", 2, "You have 2 unread emails."}, + {"my_height_in_meters", "1.7", "I am 1.7 meters tall."}, + + {"person_unread_email_count", []interface{}{0, bobMap}, "Bob has 0 unread emails."}, + {"person_unread_email_count", []interface{}{1, bobMap}, "Bob has 1 unread email."}, + {"person_unread_email_count", []interface{}{2, bobMap}, "Bob has 2 unread emails."}, + {"person_unread_email_count", []interface{}{0, bobStruct}, "Bob has 0 unread emails."}, + {"person_unread_email_count", []interface{}{1, bobStruct}, "Bob has 1 unread email."}, + {"person_unread_email_count", []interface{}{2, bobStruct}, "Bob has 2 unread emails."}, + + {"person_unread_email_count_timeframe", []interface{}{3, map[string]interface{}{ + "Person": "Bob", + "Timeframe": "0 days", + }}, "Bob has 3 unread emails in the past 0 days."}, + {"person_unread_email_count_timeframe", []interface{}{3, map[string]interface{}{ + "Person": "Bob", + "Timeframe": "1 day", + }}, "Bob has 3 unread emails in the past 1 day."}, + {"person_unread_email_count_timeframe", []interface{}{3, map[string]interface{}{ + "Person": "Bob", + "Timeframe": "2 days", + }}, "Bob has 3 unread emails in the past 2 days."}, +} + +func testFile(t *testing.T, path string) { + b := bundle.New() + b.MustLoadTranslationFile(path) + + T, err := b.Tfunc("en-US") + if err != nil { + t.Fatal(err) + } + + for _, tc := range testCases { + var args []interface{} + if _, ok := tc.arg.([]interface{}); ok { + args = tc.arg.([]interface{}) + } else { + args = []interface{}{tc.arg} + } + + got := T(tc.id, args...) + if got != tc.want { + t.Error("got: %v; want: %v", got, tc.want) + } + } +} + +func TestJSONParse(t *testing.T) { + testFile(t, "../goi18n/testdata/expected/en-us.all.json") +} + +func TestYAMLParse(t *testing.T) { + testFile(t, "../goi18n/testdata/en-us.yaml") +} + +func TestJSONFlatParse(t *testing.T) { + testFile(t, "../goi18n/testdata/en-us.flat.json") +} + +func TestYAMLFlatParse(t *testing.T) { + testFile(t, "../goi18n/testdata/en-us.flat.yaml") +} + +func TestTOMLFlatParse(t *testing.T) { + testFile(t, "../goi18n/testdata/en-us.flat.toml") +} -- cgit v1.2.3-1-g7c22