github.com/openconfig/goyang@v1.4.5/pkg/yang/camelcase_test.go (about) 1 // Copyright 2015 Google Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package yang 16 17 import ( 18 "testing" 19 ) 20 21 func TestCamelCase(t *testing.T) { 22 tests := []struct { 23 in, want string 24 }{ 25 {"one", "One"}, 26 {"one_two", "OneTwo"}, 27 {"__one__two__three__four", "XOne_Two_Three_Four"}, 28 {"one.two.three", "OneTwoThree"}, 29 {"one.two.three.", "OneTwoThree_"}, 30 {"_my_field_name_2", "XMyFieldName_2"}, 31 {"Something_Capped", "Something_Capped"}, 32 {"_Foo-bar", "XFooBar"}, 33 {"my_Name", "My_Name"}, 34 {"OneTwo", "OneTwo"}, 35 {"_", "X"}, 36 {"_a_", "XA_"}, 37 {"ietf-interface", "IETFInterface"}, 38 {"ietf-interface-1", "IETFInterface_1"}, 39 {"out-unicast.pkts", "OutUnicastPkts"}, 40 // Invalid input conversion behaviours: 41 {"one/two", "One/two"}, 42 {"/one/two", "/one/two"}, 43 {"one:two", "One:two"}, 44 {"::one::two", "::one::two"}, 45 {"one|two", "One|two"}, 46 {"one||two", "One||two"}, 47 } 48 for _, tc := range tests { 49 if got := CamelCase(tc.in); got != tc.want { 50 t.Errorf("CamelCase(%q) = %q, want %q", tc.in, got, tc.want) 51 } 52 } 53 }