Skip to content

Commit

Permalink
Merge pull request #307 from cucumber/broke-up-some-files
Browse files Browse the repository at this point in the history
Broke out some code from massive files into new files
  • Loading branch information
lonnblad authored Jun 13, 2020
2 parents a57f082 + 25b1915 commit 849e8e4
Show file tree
Hide file tree
Showing 9 changed files with 642 additions and 605 deletions.
96 changes: 96 additions & 0 deletions feature.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package godog

import (
"time"

"github.com/cucumber/messages-go/v10"
)

type feature struct {
*messages.GherkinDocument
pickles []*messages.Pickle

time time.Time
content []byte
order int
}

type sortFeaturesByName []*feature

func (s sortFeaturesByName) Len() int { return len(s) }
func (s sortFeaturesByName) Less(i, j int) bool { return s[i].Feature.Name < s[j].Feature.Name }
func (s sortFeaturesByName) Swap(i, j int) { s[i], s[j] = s[j], s[i] }

type sortFeaturesByOrder []*feature

func (s sortFeaturesByOrder) Len() int { return len(s) }
func (s sortFeaturesByOrder) Less(i, j int) bool { return s[i].order < s[j].order }
func (s sortFeaturesByOrder) Swap(i, j int) { s[i], s[j] = s[j], s[i] }

func (f feature) findScenario(astScenarioID string) *messages.GherkinDocument_Feature_Scenario {
for _, child := range f.GherkinDocument.Feature.Children {
if sc := child.GetScenario(); sc != nil && sc.Id == astScenarioID {
return sc
}
}

return nil
}

func (f feature) findBackground(astScenarioID string) *messages.GherkinDocument_Feature_Background {
var bg *messages.GherkinDocument_Feature_Background

for _, child := range f.GherkinDocument.Feature.Children {
if tmp := child.GetBackground(); tmp != nil {
bg = tmp
}

if sc := child.GetScenario(); sc != nil && sc.Id == astScenarioID {
return bg
}
}

return nil
}

func (f feature) findExample(exampleAstID string) (*messages.GherkinDocument_Feature_Scenario_Examples, *messages.GherkinDocument_Feature_TableRow) {
for _, child := range f.GherkinDocument.Feature.Children {
if sc := child.GetScenario(); sc != nil {
for _, example := range sc.Examples {
for _, row := range example.TableBody {
if row.Id == exampleAstID {
return example, row
}
}
}
}
}

return nil, nil
}

func (f feature) findStep(astStepID string) *messages.GherkinDocument_Feature_Step {
for _, child := range f.GherkinDocument.Feature.Children {
if sc := child.GetScenario(); sc != nil {
for _, step := range sc.GetSteps() {
if step.Id == astStepID {
return step
}
}
}

if bg := child.GetBackground(); bg != nil {
for _, step := range bg.GetSteps() {
if step.Id == astStepID {
return step
}
}
}
}

return nil
}

func (f feature) startedAt() time.Time {
return f.time
}
Loading

0 comments on commit 849e8e4

Please sign in to comment.