Debian Codegraph @

gstruct/keys.go

raw symbols SCIP
1 // untested sections: 6
2
3 package gstructscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/gstruct`/
4
5 import (
6 "errorsscip-go gomod github.com/golang/go/src go1.24.0 errors/"
7 "fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/"
8 "reflectscip-go gomod github.com/golang/go/src go1.24.0 reflect/"
9 "runtime/debugscip-go gomod github.com/golang/go/src go1.24.0 `runtime/debug`/"
10 "stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/"
11
12 "github.com/onsi/gomega/formatscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/format`/"
13 errorsutilscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/gstruct/errors`/ "github.com/onsi/gomega/gstruct/errorsscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/gstruct/errors`/"
14 "github.com/onsi/gomega/typesscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/types`/"
15 )
16
17 func MatchAllKeysscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/gstruct`/MatchAllKeys().(keys Keysscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/gstruct`/Keys#) typesscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/types`/.GomegaMatcherscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/types`/GomegaMatcher# {
18 return &KeysMatcherscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/gstruct`/KeysMatcher#{
19 Keysscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/gstruct`/KeysMatcher#Keys.: keys,
20 }
21 }
22
23 func MatchKeysscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/gstruct`/MatchKeys().(options Optionsscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/gstruct`/Options#, keys Keysscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/gstruct`/Keys#) typesscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/types`/.GomegaMatcherscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/types`/GomegaMatcher# {
24 return &KeysMatcherscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/gstruct`/KeysMatcher#{
25 Keysscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/gstruct`/KeysMatcher#Keys.: keys,
26 IgnoreExtrasscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/gstruct`/KeysMatcher#IgnoreExtras.: options&IgnoreExtrasscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/gstruct`/IgnoreExtras. != 0,
27 IgnoreMissingscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/gstruct`/KeysMatcher#IgnoreMissing.: options&IgnoreMissingscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/gstruct`/IgnoreMissing. != 0,
28 }
29 }
30
31 type KeysMatcherscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/gstruct`/KeysMatcher# struct {
32 // Matchers for each key.
33 Keysscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/gstruct`/KeysMatcher#Keys. Keysscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/gstruct`/Keys#
34
35 // Whether to ignore extra keys or consider it an error.
36 IgnoreExtrasscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/gstruct`/KeysMatcher#IgnoreExtras. bool
37 // Whether to ignore missing keys or consider it an error.
38 IgnoreMissingscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/gstruct`/KeysMatcher#IgnoreMissing. bool
39
40 // State.
41 failuresscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/gstruct`/KeysMatcher#failures. []error
42 }
43
44 type Keysscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/gstruct`/Keys# map[any]typesscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/types`/.GomegaMatcherscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/types`/GomegaMatcher#
45
46 func (m *KeysMatcherscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/gstruct`/KeysMatcher#) Matchscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/gstruct`/KeysMatcher#Match().(actual any) (success bool, err error) {
47 if reflectscip-go gomod github.com/golang/go/src go1.24.0 reflect/.TypeOfscip-go gomod github.com/golang/go/src go1.24.0 reflect/TypeOf().(actual).Kindscip-go gomod github.com/golang/go/src go1.24.0 reflect/Type#Kind().() != reflectscip-go gomod github.com/golang/go/src go1.24.0 reflect/.Mapscip-go gomod github.com/golang/go/src go1.24.0 reflect/Map. {
48 return false, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().("%v is type %T, expected map", actual, actual)
49 }
50
51 m.failuresscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/gstruct`/KeysMatcher#failures. = m.matchKeysscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/gstruct`/KeysMatcher#matchKeys().(actual)
52 if len(m.failuresscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/gstruct`/KeysMatcher#failures.) > 0 {
53 return false, nil
54 }
55 return true, nil
56 }
57
58 func (m *KeysMatcherscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/gstruct`/KeysMatcher#) matchKeysscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/gstruct`/KeysMatcher#matchKeys().(actual any) (errs []error) {
59 actualValue := reflectscip-go gomod github.com/golang/go/src go1.24.0 reflect/.ValueOfscip-go gomod github.com/golang/go/src go1.24.0 reflect/ValueOf().(actual)
60 keys := map[any]bool{}
61 for _, keyValue := range actualValue.MapKeysscip-go gomod github.com/golang/go/src go1.24.0 reflect/Value#MapKeys().() {
62 key := keyValue.Interfacescip-go gomod github.com/golang/go/src go1.24.0 reflect/Value#Interface().()
63 keys[key] = true
64
65 err := func() (err error) {
66 // This test relies heavily on reflect, which tends to panic.
67 // Recover here to provide more useful error messages in that case.
68 defer func() {
69 if r := recover(); r != nil {
70 err = fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().("panic checking %+v: %v\n%s", actual, r, debugscip-go gomod github.com/golang/go/src go1.24.0 `runtime/debug`/.Stackscip-go gomod github.com/golang/go/src go1.24.0 `runtime/debug`/Stack().())
71 }
72 }()
73
74 matcher, ok := m.Keysscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/gstruct`/KeysMatcher#Keys.[key]
75 if !ok {
76 if !m.IgnoreExtrasscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/gstruct`/KeysMatcher#IgnoreExtras. {
77 return fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().("unexpected key %s: %+v", key, actual)
78 }
79 return nil
80 }
81
82 valInterface := actualValue.MapIndexscip-go gomod github.com/golang/go/src go1.24.0 reflect/Value#MapIndex().(keyValue).Interfacescip-go gomod github.com/golang/go/src go1.24.0 reflect/Value#Interface().()
83
84 match, err := matcher.Matchscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/types`/GomegaMatcher#Match.(valInterface)
85 if err != nil {
86 return err
87 }
88
89 if !match {
90 if nesting, ok := matcher.(errorsutilscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/gstruct/errors`/.NestingMatcherscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/gstruct/errors`/NestingMatcher#); ok {
91 return errorsutilscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/gstruct/errors`/.AggregateErrorscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/gstruct/errors`/AggregateError#(nesting.Failuresscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/gstruct/errors`/NestingMatcher#Failures.())
92 }
93 return errorsscip-go gomod github.com/golang/go/src go1.24.0 errors/.Newscip-go gomod github.com/golang/go/src go1.24.0 errors/New().(matcher.FailureMessagescip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/types`/GomegaMatcher#FailureMessage.(valInterface))
94 }
95 return nil
96 }()
97 if err != nil {
98 errs = append(errs, errorsutilscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/gstruct/errors`/.Nestscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/gstruct/errors`/Nest().(fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Sprintf().(".%#v", key), err))
99 }
100 }
101
102 for key := range m.Keysscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/gstruct`/KeysMatcher#Keys. {
103 if !keys[key] && !m.IgnoreMissingscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/gstruct`/KeysMatcher#IgnoreMissing. {
104 errs = append(errs, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().("missing expected key %s", key))
105 }
106 }
107
108 return errs
109 }
110
111 func (m *KeysMatcherscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/gstruct`/KeysMatcher#) FailureMessagescip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/gstruct`/KeysMatcher#FailureMessage().(actual any) (message string) {
112 failures := make([]string, len(m.failuresscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/gstruct`/KeysMatcher#failures.))
113 for i := range m.failuresscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/gstruct`/KeysMatcher#failures. {
114 failures[i] = m.failuresscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/gstruct`/KeysMatcher#failures.[i].Error()
115 }
116 return formatscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/format`/.Messagescip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/format`/Message().(reflectscip-go gomod github.com/golang/go/src go1.24.0 reflect/.TypeOfscip-go gomod github.com/golang/go/src go1.24.0 reflect/TypeOf().(actual).Namescip-go gomod github.com/golang/go/src go1.24.0 reflect/Type#Name().(),
117 fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Sprintf().("to match keys: {\n%v\n}\n", stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.Joinscip-go gomod github.com/golang/go/src go1.24.0 strings/Join().(failures, "\n")))
118 }
119
120 func (m *KeysMatcherscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/gstruct`/KeysMatcher#) NegatedFailureMessagescip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/gstruct`/KeysMatcher#NegatedFailureMessage().(actual any) (message string) {
121 return formatscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/format`/.Messagescip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/format`/Message().(actual, "not to match keys")
122 }
123
124 func (m *KeysMatcherscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/gstruct`/KeysMatcher#) Failuresscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/gstruct`/KeysMatcher#Failures().() []error {
125 return m.failuresscip-go gomod github.com/onsi/gomega . `github.com/onsi/gomega/gstruct`/KeysMatcher#failures.
126 }