gitee.com/quant1x/gox@v1.21.2/api/string_snake_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 TestSnakeCase(t *testing.T) {
    13  	data := map[string]string{
    14  		"":                           "",
    15  		"F":                          "f",
    16  		"Foo":                        "foo",
    17  		"FooB":                       "foo_b",
    18  		"FooID":                      "foo_id",
    19  		" FooBar\t":                  "foo_bar",
    20  		"HTTPStatusCode":             "http_status_code",
    21  		"ParseURL.DoParse":           "parse_url.do_parse",
    22  		"Convert Space":              "convert_space",
    23  		"Convert-dash":               "convert_dash",
    24  		"Skip___MultipleUnderscores": "skip_multiple_underscores",
    25  		"Skip   MultipleSpaces":      "skip_multiple_spaces",
    26  		"Skip---MultipleDashes":      "skip_multiple_dashes",
    27  	}
    28  
    29  	for camel, snake := range data {
    30  		converted := SnakeCase(camel)
    31  		assert.Equal(t, snake, converted)
    32  	}
    33  }
    34  
    35  func TestUpperSnakeCase(t *testing.T) {
    36  	data := map[string]string{
    37  		"":                           "",
    38  		"F":                          "F",
    39  		"Foo":                        "FOO",
    40  		"FooB":                       "FOO_B",
    41  		"FooID":                      "FOO_ID",
    42  		" FooBar\t":                  "FOO_BAR",
    43  		"HTTPStatusCode":             "HTTP_STATUS_CODE",
    44  		"ParseURL.DoParse":           "PARSE_URL.DO_PARSE",
    45  		"Convert Space":              "CONVERT_SPACE",
    46  		"Convert-dash":               "CONVERT_DASH",
    47  		"Skip___MultipleUnderscores": "SKIP_MULTIPLE_UNDERSCORES",
    48  		"Skip   MultipleSpaces":      "SKIP_MULTIPLE_SPACES",
    49  		"Skip---MultipleDashes":      "SKIP_MULTIPLE_DASHES",
    50  	}
    51  
    52  	for camel, snake := range data {
    53  		converted := UpperSnakeCase(camel)
    54  		assert.Equal(t, snake, converted)
    55  	}
    56  }