| 1 |
package i18n |
| 2 |
|
| 3 |
import "testing" |
| 4 |
|
| 5 |
|
| 6 |
var _ Translator = Dict{}.Get |
| 7 |
|
| 8 |
func TestDict(t *testing.T) { |
| 9 |
const ( |
| 10 |
en = iota |
| 11 |
de |
| 12 |
hu |
| 13 |
gr |
| 14 |
) |
| 15 |
get := Dict{ |
| 16 |
en: "I%d", |
| 17 |
hu: "én%d", |
| 18 |
de: Empty, |
| 19 |
}.Get |
| 20 |
|
| 21 |
cases := []struct { |
| 22 |
name string |
| 23 |
locale int |
| 24 |
args []interface{} |
| 25 |
exp string |
| 26 |
}{ |
| 27 |
{"en-without-args", en, nil, "I%d"}, |
| 28 |
{"en-with-zero-args", en, []interface{}{}, "I%!d(MISSING)"}, |
| 29 |
{"en-with-args", en, []interface{}{1}, "I1"}, |
| 30 |
{"hu-without-args", hu, nil, "én%d"}, |
| 31 |
{"hu-with-zero-args", hu, []interface{}{}, "én%!d(MISSING)"}, |
| 32 |
{"hu-with-args", hu, []interface{}{1}, "én1"}, |
| 33 |
{"de-without-args", de, nil, ""}, |
| 34 |
{"de-with-zero-args", de, []interface{}{}, ""}, |
| 35 |
{"de-with-args", de, []interface{}{1}, ""}, |
| 36 |
{"gr-without-args", gr, nil, "I%d"}, |
| 37 |
{"gr-with-zero-args", gr, []interface{}{}, "I%!d(MISSING)"}, |
| 38 |
{"gr-with-args", gr, []interface{}{1}, "I1"}, |
| 39 |
} |
| 40 |
|
| 41 |
for _, c := range cases { |
| 42 |
if got := get(c.locale, c.args...); got != c.exp { |
| 43 |
t.Errorf("[%s] Expected: %s, got: %s", c.name, c.exp, got) |
| 44 |
} |
| 45 |
} |
| 46 |
} |