github.com/XiaoMi/Gaea@v1.2.5/stats/kebab_case_converter_test.go (about) 1 /* 2 Copyright 2018 The Vitess Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package stats 18 19 import "testing" 20 21 func TestToKebabCase(t *testing.T) { 22 var kebabCaseTest = []struct{ input, output string }{ 23 {"Camel", "camel"}, 24 {"Camel", "camel"}, 25 {"CamelCase", "camel-case"}, 26 {"CamelCaseAgain", "camel-case-again"}, 27 {"CCamel", "c-camel"}, 28 {"CCCamel", "cc-camel"}, 29 {"CAMEL_CASE", "camel-case"}, 30 {"camel-case", "camel-case"}, 31 {"0", "0"}, 32 {"0.0", "0_0"}, 33 {"JSON", "json"}, 34 } 35 36 for _, tt := range kebabCaseTest { 37 if got, want := toKebabCase(tt.input), tt.output; got != want { 38 t.Errorf("want '%s', got '%s'", want, got) 39 } 40 } 41 } 42 43 func TestMemoize(t *testing.T) { 44 key := "Test" 45 if memoizer.memo[key] != "" { 46 t.Errorf("want '', got '%s'", memoizer.memo[key]) 47 } 48 toKebabCase(key) 49 if memoizer.memo[key] != "test" { 50 t.Errorf("want 'test', got '%s'", memoizer.memo[key]) 51 } 52 }