github.com/onsi/gomega@v1.32.0/matchers/be_identical_to_test.go (about) 1 package matchers_test 2 3 import ( 4 "errors" 5 6 . "github.com/onsi/ginkgo/v2" 7 . "github.com/onsi/gomega" 8 . "github.com/onsi/gomega/matchers" 9 ) 10 11 var _ = Describe("BeIdenticalTo", func() { 12 When("asserting that nil equals nil", func() { 13 It("should error", func() { 14 success, err := (&BeIdenticalToMatcher{Expected: nil}).Match(nil) 15 16 Expect(success).Should(BeFalse()) 17 Expect(err).Should(HaveOccurred()) 18 }) 19 }) 20 21 It("should treat the same pointer to a struct as identical", func() { 22 mySpecialStruct := myCustomType{} 23 Expect(&mySpecialStruct).Should(BeIdenticalTo(&mySpecialStruct)) 24 Expect(&myCustomType{}).ShouldNot(BeIdenticalTo(&mySpecialStruct)) 25 }) 26 27 It("should be strict about types", func() { 28 Expect(5).ShouldNot(BeIdenticalTo("5")) 29 Expect(5).ShouldNot(BeIdenticalTo(5.0)) 30 Expect(5).ShouldNot(BeIdenticalTo(3)) 31 }) 32 33 It("should treat primtives as identical", func() { 34 Expect("5").Should(BeIdenticalTo("5")) 35 Expect("5").ShouldNot(BeIdenticalTo("55")) 36 37 Expect(5.55).Should(BeIdenticalTo(5.55)) 38 Expect(5.55).ShouldNot(BeIdenticalTo(6.66)) 39 40 Expect(5).Should(BeIdenticalTo(5)) 41 Expect(5).ShouldNot(BeIdenticalTo(55)) 42 }) 43 44 It("should treat the same pointers to a slice as identical", func() { 45 mySlice := []int{1, 2} 46 Expect(&mySlice).Should(BeIdenticalTo(&mySlice)) 47 Expect(&mySlice).ShouldNot(BeIdenticalTo(&[]int{1, 2})) 48 }) 49 50 It("should treat the same pointers to a map as identical", func() { 51 myMap := map[string]string{"a": "b", "c": "d"} 52 Expect(&myMap).Should(BeIdenticalTo(&myMap)) 53 Expect(myMap).ShouldNot(BeIdenticalTo(map[string]string{"a": "b", "c": "d"})) 54 }) 55 56 It("should treat the same pointers to an error as identical", func() { 57 myError := errors.New("foo") 58 Expect(&myError).Should(BeIdenticalTo(&myError)) 59 Expect(errors.New("foo")).ShouldNot(BeIdenticalTo(errors.New("bar"))) 60 }) 61 })