forked from regen-network/gocuke
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfind_step.go
45 lines (35 loc) · 886 Bytes
/
find_step.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package gocuke
import (
"testing"
messages "github.com/cucumber/messages/go/v22"
)
func (r *Runner) findStep(t *testing.T, step *messages.PickleStep) *stepDef {
t.Helper()
r.stepDefsMutex.RLock()
def := findSubmatch(t, step.Text, r.stepDefs)
r.stepDefsMutex.RUnlock()
if def != nil {
return def
}
sig := guessMethodSig(step)
method, ok := r.suiteType.MethodByName(sig.name)
if ok {
return r.addStepDef(t, sig.regex, method.Func)
}
if !r.haveSuggestion[sig.name] {
r.haveSuggestion[sig.name] = true
r.suggestions = append(r.suggestions, sig)
}
t.Errorf("can't find step definition for: %s", step.Text)
return nil
}
func findSubmatch(t *testing.T, stepText string, stepDefs []*stepDef) *stepDef {
t.Helper()
for _, def := range stepDefs {
matches := def.regex.FindSubmatch([]byte(stepText))
if len(matches) != 0 {
return def
}
}
return nil
}