@@ -13,12 +13,35 @@ type Feature struct {
13
13
Content []byte
14
14
}
15
15
16
- // FindScenario ...
16
+ // FindRule returns the rule to which the given scenario belongs
17
+ func (f Feature ) FindRule (astScenarioID string ) * messages.Rule {
18
+ for _ , child := range f .GherkinDocument .Feature .Children {
19
+ if ru := child .Rule ; ru != nil {
20
+ if rc := child .Rule ; rc != nil {
21
+ for _ , rcc := range rc .Children {
22
+ if sc := rcc .Scenario ; sc != nil && sc .Id == astScenarioID {
23
+ return ru
24
+ }
25
+ }
26
+ }
27
+ }
28
+ }
29
+ return nil
30
+ }
31
+
32
+ // FindScenario returns the scenario in the feature or in a rule in the feature
17
33
func (f Feature ) FindScenario (astScenarioID string ) * messages.Scenario {
18
34
for _ , child := range f .GherkinDocument .Feature .Children {
19
35
if sc := child .Scenario ; sc != nil && sc .Id == astScenarioID {
20
36
return sc
21
37
}
38
+ if rc := child .Rule ; rc != nil {
39
+ for _ , rcc := range rc .Children {
40
+ if sc := rcc .Scenario ; sc != nil && sc .Id == astScenarioID {
41
+ return sc
42
+ }
43
+ }
44
+ }
22
45
}
23
46
24
47
return nil
@@ -36,6 +59,18 @@ func (f Feature) FindBackground(astScenarioID string) *messages.Background {
36
59
if sc := child .Scenario ; sc != nil && sc .Id == astScenarioID {
37
60
return bg
38
61
}
62
+
63
+ if ru := child .Rule ; ru != nil {
64
+ for _ , rc := range ru .Children {
65
+ if tmp := rc .Background ; tmp != nil {
66
+ bg = tmp
67
+ }
68
+
69
+ if sc := rc .Scenario ; sc != nil && sc .Id == astScenarioID {
70
+ return bg
71
+ }
72
+ }
73
+ }
39
74
}
40
75
41
76
return nil
@@ -53,6 +88,19 @@ func (f Feature) FindExample(exampleAstID string) (*messages.Examples, *messages
53
88
}
54
89
}
55
90
}
91
+ if ru := child .Rule ; ru != nil {
92
+ for _ , rc := range ru .Children {
93
+ if sc := rc .Scenario ; sc != nil {
94
+ for _ , example := range sc .Examples {
95
+ for _ , row := range example .TableBody {
96
+ if row .Id == exampleAstID {
97
+ return example , row
98
+ }
99
+ }
100
+ }
101
+ }
102
+ }
103
+ }
56
104
}
57
105
58
106
return nil , nil
@@ -61,6 +109,27 @@ func (f Feature) FindExample(exampleAstID string) (*messages.Examples, *messages
61
109
// FindStep ...
62
110
func (f Feature ) FindStep (astStepID string ) * messages.Step {
63
111
for _ , child := range f .GherkinDocument .Feature .Children {
112
+
113
+ if ru := child .Rule ; ru != nil {
114
+ for _ , ch := range ru .Children {
115
+ if sc := ch .Scenario ; sc != nil {
116
+ for _ , step := range sc .Steps {
117
+ if step .Id == astStepID {
118
+ return step
119
+ }
120
+ }
121
+ }
122
+
123
+ if bg := ch .Background ; bg != nil {
124
+ for _ , step := range bg .Steps {
125
+ if step .Id == astStepID {
126
+ return step
127
+ }
128
+ }
129
+ }
130
+ }
131
+ }
132
+
64
133
if sc := child .Scenario ; sc != nil {
65
134
for _ , step := range sc .Steps {
66
135
if step .Id == astStepID {
0 commit comments