6 . "github.com/onsi/ginkgo"
7 . "github.com/onsi/gomega"
8 . "github.com/onsi/gomega/matchers"
11 var _ = Describe("BeIdenticalTo", func() {
12 Context("when asserting that nil equals nil", func() {
13 It("should error", func() {
14 success, err := (&BeIdenticalToMatcher{Expected: nil}).Match(nil)
16 Ω(success).Should(BeFalse())
17 Ω(err).Should(HaveOccurred())
21 It("should treat the same pointer to a struct as identical", func() {
22 mySpecialStruct := myCustomType{}
23 Ω(&mySpecialStruct).Should(BeIdenticalTo(&mySpecialStruct))
24 Ω(&myCustomType{}).ShouldNot(BeIdenticalTo(&mySpecialStruct))
27 It("should be strict about types", func() {
28 Ω(5).ShouldNot(BeIdenticalTo("5"))
29 Ω(5).ShouldNot(BeIdenticalTo(5.0))
30 Ω(5).ShouldNot(BeIdenticalTo(3))
33 It("should treat primtives as identical", func() {
34 Ω("5").Should(BeIdenticalTo("5"))
35 Ω("5").ShouldNot(BeIdenticalTo("55"))
37 Ω(5.55).Should(BeIdenticalTo(5.55))
38 Ω(5.55).ShouldNot(BeIdenticalTo(6.66))
40 Ω(5).Should(BeIdenticalTo(5))
41 Ω(5).ShouldNot(BeIdenticalTo(55))
44 It("should treat the same pointers to a slice as identical", func() {
45 mySlice := []int{1, 2}
46 Ω(&mySlice).Should(BeIdenticalTo(&mySlice))
47 Ω(&mySlice).ShouldNot(BeIdenticalTo(&[]int{1, 2}))
50 It("should treat the same pointers to a map as identical", func() {
51 myMap := map[string]string{"a": "b", "c": "d"}
52 Ω(&myMap).Should(BeIdenticalTo(&myMap))
53 Ω(myMap).ShouldNot(BeIdenticalTo(map[string]string{"a": "b", "c": "d"}))
56 It("should treat the same pointers to an error as identical", func() {
57 myError := errors.New("foo")
58 Ω(&myError).Should(BeIdenticalTo(&myError))
59 Ω(errors.New("foo")).ShouldNot(BeIdenticalTo(errors.New("bar")))