github.com/richardwilkes/toolbox@v1.121.0/txt/case_test.go (about) 1 // Copyright (c) 2016-2024 by Richard A. Wilkes. All rights reserved. 2 // 3 // This Source Code Form is subject to the terms of the Mozilla Public 4 // License, version 2.0. If a copy of the MPL was not distributed with 5 // this file, You can obtain one at http://mozilla.org/MPL/2.0/. 6 // 7 // This Source Code Form is "Incompatible With Secondary Licenses", as 8 // defined by the Mozilla Public License, version 2.0. 9 10 package txt_test 11 12 import ( 13 "testing" 14 15 "github.com/richardwilkes/toolbox/check" 16 "github.com/richardwilkes/toolbox/txt" 17 ) 18 19 func TestToCamelCase(t *testing.T) { 20 check.Equal(t, "SnakeCase", txt.ToCamelCase("snake_case")) 21 check.Equal(t, "SnakeCase", txt.ToCamelCase("snake__case")) 22 check.Equal(t, "CamelCase", txt.ToCamelCase("CamelCase")) 23 } 24 25 func TestToCamelCaseWithExceptions(t *testing.T) { 26 check.Equal(t, "ID", txt.ToCamelCaseWithExceptions("id", txt.StdAllCaps)) 27 check.Equal(t, "世界ID", txt.ToCamelCaseWithExceptions("世界_id", txt.StdAllCaps)) 28 check.Equal(t, "OneID", txt.ToCamelCaseWithExceptions("one_id", txt.StdAllCaps)) 29 check.Equal(t, "IDOne", txt.ToCamelCaseWithExceptions("id_one", txt.StdAllCaps)) 30 check.Equal(t, "OneIDTwo", txt.ToCamelCaseWithExceptions("one_id_two", txt.StdAllCaps)) 31 check.Equal(t, "OneIDTwoID", txt.ToCamelCaseWithExceptions("one_id_two_id", txt.StdAllCaps)) 32 check.Equal(t, "OneIDID", txt.ToCamelCaseWithExceptions("one_id_id", txt.StdAllCaps)) 33 check.Equal(t, "Orchid", txt.ToCamelCaseWithExceptions("orchid", txt.StdAllCaps)) 34 check.Equal(t, "OneURLTwo", txt.ToCamelCaseWithExceptions("one_url_two", txt.StdAllCaps)) 35 check.Equal(t, "URLID", txt.ToCamelCaseWithExceptions("url_id", txt.StdAllCaps)) 36 } 37 38 func TestToSnakeCase(t *testing.T) { 39 check.Equal(t, "snake_case", txt.ToSnakeCase("snake_case")) 40 check.Equal(t, "camel_case", txt.ToSnakeCase("CamelCase")) 41 }