gitee.com/quant1x/gox@v1.21.2/api/string_kebab_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 TestKebabCase(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 := KebabCase(camel) 31 assert.Equal(t, snake, converted) 32 } 33 } 34 35 func TestUpperKebabCase(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 := UpperKebabCase(camel) 54 assert.Equal(t, snake, converted) 55 } 56 }