You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

50 lines
1.0 KiB

  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: "de",
  23. key: "Hello world!\n",
  24. want: "Hallo Welt!\n",
  25. }, {
  26. lang: "en",
  27. key: "%d more files remaining!",
  28. args: args(1),
  29. want: "One file remaining!",
  30. }, {
  31. lang: "en-u-nu-fullwide",
  32. key: "%d more files remaining!",
  33. args: args(5),
  34. want: "There are 5 more files remaining!",
  35. }}
  36. for _, tc := range testCases {
  37. t.Run(path.Join(tc.lang, tc.key), func(t *testing.T) {
  38. p := message.NewPrinter(message.MatchLanguage(tc.lang))
  39. got := p.Sprintf(tc.key, tc.args...)
  40. if got != tc.want {
  41. t.Errorf("got %q; want %q", got, tc.want)
  42. }
  43. })
  44. }
  45. }