Debian Codegraph @

v2/namer/plural_namer_test.go

raw
1 /*
2 Copyright 2015 The Kubernetes Authors.
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 */
16
17 package namer
18
19 import (
20 "testing"
21
22 "k8s.io/gengo/v2/types"
23 )
24
25 func TestPluralNamer(t *testing.T) {
26 exceptions := map[string]string{
27 // The type name is already in the plural form
28 "Endpoints": "endpoints",
29 }
30 public := NewPublicPluralNamer(exceptions)
31 private := NewPrivatePluralNamer(exceptions)
32
33 cases := []struct {
34 typeName string
35 expectedPrivate string
36 expectedPublic string
37 }{
38 {
39 "I",
40 "i",
41 "I",
42 },
43 {
44 "Pod",
45 "pods",
46 "Pods",
47 },
48 {
49 "Entry",
50 "entries",
51 "Entries",
52 },
53 {
54 "Endpoints",
55 "endpoints",
56 "Endpoints",
57 },
58 {
59 "Bus",
60 "buses",
61 "Buses",
62 },
63 {
64 "Fizz",
65 "fizzes",
66 "Fizzes",
67 },
68 {
69 "Search",
70 "searches",
71 "Searches",
72 },
73 {
74 "Autograph",
75 "autographs",
76 "Autographs",
77 },
78 {
79 "Dispatch",
80 "dispatches",
81 "Dispatches",
82 },
83 {
84 "Earth",
85 "earths",
86 "Earths",
87 },
88 {
89 "City",
90 "cities",
91 "Cities",
92 },
93 {
94 "Ray",
95 "rays",
96 "Rays",
97 },
98 {
99 "Fountain",
100 "fountains",
101 "Fountains",
102 },
103 {
104 "Life",
105 "lives",
106 "Lives",
107 },
108 {
109 "Leaf",
110 "leaves",
111 "Leaves",
112 },
113 }
114 for _, c := range cases {
115 testType := &types.Type{Name: types.Name{Name: c.typeName}}
116 if e, a := c.expectedPrivate, private.Name(testType); e != a {
117 t.Errorf("Unexpected result from private plural namer. Expected: %s, Got: %s", e, a)
118 }
119 if e, a := c.expectedPublic, public.Name(testType); e != a {
120 t.Errorf("Unexpected result from public plural namer. Expected: %s, Got: %s", e, a)
121 }
122 }
123 }