fixes outline example printer, fixes #47
Этот коммит содержится в:
родитель
409db5f4de
коммит
6b2d813498
4 изменённых файлов: 40 добавлений и 45 удалений
|
@ -20,6 +20,6 @@ Feature: get version
|
||||||
And the response should match json:
|
And the response should match json:
|
||||||
"""
|
"""
|
||||||
{
|
{
|
||||||
"version": "v0.5.0"
|
"version": "v0.5.3"
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
4
fmt.go
4
fmt.go
|
@ -145,12 +145,10 @@ type basefmt struct {
|
||||||
|
|
||||||
func (f *basefmt) Node(n interface{}) {
|
func (f *basefmt) Node(n interface{}) {
|
||||||
switch t := n.(type) {
|
switch t := n.(type) {
|
||||||
case *gherkin.ScenarioOutline:
|
case *gherkin.TableRow:
|
||||||
f.owner = t
|
f.owner = t
|
||||||
case *gherkin.Scenario:
|
case *gherkin.Scenario:
|
||||||
f.owner = t
|
f.owner = t
|
||||||
case *gherkin.Background:
|
|
||||||
f.owner = t
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,9 @@ type pretty struct {
|
||||||
steps int
|
steps int
|
||||||
commentPos int
|
commentPos int
|
||||||
|
|
||||||
|
// whether scenario or scenario outline keyword was printed
|
||||||
|
scenarioKeyword bool
|
||||||
|
|
||||||
// outline
|
// outline
|
||||||
outlineSteps []*stepResult
|
outlineSteps []*stepResult
|
||||||
outlineNumExample int
|
outlineNumExample int
|
||||||
|
@ -75,12 +78,16 @@ func (f *pretty) Node(node interface{}) {
|
||||||
case *gherkin.Scenario:
|
case *gherkin.Scenario:
|
||||||
f.scenario = t
|
f.scenario = t
|
||||||
f.outline = nil
|
f.outline = nil
|
||||||
f.steps = len(t.Steps)
|
f.steps = len(t.Steps) + f.bgSteps
|
||||||
|
f.scenarioKeyword = false
|
||||||
case *gherkin.ScenarioOutline:
|
case *gherkin.ScenarioOutline:
|
||||||
f.outline = t
|
f.outline = t
|
||||||
f.scenario = nil
|
f.scenario = nil
|
||||||
f.steps = len(t.Steps)
|
|
||||||
f.outlineNumExample = -1
|
f.outlineNumExample = -1
|
||||||
|
f.scenarioKeyword = false
|
||||||
|
case *gherkin.TableRow:
|
||||||
|
f.steps = len(f.outline.Steps) + f.bgSteps
|
||||||
|
f.outlineSteps = []*stepResult{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -237,8 +244,6 @@ func (f *pretty) printStep(step *gherkin.Step, def *StepDef, c color) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *pretty) printStepKind(res *stepResult) {
|
func (f *pretty) printStepKind(res *stepResult) {
|
||||||
_, isBgStep := res.owner.(*gherkin.Background)
|
|
||||||
|
|
||||||
// if has not printed background yet
|
// if has not printed background yet
|
||||||
switch {
|
switch {
|
||||||
// first background step
|
// first background step
|
||||||
|
@ -249,51 +254,43 @@ func (f *pretty) printStepKind(res *stepResult) {
|
||||||
// subsequent background steps
|
// subsequent background steps
|
||||||
case f.bgSteps > 0:
|
case f.bgSteps > 0:
|
||||||
f.bgSteps--
|
f.bgSteps--
|
||||||
// a background step for another scenario, but all bg steps are
|
|
||||||
// already printed. so just skip it
|
|
||||||
case isBgStep:
|
|
||||||
return
|
|
||||||
// first step of scenario, print header and calculate comment position
|
// first step of scenario, print header and calculate comment position
|
||||||
case f.scenario != nil && f.steps == len(f.scenario.Steps):
|
|
||||||
f.commentPos = f.longestStep(f.scenario.Steps, f.length(f.scenario))
|
|
||||||
if f.feature.Background != nil {
|
|
||||||
if bgLen := f.longestStep(f.feature.Background.Steps, f.length(f.feature.Background)); bgLen > f.commentPos {
|
|
||||||
f.commentPos = bgLen
|
|
||||||
}
|
|
||||||
}
|
|
||||||
text := s(f.indent) + bcl(f.scenario.Keyword+": ", white) + f.scenario.Name
|
|
||||||
text += s(f.commentPos-f.length(f.scenario)+1) + f.line(f.scenario.Location)
|
|
||||||
fmt.Println("\n" + text)
|
|
||||||
f.steps--
|
|
||||||
// all subsequent scenario steps
|
|
||||||
case f.scenario != nil:
|
case f.scenario != nil:
|
||||||
|
// print scenario keyword and value if first example
|
||||||
|
if !f.scenarioKeyword {
|
||||||
|
f.commentPos = f.longestStep(f.scenario.Steps, f.length(f.scenario))
|
||||||
|
if f.feature.Background != nil {
|
||||||
|
if bgLen := f.longestStep(f.feature.Background.Steps, f.length(f.feature.Background)); bgLen > f.commentPos {
|
||||||
|
f.commentPos = bgLen
|
||||||
|
}
|
||||||
|
}
|
||||||
|
text := s(f.indent) + bcl(f.scenario.Keyword+": ", white) + f.scenario.Name
|
||||||
|
text += s(f.commentPos-f.length(f.scenario)+1) + f.line(f.scenario.Location)
|
||||||
|
fmt.Println("\n" + text)
|
||||||
|
f.scenarioKeyword = true
|
||||||
|
}
|
||||||
f.steps--
|
f.steps--
|
||||||
// first step of outline scenario, print header and calculate comment position
|
// first step of outline scenario, print header and calculate comment position
|
||||||
case f.outline != nil && f.steps == len(f.outline.Steps):
|
|
||||||
f.commentPos = f.longestStep(f.outline.Steps, f.length(f.outline))
|
|
||||||
if bgLen := f.longestStep(f.feature.Background.Steps, f.length(f.feature.Background)); bgLen > f.commentPos {
|
|
||||||
f.commentPos = bgLen
|
|
||||||
}
|
|
||||||
text := s(f.indent) + bcl(f.outline.Keyword+": ", white) + f.outline.Name
|
|
||||||
text += s(f.commentPos-f.length(f.outline)+1) + f.line(f.outline.Location)
|
|
||||||
fmt.Println("\n" + text)
|
|
||||||
f.outlineSteps = append(f.outlineSteps, res)
|
|
||||||
f.steps--
|
|
||||||
if len(f.outlineSteps) == len(f.outline.Steps) {
|
|
||||||
// an outline example steps has went through
|
|
||||||
f.printOutlineExample(f.outline)
|
|
||||||
f.outlineSteps = []*stepResult{}
|
|
||||||
f.outlineNumExamples--
|
|
||||||
}
|
|
||||||
return
|
|
||||||
// all subsequent outline steps
|
|
||||||
case f.outline != nil:
|
case f.outline != nil:
|
||||||
f.outlineSteps = append(f.outlineSteps, res)
|
f.outlineSteps = append(f.outlineSteps, res)
|
||||||
f.steps--
|
f.steps--
|
||||||
if len(f.outlineSteps) == len(f.outline.Steps) {
|
|
||||||
|
// print scenario keyword and value if first example
|
||||||
|
if !f.scenarioKeyword {
|
||||||
|
f.commentPos = f.longestStep(f.outline.Steps, f.length(f.outline))
|
||||||
|
if f.feature.Background != nil {
|
||||||
|
if bgLen := f.longestStep(f.feature.Background.Steps, f.length(f.feature.Background)); bgLen > f.commentPos {
|
||||||
|
f.commentPos = bgLen
|
||||||
|
}
|
||||||
|
}
|
||||||
|
text := s(f.indent) + bcl(f.outline.Keyword+": ", white) + f.outline.Name
|
||||||
|
text += s(f.commentPos-f.length(f.outline)+1) + f.line(f.outline.Location)
|
||||||
|
fmt.Println("\n" + text)
|
||||||
|
f.scenarioKeyword = true
|
||||||
|
}
|
||||||
|
if len(f.outlineSteps) == len(f.outline.Steps)+f.bgSteps {
|
||||||
// an outline example steps has went through
|
// an outline example steps has went through
|
||||||
f.printOutlineExample(f.outline)
|
f.printOutlineExample(f.outline)
|
||||||
f.outlineSteps = []*stepResult{}
|
|
||||||
f.outlineNumExamples--
|
f.outlineNumExamples--
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|
2
godog.go
2
godog.go
|
@ -42,4 +42,4 @@ Godog was inspired by Behat and Cucumber the above description is taken from it'
|
||||||
package godog
|
package godog
|
||||||
|
|
||||||
// Version of package - based on Semantic Versioning 2.0.0 http://semver.org/
|
// Version of package - based on Semantic Versioning 2.0.0 http://semver.org/
|
||||||
const Version = "v0.5.0"
|
const Version = "v0.5.3"
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче