...

Source file src/github.com/cli/shurcooL-graphql/ident/ident_test.go

Documentation: github.com/cli/shurcooL-graphql/ident

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

View as plain text