github.com/jxskiss/gopkg/v2@v2.14.9-0.20240514120614-899f3e7952b4/utils/strutil/strcase_test.go (about)

     1  package strutil
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func TestToCamelCase(t *testing.T) {
    10  	cases := [][]string{
    11  		{"test_case", "TestCase"},
    12  		{"test.case", "TestCase"},
    13  		{"test", "Test"},
    14  		{"TestCase", "TestCase"},
    15  		{" test  case ", "TestCase"},
    16  		{"", ""},
    17  		{"many_many_words", "ManyManyWords"},
    18  		{"AnyKind of_string", "AnyKindOfString"},
    19  		{"odd-fix", "OddFix"},
    20  		{"numbers2And55with000", "Numbers2And55With000"},
    21  		{"id", "Id"},
    22  		{"ID", "ID"},
    23  		{"someID", "SomeID"},
    24  		{"someHTMLWord", "SomeHTMLWord"},
    25  	}
    26  	for _, tc := range cases {
    27  		want := tc[1]
    28  		got := ToCamelCase(tc[0])
    29  		assert.Equal(t, want, got)
    30  	}
    31  }
    32  
    33  func TestToLowerCamelCase(t *testing.T) {
    34  	cases := [][]string{
    35  		{"test_case", "testCase"},
    36  		{"ID", "id"},
    37  		{"api-example", "apiExample"},
    38  		{"APIExample", "apiExample"},
    39  		{"ILoveYou", "iLoveYou"},
    40  	}
    41  	for _, tc := range cases {
    42  		want := tc[1]
    43  		got := ToLowerCamelCase(tc[0])
    44  		assert.Equal(t, want, got)
    45  	}
    46  }