4 . "github.com/onsi/ginkgo"
5 . "github.com/onsi/gomega"
6 . "github.com/onsi/gomega/gstruct"
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 }{}
15 It("should strictly match all fields", func() {
16 m := MatchAllFields(Fields{
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")
25 m = MatchAllFields(Fields{
29 Ω(allFields).ShouldNot(m, "should run nested matchers")
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")
38 It("should ignore missing fields", func() {
39 m := MatchFields(IgnoreMissing, Fields{
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")
49 It("should ignore extra fields", func() {
50 m := MatchFields(IgnoreExtras, Fields{
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")
60 It("should ignore missing and extra fields", func() {
61 m := MatchFields(IgnoreMissing|IgnoreExtras, Fields{
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")
70 m = MatchFields(IgnoreMissing|IgnoreExtras, Fields{
74 Ω(allFields).ShouldNot(m, "should run nested matchers")