Skip to content

Commit 900e8ca

Browse files
committed
Add some lang tests
1 parent 06b7712 commit 900e8ca

File tree

2 files changed

+92
-0
lines changed

2 files changed

+92
-0
lines changed

lang.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff 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".
4949
func TypeNameStartsWithVowel(t string) bool {
50+
if t == "" {
51+
return false
52+
}
53+
5054
t = strings.TrimLeft(t, "*")
5155

5256
switch strings.ToLower(t[:1]) {

lang_test.go

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
}

0 commit comments

Comments
 (0)