File tree Expand file tree Collapse file tree 2 files changed +92
-0
lines changed
Expand file tree Collapse file tree 2 files changed +92
-0
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,10 @@ func SimpleTypeName(t reflect.Type) string {
4747// This doesn't include "u" as a vowel since words like "user" should be "a user"
4848// and not "an user".
4949func TypeNameStartsWithVowel (t string ) bool {
50+ if t == "" {
51+ return false
52+ }
53+
5054 t = strings .TrimLeft (t , "*" )
5155
5256 switch strings .ToLower (t [:1 ]) {
Original file line number Diff line number Diff line change @@ -96,3 +96,91 @@ func TestSimpleTypeName(t *testing.T) {
9696 require .Equal (t , test .expected , name )
9797 }
9898}
99+
100+ // Tests that TypeNameStartsWithVowel returns the expected result.
101+ func TestTypeNameStartsWithVowel (t * testing.T ) {
102+ tests := []struct {
103+ name string
104+ expected bool
105+ }{
106+ {
107+ name : "" ,
108+ expected : false ,
109+ },
110+ {
111+ name : "a" ,
112+ expected : true ,
113+ },
114+ {
115+ name : "e" ,
116+ expected : true ,
117+ },
118+ {
119+ name : "i" ,
120+ expected : true ,
121+ },
122+ {
123+ name : "o" ,
124+ expected : true ,
125+ },
126+ {
127+ name : "u" ,
128+ expected : false ,
129+ },
130+ {
131+ name : "int" ,
132+ expected : true ,
133+ },
134+ {
135+ name : "*int" ,
136+ expected : true ,
137+ },
138+ {
139+ name : "string" ,
140+ expected : false ,
141+ },
142+ }
143+
144+ for _ , test := range tests {
145+ actual := schema .TypeNameStartsWithVowel (test .name )
146+ require .Equal (t , test .expected , actual )
147+ }
148+ }
149+
150+ // Tests that TypeNameStartsWithVowel returns the expected result.
151+ func TestTypeNameWithArticle (t * testing.T ) {
152+ tests := []struct {
153+ name string
154+ expected string
155+ }{
156+ {
157+ name : "float" ,
158+ expected : "a float" ,
159+ },
160+ {
161+ name : "int" ,
162+ expected : "an int" ,
163+ },
164+ {
165+ name : "*string" ,
166+ expected : "a *string" ,
167+ },
168+ {
169+ name : "*int" ,
170+ expected : "an *int" ,
171+ },
172+ {
173+ name : "null" ,
174+ expected : "null" ,
175+ },
176+ {
177+ name : "User" ,
178+ expected : "a User" ,
179+ },
180+ }
181+
182+ for _ , test := range tests {
183+ actual := schema .TypeNameWithArticle (test .name )
184+ require .Equal (t , test .expected , actual )
185+ }
186+ }
You can’t perform that action at this time.
0 commit comments