aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/onsi/gomega/matchers/assignable_to_type_of_matcher_test.go
blob: d2280e0506dcbc817c6db3930ad16d18131859f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package matchers_test

import (
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	. "github.com/onsi/gomega/matchers"
)

var _ = Describe("AssignableToTypeOf", func() {
	Context("When asserting assignability between types", func() {
		It("should do the right thing", func() {
			Ω(0).Should(BeAssignableToTypeOf(0))
			Ω(5).Should(BeAssignableToTypeOf(-1))
			Ω("foo").Should(BeAssignableToTypeOf("bar"))
			Ω(struct{ Foo string }{}).Should(BeAssignableToTypeOf(struct{ Foo string }{}))

			Ω(0).ShouldNot(BeAssignableToTypeOf("bar"))
			Ω(5).ShouldNot(BeAssignableToTypeOf(struct{ Foo string }{}))
			Ω("foo").ShouldNot(BeAssignableToTypeOf(42))
		})
	})

	Context("When asserting nil values", func() {
		It("should error", func() {
			success, err := (&AssignableToTypeOfMatcher{Expected: nil}).Match(nil)
			Ω(success).Should(BeFalse())
			Ω(err).Should(HaveOccurred())
		})
	})
})