github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/sem/tree/placeholders_test.go (about) 1 // Copyright 2019 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 package tree 12 13 import ( 14 "fmt" 15 "testing" 16 17 "github.com/cockroachdb/cockroach/pkg/sql/types" 18 "github.com/cockroachdb/cockroach/pkg/util/leaktest" 19 ) 20 21 func TestPlaceholderTypesEquals(t *testing.T) { 22 defer leaktest.AfterTest(t)() 23 testCases := []struct { 24 a, b PlaceholderTypes 25 equal bool 26 }{ 27 { // 0 28 PlaceholderTypes{}, 29 PlaceholderTypes{}, 30 true, 31 }, 32 { // 1 33 PlaceholderTypes{types.Int, types.Int}, 34 PlaceholderTypes{types.Int, types.Int}, 35 true, 36 }, 37 { // 2 38 PlaceholderTypes{types.Int}, 39 PlaceholderTypes{types.Int, types.Int}, 40 false, 41 }, 42 { // 3 43 PlaceholderTypes{types.Int, nil}, 44 PlaceholderTypes{types.Int, types.Int}, 45 false, 46 }, 47 { // 4 48 PlaceholderTypes{types.Int, types.Int}, 49 PlaceholderTypes{types.Int, nil}, 50 false, 51 }, 52 { // 5 53 PlaceholderTypes{types.Int, nil}, 54 PlaceholderTypes{types.Int, nil}, 55 true, 56 }, 57 { // 6 58 PlaceholderTypes{types.Int}, 59 PlaceholderTypes{types.Int, nil}, 60 false, 61 }, 62 } 63 for i, tc := range testCases { 64 t.Run(fmt.Sprintf("%d", i), func(t *testing.T) { 65 res := tc.a.Equals(tc.b) 66 if res != tc.equal { 67 t.Errorf("%v vs %v: expected %t, got %t", tc.a, tc.b, tc.equal, res) 68 } 69 res2 := tc.b.Equals(tc.a) 70 if res != res2 { 71 t.Errorf("%v vs %v: not commutative", tc.a, tc.b) 72 } 73 }) 74 } 75 }