Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Moved the parser code to a new internal pkg #329

Merged
merged 1 commit into from
Jul 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions parser.go → internal/parser/parser.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package godog
package parser

import (
"bytes"
Expand All @@ -19,7 +19,8 @@ import (

var pathLineRe = regexp.MustCompile(`:([\d]+)$`)

func extractFeaturePathLine(p string) (string, int) {
// ExtractFeaturePathLine ...
func ExtractFeaturePathLine(p string) (string, int) {
line := -1
retPath := p
if m := pathLineRe.FindStringSubmatch(p); len(m) > 0 {
Expand Down Expand Up @@ -80,7 +81,7 @@ func parseFeatureDir(dir string, newIDFunc func() string) ([]*models.Feature, er
func parsePath(path string) ([]*models.Feature, error) {
var features []*models.Feature

path, line := extractFeaturePathLine(path)
path, line := ExtractFeaturePathLine(path)

fi, err := os.Stat(path)
if err != nil {
Expand Down Expand Up @@ -112,7 +113,8 @@ func parsePath(path string) ([]*models.Feature, error) {
return append(features, ft), nil
}

func parseFeatures(filter string, paths []string) ([]*models.Feature, error) {
// ParseFeatures ...
func ParseFeatures(filter string, paths []string) ([]*models.Feature, error) {
var order int

featureIdxs := make(map[string]int)
Expand Down
34 changes: 34 additions & 0 deletions internal/parser/parser_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package parser_test

import (
"testing"

"github.com/stretchr/testify/assert"

"github.com/cucumber/godog/internal/parser"
)

func Test_FeatureFilePathParser(t *testing.T) {
type Case struct {
input string
path string
line int
}

cases := []Case{
{"/home/test.feature", "/home/test.feature", -1},
{"/home/test.feature:21", "/home/test.feature", 21},
{"test.feature", "test.feature", -1},
{"test.feature:2", "test.feature", 2},
{"", "", -1},
{"/c:/home/test.feature", "/c:/home/test.feature", -1},
{"/c:/home/test.feature:3", "/c:/home/test.feature", 3},
{"D:\\home\\test.feature:3", "D:\\home\\test.feature", 3},
}

for _, c := range cases {
p, ln := parser.ExtractFeaturePathLine(c.input)
assert.Equal(t, p, c.path)
assert.Equal(t, ln, c.line)
}
}
3 changes: 2 additions & 1 deletion run.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

"github.com/cucumber/godog/colors"
"github.com/cucumber/godog/internal/models"
"github.com/cucumber/godog/internal/parser"
"github.com/cucumber/godog/internal/storage"
"github.com/cucumber/godog/internal/utils"
)
Expand Down Expand Up @@ -180,7 +181,7 @@ func runWithOptions(suiteName string, runner runner, opt Options) int {
runner.fmt = formatter(suiteName, output)

var err error
if runner.features, err = parseFeatures(opt.Tags, opt.Paths); err != nil {
if runner.features, err = parser.ParseFeatures(opt.Tags, opt.Paths); err != nil {
fmt.Fprintln(os.Stderr, err)
return exitOptionError
}
Expand Down
26 changes: 0 additions & 26 deletions run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,32 +256,6 @@ func bufErrorPipe(t *testing.T) (io.ReadCloser, func()) {
}
}

func Test_FeatureFilePathParser(t *testing.T) {

type Case struct {
input string
path string
line int
}

cases := []Case{
{"/home/test.feature", "/home/test.feature", -1},
{"/home/test.feature:21", "/home/test.feature", 21},
{"test.feature", "test.feature", -1},
{"test.feature:2", "test.feature", 2},
{"", "", -1},
{"/c:/home/test.feature", "/c:/home/test.feature", -1},
{"/c:/home/test.feature:3", "/c:/home/test.feature", 3},
{"D:\\home\\test.feature:3", "D:\\home\\test.feature", 3},
}

for _, c := range cases {
p, ln := extractFeaturePathLine(c.input)
assert.Equal(t, p, c.path)
assert.Equal(t, ln, c.line)
}
}

func Test_RandomizeRun(t *testing.T) {
const noRandomFlag = 0
const createRandomSeedFlag = -1
Expand Down
3 changes: 2 additions & 1 deletion suite_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/cucumber/godog/colors"
"github.com/cucumber/godog/internal/formatters"
"github.com/cucumber/godog/internal/models"
"github.com/cucumber/godog/internal/parser"
"github.com/cucumber/godog/internal/storage"
"github.com/cucumber/godog/internal/tags"
"github.com/cucumber/godog/internal/utils"
Expand Down Expand Up @@ -418,7 +419,7 @@ func (tc *godogFeaturesScenario) featurePath(path string) error {
}

func (tc *godogFeaturesScenario) parseFeatures() error {
fts, err := parseFeatures("", tc.paths)
fts, err := parser.ParseFeatures("", tc.paths)
if err != nil {
return err
}
Expand Down