1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
|
package ident_test
import (
"fmt"
"reflect"
"testing"
"github.com/cli/shurcooL-graphql/ident"
)
func Example_lowerCamelCaseToMixedCaps() {
fmt.Println(ident.ParseLowerCamelCase("clientMutationId").ToMixedCaps())
// Output: ClientMutationID
}
func Example_screamingSnakeCaseToMixedCaps() {
fmt.Println(ident.ParseScreamingSnakeCase("CLIENT_MUTATION_ID").ToMixedCaps())
// Output: ClientMutationID
}
func Example_mixedCapsToLowerCamelCase() {
fmt.Println(ident.ParseMixedCaps("ClientMutationID").ToLowerCamelCase())
// Output: clientMutationId
}
func TestParseMixedCaps(t *testing.T) {
tests := []struct {
in string
want ident.Name
}{
{in: "ClientMutationID", want: ident.Name{"Client", "Mutation", "ID"}},
{in: "StringURLAppend", want: ident.Name{"String", "URL", "Append"}},
{in: "URLFrom", want: ident.Name{"URL", "From"}},
{in: "SetURL", want: ident.Name{"Set", "URL"}},
{in: "UIIP", want: ident.Name{"UI", "IP"}},
{in: "URLHTMLFrom", want: ident.Name{"URL", "HTML", "From"}},
{in: "SetURLHTML", want: ident.Name{"Set", "URL", "HTML"}},
{in: "HTTPSQL", want: ident.Name{"HTTP", "SQL"}},
{in: "HTTPSSQL", want: ident.Name{"HTTPS", "SQL"}},
{in: "UserIDs", want: ident.Name{"User", "IDs"}},
{in: "TeamIDsSorted", want: ident.Name{"Team", "IDs", "Sorted"}},
}
for _, tc := range tests {
got := ident.ParseMixedCaps(tc.in)
if !reflect.DeepEqual(got, tc.want) {
t.Errorf("got: %q, want: %q", got, tc.want)
}
}
}
func TestParseLowerCamelCase(t *testing.T) {
tests := []struct {
in string
want ident.Name
}{
{in: "clientMutationId", want: ident.Name{"client", "Mutation", "Id"}},
}
for _, tc := range tests {
got := ident.ParseLowerCamelCase(tc.in)
if !reflect.DeepEqual(got, tc.want) {
t.Errorf("got: %q, want: %q", got, tc.want)
}
}
}
func TestParseScreamingSnakeCase(t *testing.T) {
tests := []struct {
in string
want ident.Name
}{
{in: "CLIENT_MUTATION_ID", want: ident.Name{"CLIENT", "MUTATION", "ID"}},
}
for _, tc := range tests {
got := ident.ParseScreamingSnakeCase(tc.in)
if !reflect.DeepEqual(got, tc.want) {
t.Errorf("got: %q, want: %q", got, tc.want)
}
}
}
func TestName_ToMixedCaps(t *testing.T) {
tests := []struct {
in ident.Name
want string
}{
{in: ident.Name{"client", "Mutation", "Id"}, want: "ClientMutationID"},
{in: ident.Name{"CLIENT", "MUTATION", "ID"}, want: "ClientMutationID"},
{in: ident.Name{"github", "logo"}, want: "GitHubLogo"},
{in: ident.Name{"AZURE", "DEVOPS"}, want: "AzureDevOps"},
}
for _, tc := range tests {
got := tc.in.ToMixedCaps()
if got != tc.want {
t.Errorf("got: %q, want: %q", got, tc.want)
}
}
}
func TestName_ToLowerCamelCase(t *testing.T) {
tests := []struct {
in ident.Name
want string
}{
{in: ident.Name{"client", "Mutation", "Id"}, want: "clientMutationId"},
{in: ident.Name{"CLIENT", "MUTATION", "ID"}, want: "clientMutationId"},
}
for _, tc := range tests {
got := tc.in.ToLowerCamelCase()
if got != tc.want {
t.Errorf("got: %q, want: %q", got, tc.want)
}
}
}
func TestMixedCapsToLowerCamelCase(t *testing.T) {
tests := []struct {
in string
want string
}{
{in: "DatabaseID", want: "databaseId"},
{in: "URL", want: "url"},
{in: "ID", want: "id"},
{in: "CreatedAt", want: "createdAt"},
{in: "Login", want: "login"},
{in: "ResetAt", want: "resetAt"},
{in: "ID", want: "id"},
{in: "IDs", want: "ids"},
{in: "IDsAndNames", want: "idsAndNames"},
{in: "UserIDs", want: "userIds"},
{in: "TeamIDsSorted", want: "teamIdsSorted"},
}
for _, tc := range tests {
got := ident.ParseMixedCaps(tc.in).ToLowerCamelCase()
if got != tc.want {
t.Errorf("got: %q, want: %q", got, tc.want)
}
}
}
func TestLowerCamelCaseToMixedCaps(t *testing.T) {
tests := []struct {
in string
want string
}{
{in: "databaseId", want: "DatabaseID"},
{in: "url", want: "URL"},
{in: "id", want: "ID"},
{in: "createdAt", want: "CreatedAt"},
{in: "login", want: "Login"},
{in: "resetAt", want: "ResetAt"},
{in: "id", want: "ID"},
{in: "ids", want: "IDs"},
{in: "idsAndNames", want: "IDsAndNames"},
{in: "userIds", want: "UserIDs"},
{in: "teamIdsSorted", want: "TeamIDsSorted"},
}
for _, tc := range tests {
got := ident.ParseLowerCamelCase(tc.in).ToMixedCaps()
if got != tc.want {
t.Errorf("got: %q, want: %q", got, tc.want)
}
}
}
|