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

Function TestRegisterEngine_CacheHitMaintainCaptureOrder

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

Source from the content-addressed store, hash-verified

257}
258
259func TestRegisterEngine_CacheHitMaintainCaptureOrder(t *testing.T) {
260 didFindFirst := false
261 didExecute := false
262 engine := emptyEngine{
263 findFirstChar: func(r *Runner) bool {
264 didFindFirst = true
265 return true
266 },
267 execute: func(r *Runner) error {
268 didExecute = true
269 return nil
270 },
271 }
272 RegisterEngine("(?<first>This) (is)", RuntimeEngineData{
273 CapSize: 3,
274 FindFirstChar: engine.FindFirstChar,
275 Execute: engine.Execute,
276 }, OptionMaintainCaptureOrder())
277
278 re := MustCompile("(?<first>This) (is)", OptionMaintainCaptureOrder())
279 val, err := re.MatchString("This is")
280
281 if !didFindFirst {
282 t.Fatal("Expected find first char to be called, but it wasn't")
283 }
284 if !didExecute {
285 t.Fatal("Expected execute to be called, but it wasn't")
286 }
287 if err != nil {
288 t.Fatal("Unexpected error", err)
289 }
290 if val {
291 t.Fatal("Expected no match")
292 }
293}
294
295func TestStringPrefixFilterSkipsDecodeOnMiss(t *testing.T) {
296 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