forked from regen-network/gocuke
-
Notifications
You must be signed in to change notification settings - Fork 0
/
guess_test.go
60 lines (48 loc) · 1.27 KB
/
guess_test.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package gocuke
import (
"testing"
messages "github.com/cucumber/messages/go/v21"
"gotest.tools/v3/assert"
)
func TestGuessMethodSig(t *testing.T) {
NewRunner(t, &guessSuite{}).Path("features/guess.feature").Run()
}
type guessSuite struct {
TestingT
step string
sig methodSig
matches []string
hasDocString bool
hasDataTable bool
}
func (s *guessSuite) TheStep(a DocString) {
s.step = a.Content
}
func (s *guessSuite) WeGuessTheStepDefinition() {
ps := &messages.PickleStep{Text: s.step}
if s.hasDocString {
ps.Argument = &messages.PickleStepArgument{DocString: &messages.PickleDocString{}}
}
if s.hasDataTable {
ps.Argument = &messages.PickleStepArgument{DataTable: &messages.PickleTable{}}
}
s.sig = guessMethodSig(ps)
}
func (s *guessSuite) WeGetTheMethodSignature(a DocString) {
assert.Equal(s, s.sig.methodSig(), a.Content)
}
func (s *guessSuite) WeMatchTheStep() {
s.matches = s.sig.regex.FindStringSubmatch(s.step)[1:]
}
func (s *guessSuite) WeGetTheValues(a DataTable) {
assert.Equal(s, a.NumCols(), len(s.matches))
for i, match := range s.matches {
assert.Equal(s, a.Cell(0, i).String(), match)
}
}
func (s *guessSuite) WithADocString() {
s.hasDocString = true
}
func (s *guessSuite) WithADataTable() {
s.hasDataTable = true
}