...

Source file src/github.com/GoogleCloudPlatform/k8s-config-connector/pkg/text/text_test.go

Documentation: github.com/GoogleCloudPlatform/k8s-config-connector/pkg/text

     1  // Copyright 2022 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  //      http://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 text
    16  
    17  import "testing"
    18  
    19  func TestAsSnakeCase(t *testing.T) {
    20  	tests := []struct {
    21  		input    string
    22  		expected string
    23  	}{
    24  		{
    25  			input:    "lowerCamelCaseInput",
    26  			expected: "lower_camel_case_input",
    27  		},
    28  		{
    29  			input:    "UpperCamelCaseInput",
    30  			expected: "upper_camel_case_input",
    31  		},
    32  		{
    33  			input:    "snake_case_input",
    34  			expected: "snake_case_input",
    35  		},
    36  	}
    37  	for _, tc := range tests {
    38  		t.Run(tc.input, func(t *testing.T) {
    39  			output := AsSnakeCase(tc.input)
    40  			if tc.expected != output {
    41  				t.Errorf("expected: %v, actual: %v", tc.expected, output)
    42  			}
    43  		})
    44  	}
    45  }
    46  
    47  func TestSnakeCaseToLowerCase(t *testing.T) {
    48  	tests := []struct {
    49  		input    string
    50  		expected string
    51  	}{
    52  		{
    53  			input:    "snake_case_input",
    54  			expected: "snakecaseinput",
    55  		},
    56  		{
    57  			input:    "input",
    58  			expected: "input",
    59  		},
    60  	}
    61  	for _, tc := range tests {
    62  		t.Run(tc.input, func(t *testing.T) {
    63  			output := SnakeCaseToLowerCase(tc.input)
    64  			if tc.expected != output {
    65  				t.Errorf("error parsing snake case to lower case: got %v, want %v", output, tc.expected)
    66  			}
    67  		})
    68  	}
    69  }
    70  
    71  func TestIsPascalCase(t *testing.T) {
    72  	tests := []struct {
    73  		input    string
    74  		expected bool
    75  	}{
    76  		{
    77  			input:    "PrivateCA",
    78  			expected: true,
    79  		},
    80  		{
    81  			input:    "CAPool",
    82  			expected: true,
    83  		},
    84  		{
    85  			input:    "IAM",
    86  			expected: true,
    87  		},
    88  		{
    89  			input:    "Bigtable",
    90  			expected: true,
    91  		},
    92  		{
    93  			input:    "bigquery",
    94  			expected: false,
    95  		},
    96  		{
    97  			input:    "MD5",
    98  			expected: false,
    99  		},
   100  	}
   101  	for _, tc := range tests {
   102  		t.Run(tc.input, func(t *testing.T) {
   103  			output := IsPascalCase(tc.input)
   104  			if tc.expected != output {
   105  				t.Errorf("error checking if the input is pascal case: got %v, want %v", output, tc.expected)
   106  			}
   107  		})
   108  	}
   109  }
   110  
   111  func TestRemoveSpecialCharacters(t *testing.T) {
   112  	tests := []struct {
   113  		input    string
   114  		expected string
   115  	}{
   116  		{
   117  			input:    "Config Connector 123",
   118  			expected: "Config Connector 123",
   119  		},
   120  		{
   121  			input:    "project_id",
   122  			expected: "projectid",
   123  		},
   124  		{
   125  			input:    "${uniqueId}",
   126  			expected: "uniqueId",
   127  		},
   128  	}
   129  	for _, tc := range tests {
   130  		t.Run(tc.input, func(t *testing.T) {
   131  			output := RemoveSpecialCharacters(tc.input)
   132  			if tc.expected != output {
   133  				t.Errorf("error checking if the input is pascal case: got %v, want %v", output, tc.expected)
   134  			}
   135  		})
   136  	}
   137  }
   138  

View as plain text