...
1 package matchers_test
2
3 import (
4 . "github.com/onsi/ginkgo/v2"
5 . "github.com/onsi/gomega"
6 . "github.com/onsi/gomega/matchers"
7 )
8
9 var _ = Describe("BeEquivalentTo", func() {
10 When("asserting that nil is equivalent to nil", func() {
11 It("should error", func() {
12 success, err := (&BeEquivalentToMatcher{Expected: nil}).Match(nil)
13
14 Expect(success).Should(BeFalse())
15 Expect(err).Should(HaveOccurred())
16 })
17 })
18
19 Context("When asserting on nil", func() {
20 It("should do the right thing", func() {
21 Expect("foo").ShouldNot(BeEquivalentTo(nil))
22 Expect(nil).ShouldNot(BeEquivalentTo(3))
23 Expect([]int{1, 2}).ShouldNot(BeEquivalentTo(nil))
24 })
25 })
26
27 Context("When asserting on type aliases", func() {
28 It("should the right thing", func() {
29 Expect(StringAlias("foo")).Should(BeEquivalentTo("foo"))
30 Expect("foo").Should(BeEquivalentTo(StringAlias("foo")))
31 Expect(StringAlias("foo")).ShouldNot(BeEquivalentTo("bar"))
32 Expect("foo").ShouldNot(BeEquivalentTo(StringAlias("bar")))
33 })
34 })
35
36 Context("When asserting on numbers", func() {
37 It("should convert actual to expected and do the right thing", func() {
38 Expect(5).Should(BeEquivalentTo(5))
39 Expect(5.0).Should(BeEquivalentTo(5.0))
40 Expect(5).Should(BeEquivalentTo(5.0))
41
42 Expect(5).ShouldNot(BeEquivalentTo("5"))
43 Expect(5).ShouldNot(BeEquivalentTo(3))
44
45
46 Expect(5.1).Should(BeEquivalentTo(5))
47 Expect(5).ShouldNot(BeEquivalentTo(5.1))
48 })
49 })
50 })
51
View as plain text