4 . "github.com/onsi/ginkgo"
5 . "github.com/onsi/gomega"
8 var _ = Describe("ConsistOf", func() {
9 Context("with a slice", func() {
10 It("should do the right thing", func() {
11 Ω([]string{"foo", "bar", "baz"}).Should(ConsistOf("foo", "bar", "baz"))
12 Ω([]string{"foo", "bar", "baz"}).Should(ConsistOf("foo", "bar", "baz"))
13 Ω([]string{"foo", "bar", "baz"}).Should(ConsistOf("baz", "bar", "foo"))
14 Ω([]string{"foo", "bar", "baz"}).ShouldNot(ConsistOf("baz", "bar", "foo", "foo"))
15 Ω([]string{"foo", "bar", "baz"}).ShouldNot(ConsistOf("baz", "foo"))
19 Context("with an array", func() {
20 It("should do the right thing", func() {
21 Ω([3]string{"foo", "bar", "baz"}).Should(ConsistOf("foo", "bar", "baz"))
22 Ω([3]string{"foo", "bar", "baz"}).Should(ConsistOf("baz", "bar", "foo"))
23 Ω([3]string{"foo", "bar", "baz"}).ShouldNot(ConsistOf("baz", "bar", "foo", "foo"))
24 Ω([3]string{"foo", "bar", "baz"}).ShouldNot(ConsistOf("baz", "foo"))
28 Context("with a map", func() {
29 It("should apply to the values", func() {
30 Ω(map[int]string{1: "foo", 2: "bar", 3: "baz"}).Should(ConsistOf("foo", "bar", "baz"))
31 Ω(map[int]string{1: "foo", 2: "bar", 3: "baz"}).Should(ConsistOf("baz", "bar", "foo"))
32 Ω(map[int]string{1: "foo", 2: "bar", 3: "baz"}).ShouldNot(ConsistOf("baz", "bar", "foo", "foo"))
33 Ω(map[int]string{1: "foo", 2: "bar", 3: "baz"}).ShouldNot(ConsistOf("baz", "foo"))
38 Context("with anything else", func() {
39 It("should error", func() {
40 failures := InterceptGomegaFailures(func() {
41 Ω("foo").Should(ConsistOf("f", "o", "o"))
44 Ω(failures).Should(HaveLen(1))
48 Context("when passed matchers", func() {
49 It("should pass if the matchers pass", func() {
50 Ω([]string{"foo", "bar", "baz"}).Should(ConsistOf("foo", MatchRegexp("^ba"), "baz"))
51 Ω([]string{"foo", "bar", "baz"}).ShouldNot(ConsistOf("foo", MatchRegexp("^ba")))
52 Ω([]string{"foo", "bar", "baz"}).ShouldNot(ConsistOf("foo", MatchRegexp("^ba"), MatchRegexp("foo")))
53 Ω([]string{"foo", "bar", "baz"}).Should(ConsistOf("foo", MatchRegexp("^ba"), MatchRegexp("^ba")))
54 Ω([]string{"foo", "bar", "baz"}).ShouldNot(ConsistOf("foo", MatchRegexp("^ba"), MatchRegexp("turducken")))
57 It("should not depend on the order of the matchers", func() {
58 Ω([][]int{[]int{1, 2}, []int{2}}).Should(ConsistOf(ContainElement(1), ContainElement(2)))
59 Ω([][]int{[]int{1, 2}, []int{2}}).Should(ConsistOf(ContainElement(2), ContainElement(1)))
62 Context("when a matcher errors", func() {
63 It("should soldier on", func() {
64 Ω([]string{"foo", "bar", "baz"}).ShouldNot(ConsistOf(BeFalse(), "foo", "bar"))
65 Ω([]interface{}{"foo", "bar", false}).Should(ConsistOf(BeFalse(), ContainSubstring("foo"), "bar"))
70 Context("when passed exactly one argument, and that argument is a slice", func() {
71 It("should match against the elements of that argument", func() {
72 Ω([]string{"foo", "bar", "baz"}).Should(ConsistOf([]string{"foo", "bar", "baz"}))