MCPcopy Create free account
hub / github.com/dlclark/regexp2 / TestRegisterEngine_CacheHitMaintainCaptureOrder

Function TestRegisterEngine_CacheHitMaintainCaptureOrder

regexp_codegen_test.go:199–233  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

197}
198
199func TestRegisterEngine_CacheHitMaintainCaptureOrder(t *testing.T) {
200 didFindFirst := false
201 didExecute := false
202 engine := emptyEngine{
203 findFirstChar: func(r *Runner) bool {
204 didFindFirst = true
205 return true
206 },
207 execute: func(r *Runner) error {
208 didExecute = true
209 return nil
210 },
211 }
212 RegisterEngine("(?<first>This) (is)", RuntimeEngineData{
213 CapSize: 3,
214 FindFirstChar: engine.FindFirstChar,
215 Execute: engine.Execute,
216 }, OptionMaintainCaptureOrder())
217
218 re := MustCompile("(?<first>This) (is)", OptionMaintainCaptureOrder())
219 val, err := re.MatchString("This is")
220
221 if !didFindFirst {
222 t.Fatal("Expected find first char to be called, but it wasn't")
223 }
224 if !didExecute {
225 t.Fatal("Expected execute to be called, but it wasn't")
226 }
227 if err != nil {
228 t.Fatal("Unexpected error", err)
229 }
230 if val {
231 t.Fatal("Expected no match")
232 }
233}
234
235func TestStringPrefixFilterSkipsDecodeOnMiss(t *testing.T) {
236 const pattern = `string-prefix-filter-miss-only`

Callers

nothing calls this directly

Calls 4

RegisterEngineFunction · 0.85
MustCompileFunction · 0.70
MatchStringMethod · 0.65

Tested by

no test coverage detected