7 . "github.com/onsi/ginkgo"
8 . "github.com/onsi/gomega"
9 . "github.com/onsi/gomega/matchers"
12 var _ = Describe("Equal", func() {
13 Context("when asserting that nil equals nil", func() {
14 It("should error", func() {
15 success, err := (&EqualMatcher{Expected: nil}).Match(nil)
17 Ω(success).Should(BeFalse())
18 Ω(err).Should(HaveOccurred())
22 Context("When asserting equality between objects", func() {
23 It("should do the right thing", func() {
25 Ω(5.0).Should(Equal(5.0))
27 Ω(5).ShouldNot(Equal("5"))
28 Ω(5).ShouldNot(Equal(5.0))
29 Ω(5).ShouldNot(Equal(3))
31 Ω("5").Should(Equal("5"))
32 Ω([]int{1, 2}).Should(Equal([]int{1, 2}))
33 Ω([]int{1, 2}).ShouldNot(Equal([]int{2, 1}))
34 Ω(map[string]string{"a": "b", "c": "d"}).Should(Equal(map[string]string{"a": "b", "c": "d"}))
35 Ω(map[string]string{"a": "b", "c": "d"}).ShouldNot(Equal(map[string]string{"a": "b", "c": "e"}))
36 Ω(errors.New("foo")).Should(Equal(errors.New("foo")))
37 Ω(errors.New("foo")).ShouldNot(Equal(errors.New("bar")))
39 Ω(myCustomType{s: "foo", n: 3, f: 2.0, arr: []string{"a", "b"}}).Should(Equal(myCustomType{s: "foo", n: 3, f: 2.0, arr: []string{"a", "b"}}))
40 Ω(myCustomType{s: "foo", n: 3, f: 2.0, arr: []string{"a", "b"}}).ShouldNot(Equal(myCustomType{s: "bar", n: 3, f: 2.0, arr: []string{"a", "b"}}))
41 Ω(myCustomType{s: "foo", n: 3, f: 2.0, arr: []string{"a", "b"}}).ShouldNot(Equal(myCustomType{s: "foo", n: 2, f: 2.0, arr: []string{"a", "b"}}))
42 Ω(myCustomType{s: "foo", n: 3, f: 2.0, arr: []string{"a", "b"}}).ShouldNot(Equal(myCustomType{s: "foo", n: 3, f: 3.0, arr: []string{"a", "b"}}))
43 Ω(myCustomType{s: "foo", n: 3, f: 2.0, arr: []string{"a", "b"}}).ShouldNot(Equal(myCustomType{s: "foo", n: 3, f: 2.0, arr: []string{"a", "b", "c"}}))
47 Describe("failure messages", func() {
48 It("shows the two strings simply when they are short", func() {
49 subject := EqualMatcher{Expected: "eric"}
51 failureMessage := subject.FailureMessage("tim")
52 Ω(failureMessage).To(BeEquivalentTo(expectedShortStringFailureMessage))
55 It("shows the exact point where two long strings differ", func() {
56 stringWithB := "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
57 stringWithZ := "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaazaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
59 subject := EqualMatcher{Expected: stringWithZ}
61 failureMessage := subject.FailureMessage(stringWithB)
62 Ω(failureMessage).To(BeEquivalentTo(expectedLongStringFailureMessage))
67 var expectedShortStringFailureMessage = strings.TrimSpace(`
73 var expectedLongStringFailureMessage = strings.TrimSpace(`
75 <string>: "...aaaaabaaaaa..."
77 <string>: "...aaaaazaaaaa..."