vitess.io/vitess@v0.16.2/go/vt/vtgate/planbuilder/expr_test.go (about) 1 /* 2 Copyright 2019 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 planbuilder 18 19 import ( 20 "testing" 21 22 "vitess.io/vitess/go/vt/sqlparser" 23 ) 24 25 func TestValEqual(t *testing.T) { 26 c1 := &column{} 27 c2 := &column{} 28 testcases := []struct { 29 in1, in2 sqlparser.Expr 30 out bool 31 }{{ 32 in1: &sqlparser.ColName{Metadata: c1, Name: sqlparser.NewIdentifierCI("c1")}, 33 in2: &sqlparser.ColName{Metadata: c1, Name: sqlparser.NewIdentifierCI("c1")}, 34 out: true, 35 }, { 36 // Objects that have the same name need not be the same because 37 // they might have appeared in different scopes and could have 38 // resolved to different columns. 39 in1: &sqlparser.ColName{Metadata: c1, Name: sqlparser.NewIdentifierCI("c1")}, 40 in2: &sqlparser.ColName{Metadata: c2, Name: sqlparser.NewIdentifierCI("c1")}, 41 out: false, 42 }, { 43 in1: sqlparser.NewArgument("aa"), 44 in2: &sqlparser.ColName{Metadata: c1, Name: sqlparser.NewIdentifierCI("c1")}, 45 out: false, 46 }, { 47 in1: sqlparser.NewArgument("aa"), 48 in2: sqlparser.NewArgument("aa"), 49 out: true, 50 }, { 51 in1: sqlparser.NewArgument("aa"), 52 in2: sqlparser.NewArgument("bb"), 53 }, { 54 in1: sqlparser.NewStrLiteral("aa"), 55 in2: sqlparser.NewStrLiteral("aa"), 56 out: true, 57 }, { 58 in1: sqlparser.NewStrLiteral("11"), 59 in2: sqlparser.NewHexLiteral("3131"), 60 out: true, 61 }, { 62 in1: sqlparser.NewHexLiteral("3131"), 63 in2: sqlparser.NewStrLiteral("11"), 64 out: true, 65 }, { 66 in1: sqlparser.NewHexLiteral("3131"), 67 in2: sqlparser.NewHexLiteral("3131"), 68 out: true, 69 }, { 70 in1: sqlparser.NewHexLiteral("3131"), 71 in2: sqlparser.NewHexLiteral("3132"), 72 out: false, 73 }, { 74 in1: sqlparser.NewHexLiteral("313"), 75 in2: sqlparser.NewHexLiteral("3132"), 76 out: false, 77 }, { 78 in1: sqlparser.NewHexLiteral("3132"), 79 in2: sqlparser.NewHexLiteral("313"), 80 out: false, 81 }, { 82 in1: sqlparser.NewIntLiteral("313"), 83 in2: sqlparser.NewHexLiteral("3132"), 84 out: false, 85 }, { 86 in1: sqlparser.NewHexLiteral("3132"), 87 in2: sqlparser.NewIntLiteral("313"), 88 out: false, 89 }, { 90 in1: sqlparser.NewIntLiteral("313"), 91 in2: sqlparser.NewIntLiteral("313"), 92 out: true, 93 }, { 94 in1: sqlparser.NewIntLiteral("313"), 95 in2: sqlparser.NewIntLiteral("314"), 96 out: false, 97 }} 98 for _, tc := range testcases { 99 out := valEqual(tc.in1, tc.in2) 100 if out != tc.out { 101 t.Errorf("valEqual(%#v, %#v): %v, want %v", tc.in1, tc.in2, out, tc.out) 102 } 103 } 104 }