plural_test.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright 2018 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package locale // import "miniflux.app/locale"
  5. import "testing"
  6. func TestPluralRules(t *testing.T) {
  7. scenarios := map[string]map[int]int{
  8. "default": map[int]int{
  9. 1: 0,
  10. 2: 1,
  11. 5: 1,
  12. },
  13. "ar_AR": map[int]int{
  14. 0: 0,
  15. 1: 1,
  16. 2: 2,
  17. 5: 3,
  18. 11: 4,
  19. 200: 5,
  20. },
  21. "cs_CZ": map[int]int{
  22. 1: 0,
  23. 2: 1,
  24. 5: 2,
  25. },
  26. "pl_PL": map[int]int{
  27. 1: 0,
  28. 2: 1,
  29. 5: 2,
  30. },
  31. "pt_BR": map[int]int{
  32. 1: 0,
  33. 2: 1,
  34. 5: 1,
  35. },
  36. "ru_RU": map[int]int{
  37. 1: 0,
  38. 2: 1,
  39. 5: 2,
  40. },
  41. "sr_RS": map[int]int{
  42. 1: 0,
  43. 2: 1,
  44. 5: 2,
  45. },
  46. "zh_CN": map[int]int{
  47. 1: 0,
  48. 5: 0,
  49. },
  50. }
  51. for rule, values := range scenarios {
  52. for input, expected := range values {
  53. result := pluralForms[rule](input)
  54. if result != expected {
  55. t.Errorf(`Unexpected result for %q rule, got %d instead of %d for %d as input`, rule, result, expected, input)
  56. }
  57. }
  58. }
  59. }