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

Function TestRegisterEngine_CacheHit

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

Source from the content-addressed store, hash-verified

17}
18
19func TestRegisterEngine_CacheHit(t *testing.T) {
20 didFindFirst := false
21 didExecute := false
22 engine := emptyEngine{
23 findFirstChar: func(r *Runner) bool {
24 didFindFirst = true
25 return true
26 },
27 execute: func(r *Runner) error {
28 didExecute = true
29 return nil
30 },
31 }
32 RegisterEngine("This is a regexp", RuntimeEngineData{
33 CapSize: 1,
34 FindFirstChar: engine.FindFirstChar,
35 Execute: engine.Execute,
36 }, RE2)
37
38 re := MustCompile("This is a regexp", RE2)
39 val, err := re.MatchString("This is a regexp")
40
41 if !didFindFirst {
42 t.Fatal("Expected find first char to be called, but it wasn't")
43 }
44 if !didExecute {
45 t.Fatal("Expected execute to be called, but it wasn't")
46 }
47 if err != nil {
48 t.Fatal("Unexpected error", err)
49 }
50 if val {
51 t.Fatal("Expected no match")
52 }
53}
54
55func TestRegisterEngine_QuickExecute(t *testing.T) {
56 const pattern = "quick-execute"

Callers

nothing calls this directly

Calls 3

RegisterEngineFunction · 0.85
MustCompileFunction · 0.70
MatchStringMethod · 0.65

Tested by

no test coverage detected