catalog_test.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright 2017 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package main
  5. import (
  6. "path"
  7. "testing"
  8. "golang.org/x/text/message"
  9. )
  10. func TestCatalog(t *testing.T) {
  11. args := func(a ...interface{}) []interface{} { return a }
  12. testCases := []struct {
  13. lang string
  14. key string
  15. args []interface{}
  16. want string
  17. }{{
  18. lang: "en",
  19. key: "Hello world!\n",
  20. want: "Hello world!\n",
  21. }, {
  22. lang: "en",
  23. key: "non-existing-key\n",
  24. want: "non-existing-key\n",
  25. }, {
  26. lang: "de",
  27. key: "Hello world!\n",
  28. want: "Hallo Welt!\n",
  29. }, {
  30. lang: "en",
  31. key: "%d more files remaining!",
  32. args: args(1),
  33. want: "One file remaining!",
  34. }, {
  35. lang: "en-u-nu-fullwide",
  36. key: "%d more files remaining!",
  37. args: args(5),
  38. want: "There are 5 more files remaining!",
  39. }}
  40. for _, tc := range testCases {
  41. t.Run(path.Join(tc.lang, tc.key), func(t *testing.T) {
  42. p := message.NewPrinter(message.MatchLanguage(tc.lang))
  43. got := p.Sprintf(tc.key, tc.args...)
  44. if got != tc.want {
  45. t.Errorf("got %q; want %q", got, tc.want)
  46. }
  47. })
  48. }
  49. }