initial commit
[govpp.git] / vendor / github.com / onsi / gomega / gstruct / fields_test.go
1 package gstruct_test
2
3 import (
4         . "github.com/onsi/ginkgo"
5         . "github.com/onsi/gomega"
6         . "github.com/onsi/gomega/gstruct"
7 )
8
9 var _ = Describe("Struct", func() {
10         allFields := struct{ A, B string }{"a", "b"}
11         missingFields := struct{ A string }{"a"}
12         extraFields := struct{ A, B, C string }{"a", "b", "c"}
13         emptyFields := struct{ A, B string }{}
14
15         It("should strictly match all fields", func() {
16                 m := MatchAllFields(Fields{
17                         "B": Equal("b"),
18                         "A": Equal("a"),
19                 })
20                 Ω(allFields).Should(m, "should match all fields")
21                 Ω(missingFields).ShouldNot(m, "should fail with missing fields")
22                 Ω(extraFields).ShouldNot(m, "should fail with extra fields")
23                 Ω(emptyFields).ShouldNot(m, "should fail with empty fields")
24
25                 m = MatchAllFields(Fields{
26                         "A": Equal("a"),
27                         "B": Equal("fail"),
28                 })
29                 Ω(allFields).ShouldNot(m, "should run nested matchers")
30         })
31
32         It("should handle empty structs", func() {
33                 m := MatchAllFields(Fields{})
34                 Ω(struct{}{}).Should(m, "should handle empty structs")
35                 Ω(allFields).ShouldNot(m, "should fail with extra fields")
36         })
37
38         It("should ignore missing fields", func() {
39                 m := MatchFields(IgnoreMissing, Fields{
40                         "B": Equal("b"),
41                         "A": Equal("a"),
42                 })
43                 Ω(allFields).Should(m, "should match all fields")
44                 Ω(missingFields).Should(m, "should ignore missing fields")
45                 Ω(extraFields).ShouldNot(m, "should fail with extra fields")
46                 Ω(emptyFields).ShouldNot(m, "should fail with empty fields")
47         })
48
49         It("should ignore extra fields", func() {
50                 m := MatchFields(IgnoreExtras, Fields{
51                         "B": Equal("b"),
52                         "A": Equal("a"),
53                 })
54                 Ω(allFields).Should(m, "should match all fields")
55                 Ω(missingFields).ShouldNot(m, "should fail with missing fields")
56                 Ω(extraFields).Should(m, "should ignore extra fields")
57                 Ω(emptyFields).ShouldNot(m, "should fail with empty fields")
58         })
59
60         It("should ignore missing and extra fields", func() {
61                 m := MatchFields(IgnoreMissing|IgnoreExtras, Fields{
62                         "B": Equal("b"),
63                         "A": Equal("a"),
64                 })
65                 Ω(allFields).Should(m, "should match all fields")
66                 Ω(missingFields).Should(m, "should ignore missing fields")
67                 Ω(extraFields).Should(m, "should ignore extra fields")
68                 Ω(emptyFields).ShouldNot(m, "should fail with empty fields")
69
70                 m = MatchFields(IgnoreMissing|IgnoreExtras, Fields{
71                         "A": Equal("a"),
72                         "B": Equal("fail"),
73                 })
74                 Ω(allFields).ShouldNot(m, "should run nested matchers")
75         })
76 })