github.com/googleapis/api-linter@v1.65.2/rules/internal/utils/casing_test.go (about)

     1  // Copyright 2023 Google LLC
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     https://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package utils
    16  
    17  import "testing"
    18  
    19  func TestToLowerCamelCase(t *testing.T) {
    20  	for _, test := range []struct {
    21  		name  string
    22  		input string
    23  		want  string
    24  	}{
    25  		{
    26  			name:  "OneWord",
    27  			input: "Foo",
    28  			want:  "foo",
    29  		},
    30  		{
    31  			name:  "OneWordNoop",
    32  			input: "foo",
    33  			want:  "foo",
    34  		},
    35  		{
    36  			name:  "TwoWords",
    37  			input: "bookShelf",
    38  			want:  "bookShelf",
    39  		},
    40  		{
    41  			name:  "WithDash",
    42  			input: "book-shelf",
    43  			want:  "bookShelf",
    44  		},
    45  		{
    46  			name:  "WithNumbers",
    47  			input: "universe42love",
    48  			want:  "universe42love",
    49  		},
    50  		{
    51  			name:  "WithUnderscore",
    52  			input: "book_shelf",
    53  			want:  "bookShelf",
    54  		},
    55  		{
    56  			name:  "WithUnderscore",
    57  			input: "book_shelf",
    58  			want:  "bookShelf",
    59  		},
    60  		{
    61  			name:  "WithSpaces",
    62  			input: "book shelf",
    63  			want:  "bookShelf",
    64  		},
    65  		{
    66  			name:  "WithPeriods",
    67  			input: "book.shelf",
    68  			want:  "bookShelf",
    69  		},
    70  	} {
    71  		t.Run(test.name, func(t *testing.T) {
    72  			got := ToLowerCamelCase(test.input)
    73  			if got != test.want {
    74  				t.Errorf("ToLowerCamelCase(%q) = %q, got %q", test.input, test.want, got)
    75  			}
    76  		})
    77  	}
    78  }
    79  
    80  func TestToUpperCamelCase(t *testing.T) {
    81  	for _, test := range []struct {
    82  		name  string
    83  		input string
    84  		want  string
    85  	}{
    86  		{
    87  			name:  "OneWord",
    88  			input: "foo",
    89  			want:  "Foo",
    90  		},
    91  		{
    92  			name:  "OneWordNoop",
    93  			input: "Foo",
    94  			want:  "Foo",
    95  		},
    96  		{
    97  			name:  "TwoWords",
    98  			input: "bookShelf",
    99  			want:  "BookShelf",
   100  		},
   101  		{
   102  			name:  "WithDash",
   103  			input: "book-shelf",
   104  			want:  "BookShelf",
   105  		},
   106  		{
   107  			name:  "WithNumbers",
   108  			input: "universe42love",
   109  			want:  "Universe42love",
   110  		},
   111  		{
   112  			name:  "WithUnderscore",
   113  			input: "Book_shelf",
   114  			want:  "BookShelf",
   115  		},
   116  		{
   117  			name:  "WithUnderscore",
   118  			input: "Book_shelf",
   119  			want:  "BookShelf",
   120  		},
   121  		{
   122  			name:  "WithSpaces",
   123  			input: "Book shelf",
   124  			want:  "BookShelf",
   125  		},
   126  		{
   127  			name:  "WithPeriods",
   128  			input: "book.shelf",
   129  			want:  "BookShelf",
   130  		},
   131  	} {
   132  		t.Run(test.name, func(t *testing.T) {
   133  			got := ToUpperCamelCase(test.input)
   134  			if got != test.want {
   135  				t.Errorf("ToLowerCamelCase(%q) = %q, got %q", test.input, test.want, got)
   136  			}
   137  		})
   138  	}
   139  }