Added examples logic.
Этот коммит содержится в:
родитель
a201aed432
коммит
9820f49ceb
1 изменённых файлов: 121 добавлений и 60 удалений
|
@ -7,6 +7,7 @@ import (
|
|||
"strings"
|
||||
"github.com/DATA-DOG/godog/gherkin"
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
const cukeurl = "https://www.relishapp.com/cucumber/cucumber/docs/formatters/json-output-formatter"
|
||||
|
@ -47,6 +48,21 @@ type cukeMatch struct {
|
|||
Location string `json:"location"`
|
||||
}
|
||||
|
||||
type cukeExample struct {
|
||||
Keyword string `json:"keyword"`
|
||||
Id string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Line int `json:"line"`
|
||||
Description string `json:"description"`
|
||||
Rows []cukeRow `json:"rows"`
|
||||
}
|
||||
|
||||
type cukeRow struct {
|
||||
Cells []string `json:"cells"`
|
||||
Id string `json:"id"`
|
||||
Line int `json:"line"`
|
||||
}
|
||||
|
||||
type cukeStep struct {
|
||||
Keyword string `json:"keyword"`
|
||||
Name string `json:"name"`
|
||||
|
@ -55,7 +71,6 @@ type cukeStep struct {
|
|||
Result cukeResult `json:"result"`
|
||||
}
|
||||
|
||||
|
||||
type cukeElement struct {
|
||||
Keyword string `json:"keyword"`
|
||||
Id string `json:"id"`
|
||||
|
@ -65,7 +80,7 @@ type cukeElement struct {
|
|||
Tags []cukeTag `json:"tags"`
|
||||
Type string `json:type`
|
||||
Steps []cukeStep `json:steps`
|
||||
|
||||
Examples []cukeExample `json:examples,omitempty`
|
||||
}
|
||||
|
||||
type cukeFeatureJson struct {
|
||||
|
@ -77,7 +92,6 @@ type cukeFeatureJson struct {
|
|||
Description string `json:"description"`
|
||||
Tags []cukeTag `json:"tags"`
|
||||
Elements []cukeElement `json:"elements"`
|
||||
|
||||
}
|
||||
|
||||
type cukefmt struct {
|
||||
|
@ -95,16 +109,58 @@ type cukefmt struct {
|
|||
curStep *cukeStep // track the current step
|
||||
curElement *cukeElement // track the current element
|
||||
curFeature *cukeFeatureJson // track the current feature
|
||||
|
||||
}
|
||||
|
||||
|
||||
func (f *cukefmt) Node(n interface{}) {
|
||||
f.basefmt.Node(n)
|
||||
|
||||
switch t := n.(type) {
|
||||
|
||||
case *gherkin.Examples:
|
||||
ex := cukeExample{}
|
||||
ex.Description = t.Description
|
||||
ex.Id = f.curElement.Id + ";" + makeId(t.Name)
|
||||
ex.Line = t.Location.Line
|
||||
ex.Name = t.Name
|
||||
ex.Keyword = t.Keyword
|
||||
ex.Rows = make([]cukeRow,len(t.TableBody)+1)
|
||||
|
||||
// first row is the header
|
||||
ex.Rows[0].Line = t.TableHeader.Location.Line
|
||||
ex.Rows[0].Cells = make([]string,len(t.TableHeader.Cells))
|
||||
ex.Rows[0].Id = ex.Id + ";1"
|
||||
for idx, val := range t.TableHeader.Cells {
|
||||
ex.Rows[0].Cells[idx] = val.Value
|
||||
}
|
||||
|
||||
// The other example are in the body
|
||||
for i, row := range t.TableBody {
|
||||
ex.Rows[1+i].Line = row.Location.Line
|
||||
ex.Rows[1+i].Cells = make([]string,len(row.Cells))
|
||||
ex.Rows[1+i].Id = ex.Id + ";"+strconv.Itoa(i+2)
|
||||
for idx, val := range row.Cells {
|
||||
ex.Rows[1+i].Cells[idx] = val.Value
|
||||
}
|
||||
}
|
||||
|
||||
f.curElement.Examples = append(f.curElement.Examples,ex)
|
||||
|
||||
case *gherkin.ScenarioOutline:
|
||||
f.curFeature.Elements = append(f.curFeature.Elements, cukeElement{})
|
||||
f.curElement = &f.curFeature.Elements[len(f.curFeature.Elements) - 1]
|
||||
|
||||
f.curElement.Name = t.Name
|
||||
f.curElement.Line = t.Location.Line
|
||||
f.curElement.Description = t.Description
|
||||
f.curElement.Keyword = t.Keyword
|
||||
f.curElement.Id = f.curFeature.Id + ";" + makeId(t.Name)
|
||||
f.curElement.Type = t.Type
|
||||
f.curElement.Tags = make([]cukeTag, len(t.Tags))
|
||||
for idx, element := range t.Tags {
|
||||
f.curElement.Tags[idx].Line = element.Location.Line
|
||||
f.curElement.Tags[idx].Name = element.Name
|
||||
}
|
||||
|
||||
case *gherkin.Scenario:
|
||||
f.curFeature.Elements = append(f.curFeature.Elements, cukeElement{})
|
||||
f.curElement = &f.curFeature.Elements[len(f.curFeature.Elements) - 1]
|
||||
|
@ -122,6 +178,7 @@ func (f *cukefmt) Node(n interface{}) {
|
|||
}
|
||||
|
||||
case *gherkin.TableRow:
|
||||
|
||||
fmt.Fprintf(f.out, "Entering Node TableRow: %s:%d\n", f.path, t.Location.Line)
|
||||
}
|
||||
|
||||
|
@ -129,7 +186,6 @@ func (f *cukefmt) Node(n interface{}) {
|
|||
|
||||
func (f *cukefmt) Feature(ft *gherkin.Feature, p string, c []byte) {
|
||||
|
||||
|
||||
f.basefmt.Feature(ft, p, c)
|
||||
f.path = p
|
||||
f.id = makeId(ft.Name)
|
||||
|
@ -161,7 +217,6 @@ func (f *cukefmt) Summary() {
|
|||
|
||||
func (f *cukefmt) step(res *stepResult) {
|
||||
|
||||
|
||||
// determine if test case has finished
|
||||
var finished bool
|
||||
var line int
|
||||
|
@ -184,6 +239,12 @@ func (f *cukefmt) Defined(step *gherkin.Step, def *StepDef) {
|
|||
f.curElement.Steps = append(f.curElement.Steps, cukeStep{})
|
||||
f.curStep = &f.curElement.Steps[len(f.curElement.Steps) - 1]
|
||||
|
||||
if def != nil {
|
||||
if def.args != nil {
|
||||
fmt.Fprintf(f.out, "Argument: %v\n", def.args)
|
||||
}
|
||||
}
|
||||
|
||||
f.curStep.Name = step.Text
|
||||
f.curStep.Line = step.Location.Line
|
||||
f.curStep.Keyword = step.Keyword
|
||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче