plural_test.go 942 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
  2. // SPDX-License-Identifier: Apache-2.0
  3. package locale // import "miniflux.app/v2/internal/locale"
  4. import "testing"
  5. func TestPluralRules(t *testing.T) {
  6. scenarios := map[string]map[int]int{
  7. "default": {
  8. 1: 0,
  9. 2: 1,
  10. 5: 1,
  11. },
  12. "ar_AR": {
  13. 0: 0,
  14. 1: 1,
  15. 2: 2,
  16. 5: 3,
  17. 11: 4,
  18. 200: 5,
  19. },
  20. "cs_CZ": {
  21. 1: 0,
  22. 2: 1,
  23. 5: 2,
  24. },
  25. "pl_PL": {
  26. 1: 0,
  27. 2: 1,
  28. 5: 2,
  29. },
  30. "pt_BR": {
  31. 1: 0,
  32. 2: 1,
  33. 5: 1,
  34. },
  35. "ru_RU": {
  36. 1: 0,
  37. 2: 1,
  38. 5: 2,
  39. },
  40. "sr_RS": {
  41. 1: 0,
  42. 2: 1,
  43. 5: 2,
  44. },
  45. "zh_CN": {
  46. 1: 0,
  47. 5: 0,
  48. },
  49. }
  50. for rule, values := range scenarios {
  51. for input, expected := range values {
  52. result := pluralForms[rule](input)
  53. if result != expected {
  54. t.Errorf(`Unexpected result for %q rule, got %d instead of %d for %d as input`, rule, result, expected, input)
  55. }
  56. }
  57. }
  58. }