Skip to content

Commit

Permalink
Add some lang tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kangaroux committed May 21, 2021
1 parent 06b7712 commit 900e8ca
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lang.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ func SimpleTypeName(t reflect.Type) string {
// This doesn't include "u" as a vowel since words like "user" should be "a user"
// and not "an user".
func TypeNameStartsWithVowel(t string) bool {
if t == "" {
return false
}

t = strings.TrimLeft(t, "*")

switch strings.ToLower(t[:1]) {
Expand Down
88 changes: 88 additions & 0 deletions lang_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,91 @@ func TestSimpleTypeName(t *testing.T) {
require.Equal(t, test.expected, name)
}
}

// Tests that TypeNameStartsWithVowel returns the expected result.
func TestTypeNameStartsWithVowel(t *testing.T) {
tests := []struct {
name string
expected bool
}{
{
name: "",
expected: false,
},
{
name: "a",
expected: true,
},
{
name: "e",
expected: true,
},
{
name: "i",
expected: true,
},
{
name: "o",
expected: true,
},
{
name: "u",
expected: false,
},
{
name: "int",
expected: true,
},
{
name: "*int",
expected: true,
},
{
name: "string",
expected: false,
},
}

for _, test := range tests {
actual := schema.TypeNameStartsWithVowel(test.name)
require.Equal(t, test.expected, actual)
}
}

// Tests that TypeNameStartsWithVowel returns the expected result.
func TestTypeNameWithArticle(t *testing.T) {
tests := []struct {
name string
expected string
}{
{
name: "float",
expected: "a float",
},
{
name: "int",
expected: "an int",
},
{
name: "*string",
expected: "a *string",
},
{
name: "*int",
expected: "an *int",
},
{
name: "null",
expected: "null",
},
{
name: "User",
expected: "a User",
},
}

for _, test := range tests {
actual := schema.TypeNameWithArticle(test.name)
require.Equal(t, test.expected, actual)
}
}

0 comments on commit 900e8ca

Please sign in to comment.