gitee.com/quant1x/gox@v1.21.2/api/string_camel_test.go (about)

     1  // Copyright (c) 2017, A. Stoewer <adrian.stoewer@rz.ifi.lmu.de>
     2  // All rights reserved.
     3  
     4  package api
     5  
     6  import (
     7  	"testing"
     8  
     9  	"gitee.com/quant1x/pkg/testify/assert"
    10  )
    11  
    12  func TestUpperCamelCase(t *testing.T) {
    13  	data := map[string]string{
    14  		"":                      "",
    15  		"f":                     "F",
    16  		"foo":                   "Foo",
    17  		"fooBar":                "FooBar",
    18  		"FooBarBla":             "FooBarBla",
    19  		"foo_barBla":            "FooBarBla",
    20  		" foo_bar\n":            "FooBar",
    21  		" foo-bar\t":            "FooBar",
    22  		" foo bar\r":            "FooBar",
    23  		"HTTP_status_code":      "HttpStatusCode",
    24  		"skip   many spaces":    "SkipManySpaces",
    25  		"skip---many-dashes":    "SkipManyDashes",
    26  		"skip___many_underline": "SkipManyUnderline",
    27  	}
    28  
    29  	for in, out := range data {
    30  		converted := UpperCamelCase(in)
    31  		assert.Equal(t, out, converted)
    32  	}
    33  }
    34  
    35  func TestLowerCamelCase(t *testing.T) {
    36  	data := map[string]string{
    37  		"":                      "",
    38  		"F":                     "f",
    39  		"foo":                   "foo",
    40  		"FooBar":                "fooBar",
    41  		"fooBarBla":             "fooBarBla",
    42  		"foo_barBla":            "fooBarBla",
    43  		" foo_bar\n":            "fooBar",
    44  		" foo-bar\t":            "fooBar",
    45  		" foo bar\r":            "fooBar",
    46  		"HTTP_status_code":      "httpStatusCode",
    47  		"skip   many spaces":    "skipManySpaces",
    48  		"skip---many-dashes":    "skipManyDashes",
    49  		"skip___many_underline": "skipManyUnderline",
    50  	}
    51  
    52  	for in, out := range data {
    53  		converted := LowerCamelCase(in)
    54  		assert.Equal(t, out, converted)
    55  	}
    56  }