2add0b7499ee27c0ca55aced06ba03ce7f71a844
[govpp.git] / vendor / github.com / onsi / gomega / matchers / equal_matcher_test.go
1 package matchers_test
2
3 import (
4         "errors"
5         "strings"
6
7         . "github.com/onsi/ginkgo"
8         . "github.com/onsi/gomega"
9         . "github.com/onsi/gomega/matchers"
10 )
11
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)
16
17                         Ω(success).Should(BeFalse())
18                         Ω(err).Should(HaveOccurred())
19                 })
20         })
21
22         Context("When asserting equality between objects", func() {
23                 It("should do the right thing", func() {
24                         Ω(5).Should(Equal(5))
25                         Ω(5.0).Should(Equal(5.0))
26
27                         Ω(5).ShouldNot(Equal("5"))
28                         Ω(5).ShouldNot(Equal(5.0))
29                         Ω(5).ShouldNot(Equal(3))
30
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")))
38
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"}}))
44                 })
45         })
46
47         Describe("failure messages", func() {
48                 It("shows the two strings simply when they are short", func() {
49                         subject := EqualMatcher{Expected: "eric"}
50
51                         failureMessage := subject.FailureMessage("tim")
52                         Ω(failureMessage).To(BeEquivalentTo(expectedShortStringFailureMessage))
53                 })
54
55                 It("shows the exact point where two long strings differ", func() {
56                         stringWithB := "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
57                         stringWithZ := "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaazaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
58
59                         subject := EqualMatcher{Expected: stringWithZ}
60
61                         failureMessage := subject.FailureMessage(stringWithB)
62                         Ω(failureMessage).To(BeEquivalentTo(expectedLongStringFailureMessage))
63                 })
64         })
65 })
66
67 var expectedShortStringFailureMessage = strings.TrimSpace(`
68 Expected
69     <string>: tim
70 to equal
71     <string>: eric
72 `)
73 var expectedLongStringFailureMessage = strings.TrimSpace(`
74 Expected
75     <string>: "...aaaaabaaaaa..."
76 to equal               |
77     <string>: "...aaaaazaaaaa..."
78 `)