MCPcopy
hub / github.com/grafana/tempo / TestShouldMemoize

Function TestShouldMemoize

pkg/regexp/regexp_test.go:158–196  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

156}
157
158func TestShouldMemoize(t *testing.T) {
159 tcs := []struct {
160 regex string
161 shouldMemoize bool
162 }{
163 {
164 regex: ".*",
165 shouldMemoize: false,
166 },
167 {
168 regex: "foo.*",
169 shouldMemoize: false,
170 },
171 {
172 regex: ".*bar",
173 shouldMemoize: false,
174 },
175 {
176 regex: "foo|bar",
177 shouldMemoize: false,
178 },
179 {
180 regex: ".*bar.*", // creates a containsStringMatcher so should not memoize
181 shouldMemoize: false,
182 },
183 {
184 regex: ".*bar.*foo.*", // now uses a stringMatcher in prometheus v0.311.2+
185 shouldMemoize: false,
186 },
187 }
188
189 for _, tc := range tcs {
190 t.Run(tc.regex, func(t *testing.T) {
191 m, err := labels.NewFastRegexMatcher(tc.regex)
192 require.NoError(t, err)
193 require.Equal(t, tc.shouldMemoize, shouldMemoize(m))
194 })
195 }
196}

Callers

nothing calls this directly

Calls 3

shouldMemoizeFunction · 0.85
RunMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected