go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/common/testing/assert/should/equal_test.go (about) 1 // Copyright 2024 The LUCI Authors. 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 should 16 17 import ( 18 "testing" 19 20 "go.chromium.org/luci/common/testing/typed" 21 ) 22 23 // TestEqual checks whether two things are equal. 24 func TestEqual(t *testing.T) { 25 t.Parallel() 26 27 cases := []struct { 28 name string 29 lhs interface{} 30 rhs interface{} 31 ok bool 32 }{ 33 { 34 name: "empty", 35 lhs: nil, 36 rhs: nil, 37 ok: true, 38 }, 39 { 40 name: "nil vs non-nil", 41 lhs: nil, 42 rhs: 7, 43 ok: false, 44 }, 45 } 46 47 for _, tt := range cases { 48 tt := tt 49 t.Run(tt.name, func(t *testing.T) { 50 t.Parallel() 51 52 got := Equal(tt.lhs)(tt.rhs) == nil 53 want := tt.ok 54 if diff := typed.Got(got).Want(want).Diff(); diff != "" { 55 t.Errorf("unexpected diff (-want +got): %s", diff) 56 } 57 }) 58 } 59 }