MCPcopy Create free account
hub / github.com/daodst/chat / TestPatternMatches

Function TestPatternMatches

internal/pushrules/evaluate_test.go:150–181  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

148}
149
150func TestPatternMatches(t *testing.T) {
151 tsts := []struct {
152 Name string
153 Key string
154 Pattern string
155 EventJSON string
156 Want bool
157 }{
158 {"empty", "", "", `{}`, false},
159
160 // Note that an empty pattern contains no wildcard characters,
161 // which implicitly means "*".
162 {"patternEmpty", "content", "", `{"content":{}}`, true},
163
164 {"literal", "content.creator", "acreator", `{"content":{"creator":"acreator"}}`, true},
165 {"substring", "content.creator", "reat", `{"content":{"creator":"acreator"}}`, true},
166 {"singlePattern", "content.creator", "acr?ator", `{"content":{"creator":"acreator"}}`, true},
167 {"multiPattern", "content.creator", "a*ea*r", `{"content":{"creator":"acreator"}}`, true},
168 {"patternNoSubstring", "content.creator", "r*t", `{"content":{"creator":"acreator"}}`, false},
169 }
170 for _, tst := range tsts {
171 t.Run(tst.Name, func(t *testing.T) {
172 got, err := patternMatches(tst.Key, tst.Pattern, mustEventFromJSON(t, tst.EventJSON))
173 if err != nil {
174 t.Fatalf("patternMatches failed: %v", err)
175 }
176 if got != tst.Want {
177 t.Errorf("patternMatches: got %v, want %v", got, tst.Want)
178 }
179 })
180 }
181}
182
183func mustEventFromJSON(t *testing.T, json string) *gomatrixserverlib.Event {
184 ev, err := gomatrixserverlib.NewEventFromTrustedJSON([]byte(json), false, gomatrixserverlib.RoomVersionV7)

Callers

nothing calls this directly

Calls 3

patternMatchesFunction · 0.85
mustEventFromJSONFunction · 0.85
RunMethod · 0.80

Tested by

no test coverage detected