...
1
2
3
4
5 package main
6
7 import (
8 "path"
9 "testing"
10
11 "golang.org/x/text/message"
12 )
13
14 func TestCatalog(t *testing.T) {
15 args := func(a ...interface{}) []interface{} { return a }
16 testCases := []struct {
17 lang string
18 key string
19 args []interface{}
20 want string
21 }{{
22 lang: "en",
23 key: "Hello world!\n",
24 want: "Hello world!\n",
25 }, {
26 lang: "en",
27 key: "non-existing-key\n",
28 want: "non-existing-key\n",
29 }, {
30 lang: "de",
31 key: "Hello world!\n",
32 want: "Hallo Welt!\n",
33 }, {
34 lang: "en",
35 key: "%d more files remaining!",
36 args: args(1),
37 want: "One file remaining!",
38 }, {
39 lang: "en-u-nu-fullwide",
40 key: "%d more files remaining!",
41 args: args(5),
42 want: "There are 5 more files remaining!",
43 }}
44 for _, tc := range testCases {
45 t.Run(path.Join(tc.lang, tc.key), func(t *testing.T) {
46 p := message.NewPrinter(message.MatchLanguage(tc.lang))
47 got := p.Sprintf(tc.key, tc.args...)
48 if got != tc.want {
49 t.Errorf("got %q; want %q", got, tc.want)
50 }
51 })
52 }
53 }
54
View as plain text