plural_namer_test.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. package namer
  2. import (
  3. "testing"
  4. "go-common/app/tool/gengo/types"
  5. )
  6. func TestPluralNamer(t *testing.T) {
  7. exceptions := map[string]string{
  8. // The type name is already in the plural form
  9. "Endpoints": "endpoints",
  10. }
  11. public := NewPublicPluralNamer(exceptions)
  12. private := NewPrivatePluralNamer(exceptions)
  13. cases := []struct {
  14. typeName string
  15. expectedPrivate string
  16. expectedPublic string
  17. }{
  18. {
  19. "I",
  20. "i",
  21. "I",
  22. },
  23. {
  24. "Pod",
  25. "pods",
  26. "Pods",
  27. },
  28. {
  29. "Entry",
  30. "entries",
  31. "Entries",
  32. },
  33. {
  34. "Endpoints",
  35. "endpoints",
  36. "Endpoints",
  37. },
  38. {
  39. "Bus",
  40. "buses",
  41. "Buses",
  42. },
  43. {
  44. "Fizz",
  45. "fizzes",
  46. "Fizzes",
  47. },
  48. {
  49. "Search",
  50. "searches",
  51. "Searches",
  52. },
  53. {
  54. "Autograph",
  55. "autographs",
  56. "Autographs",
  57. },
  58. {
  59. "Dispatch",
  60. "dispatches",
  61. "Dispatches",
  62. },
  63. {
  64. "Earth",
  65. "earths",
  66. "Earths",
  67. },
  68. {
  69. "City",
  70. "cities",
  71. "Cities",
  72. },
  73. {
  74. "Ray",
  75. "rays",
  76. "Rays",
  77. },
  78. {
  79. "Fountain",
  80. "fountains",
  81. "Fountains",
  82. },
  83. {
  84. "Life",
  85. "lives",
  86. "Lives",
  87. },
  88. {
  89. "Leaf",
  90. "leaves",
  91. "Leaves",
  92. },
  93. }
  94. for _, c := range cases {
  95. testType := &types.Type{Name: types.Name{Name: c.typeName}}
  96. if e, a := c.expectedPrivate, private.Name(testType); e != a {
  97. t.Errorf("Unexpected result from private plural namer. Expected: %s, Got: %s", e, a)
  98. }
  99. if e, a := c.expectedPublic, public.Name(testType); e != a {
  100. t.Errorf("Unexpected result from public plural namer. Expected: %s, Got: %s", e, a)
  101. }
  102. }
  103. }