@@ -36,6 +36,9 @@ type pretty struct {
36
36
steps int
37
37
commentPos int
38
38
39
+ // whether scenario or scenario outline keyword was printed
40
+ scenarioKeyword bool
41
+
39
42
// outline
40
43
outlineSteps []* stepResult
41
44
outlineNumExample int
@@ -75,12 +78,16 @@ func (f *pretty) Node(node interface{}) {
75
78
case * gherkin.Scenario :
76
79
f .scenario = t
77
80
f .outline = nil
78
- f .steps = len (t .Steps )
81
+ f .steps = len (t .Steps ) + f .bgSteps
82
+ f .scenarioKeyword = false
79
83
case * gherkin.ScenarioOutline :
80
84
f .outline = t
81
85
f .scenario = nil
82
- f .steps = len (t .Steps )
83
86
f .outlineNumExample = - 1
87
+ f .scenarioKeyword = false
88
+ case * gherkin.TableRow :
89
+ f .steps = len (f .outline .Steps ) + f .bgSteps
90
+ f .outlineSteps = []* stepResult {}
84
91
}
85
92
}
86
93
@@ -237,8 +244,6 @@ func (f *pretty) printStep(step *gherkin.Step, def *StepDef, c color) {
237
244
}
238
245
239
246
func (f * pretty ) printStepKind (res * stepResult ) {
240
- _ , isBgStep := res .owner .(* gherkin.Background )
241
-
242
247
// if has not printed background yet
243
248
switch {
244
249
// first background step
@@ -249,51 +254,43 @@ func (f *pretty) printStepKind(res *stepResult) {
249
254
// subsequent background steps
250
255
case f .bgSteps > 0 :
251
256
f .bgSteps --
252
- // a background step for another scenario, but all bg steps are
253
- // already printed. so just skip it
254
- case isBgStep :
255
- return
256
257
// first step of scenario, print header and calculate comment position
257
- case f .scenario != nil && f .steps == len (f .scenario .Steps ):
258
- f .commentPos = f .longestStep (f .scenario .Steps , f .length (f .scenario ))
259
- if f .feature .Background != nil {
260
- if bgLen := f .longestStep (f .feature .Background .Steps , f .length (f .feature .Background )); bgLen > f .commentPos {
261
- f .commentPos = bgLen
258
+ case f .scenario != nil :
259
+ // print scenario keyword and value if first example
260
+ if ! f .scenarioKeyword {
261
+ f .commentPos = f .longestStep (f .scenario .Steps , f .length (f .scenario ))
262
+ if f .feature .Background != nil {
263
+ if bgLen := f .longestStep (f .feature .Background .Steps , f .length (f .feature .Background )); bgLen > f .commentPos {
264
+ f .commentPos = bgLen
265
+ }
262
266
}
267
+ text := s (f .indent ) + bcl (f .scenario .Keyword + ": " , white ) + f .scenario .Name
268
+ text += s (f .commentPos - f .length (f .scenario )+ 1 ) + f .line (f .scenario .Location )
269
+ fmt .Println ("\n " + text )
270
+ f .scenarioKeyword = true
263
271
}
264
- text := s (f .indent ) + bcl (f .scenario .Keyword + ": " , white ) + f .scenario .Name
265
- text += s (f .commentPos - f .length (f .scenario )+ 1 ) + f .line (f .scenario .Location )
266
- fmt .Println ("\n " + text )
267
- f .steps --
268
- // all subsequent scenario steps
269
- case f .scenario != nil :
270
272
f .steps --
271
273
// first step of outline scenario, print header and calculate comment position
272
- case f .outline != nil && f .steps == len (f .outline .Steps ):
273
- f .commentPos = f .longestStep (f .outline .Steps , f .length (f .outline ))
274
- if bgLen := f .longestStep (f .feature .Background .Steps , f .length (f .feature .Background )); bgLen > f .commentPos {
275
- f .commentPos = bgLen
276
- }
277
- text := s (f .indent ) + bcl (f .outline .Keyword + ": " , white ) + f .outline .Name
278
- text += s (f .commentPos - f .length (f .outline )+ 1 ) + f .line (f .outline .Location )
279
- fmt .Println ("\n " + text )
280
- f .outlineSteps = append (f .outlineSteps , res )
281
- f .steps --
282
- if len (f .outlineSteps ) == len (f .outline .Steps ) {
283
- // an outline example steps has went through
284
- f .printOutlineExample (f .outline )
285
- f .outlineSteps = []* stepResult {}
286
- f .outlineNumExamples --
287
- }
288
- return
289
- // all subsequent outline steps
290
274
case f .outline != nil :
291
275
f .outlineSteps = append (f .outlineSteps , res )
292
276
f .steps --
293
- if len (f .outlineSteps ) == len (f .outline .Steps ) {
277
+
278
+ // print scenario keyword and value if first example
279
+ if ! f .scenarioKeyword {
280
+ f .commentPos = f .longestStep (f .outline .Steps , f .length (f .outline ))
281
+ if f .feature .Background != nil {
282
+ if bgLen := f .longestStep (f .feature .Background .Steps , f .length (f .feature .Background )); bgLen > f .commentPos {
283
+ f .commentPos = bgLen
284
+ }
285
+ }
286
+ text := s (f .indent ) + bcl (f .outline .Keyword + ": " , white ) + f .outline .Name
287
+ text += s (f .commentPos - f .length (f .outline )+ 1 ) + f .line (f .outline .Location )
288
+ fmt .Println ("\n " + text )
289
+ f .scenarioKeyword = true
290
+ }
291
+ if len (f .outlineSteps ) == len (f .outline .Steps )+ f .bgSteps {
294
292
// an outline example steps has went through
295
293
f .printOutlineExample (f .outline )
296
- f .outlineSteps = []* stepResult {}
297
294
f .outlineNumExamples --
298
295
}
299
296
return
0 commit comments