github.com/bingoohuang/gg@v0.0.0-20240325092523-45da7dee9335/pkg/strcase/camel_test.go (about)

     1  package strcase
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  func TestToCamel(t *testing.T) {
     8  	cases := [][]string{
     9  		{"v1", "V1"},
    10  		{"test_case", "TestCase"},
    11  		{"test_CASE", "TestCase"},
    12  		{"test", "Test"},
    13  		{"TestCase", "TestCase"},
    14  		{"mySQL", "MySql"},
    15  		{" test  case ", "TestCase"},
    16  		{"", ""},
    17  		{"many_many_words", "ManyManyWords"},
    18  		{"AnyKind of_string", "AnyKindOfString"},
    19  		{"odd-fix", "OddFix"},
    20  		{"numbers2And55with000", "Numbers2And55With000"},
    21  	}
    22  	for _, i := range cases {
    23  		in := i[0]
    24  		out := i[1]
    25  		result := ToCamel(in)
    26  
    27  		if result != out {
    28  			t.Error("'" + result + "' != '" + out + "'")
    29  		}
    30  	}
    31  }
    32  
    33  func TestToCamelLower(t *testing.T) {
    34  	cases := [][]string{
    35  		{"ID", "id"},
    36  		{"SQL", "sql"},
    37  		{"MySQL", "mySql"},
    38  		{"SQLMap", "sqlMap"},
    39  		{"foo-bar", "fooBar"},
    40  		{"foo_bar", "fooBar"},
    41  		{"TestCase", "testCase"},
    42  		{"", ""},
    43  		{"AnyKind of_string", "anyKindOfString"},
    44  	}
    45  
    46  	for _, i := range cases {
    47  		in := i[0]
    48  		out := i[1]
    49  		result := ToCamelLower(in)
    50  
    51  		if result != out {
    52  			t.Error("'" + result + "' != '" + out + "'")
    53  		}
    54  	}
    55  }