vitess.io/vitess@v0.16.2/go/sqlescape/ids_test.go (about) 1 /* 2 Copyright 2019 The Vitess Authors. 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 http://www.apache.org/licenses/LICENSE-2.0 7 Unless required by applicable law or agreed to in writing, software 8 distributed under the License is distributed on an "AS IS" BASIS, 9 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 See the License for the specific language governing permissions and 11 limitations under the License. 12 */ 13 14 package sqlescape 15 16 import ( 17 "testing" 18 ) 19 20 func TestEscapeID(t *testing.T) { 21 testcases := []struct { 22 in, out string 23 }{{ 24 in: "aa", 25 out: "`aa`", 26 }, { 27 in: "a`a", 28 out: "`a``a`", 29 }} 30 for _, tc := range testcases { 31 out := EscapeID(tc.in) 32 if out != tc.out { 33 t.Errorf("EscapeID(%s): %s, want %s", tc.in, out, tc.out) 34 } 35 } 36 } 37 38 var scratch string 39 40 func BenchmarkEscapeID(b *testing.B) { 41 testcases := []string{ 42 "aa", "a`a", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 43 } 44 for _, tc := range testcases { 45 name := tc 46 if len(name) > 10 { 47 name = "long" 48 } 49 b.Run(name, func(b *testing.B) { 50 for i := 0; i < b.N; i++ { 51 scratch = EscapeID(tc) 52 } 53 }) 54 } 55 }