github.com/jxskiss/gopkg@v0.17.3/strutil/strcase_test.go (about)

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