diff --git a/parser.go b/internal/parser/parser.go similarity index 93% rename from parser.go rename to internal/parser/parser.go index 3ff82e2..40c2895 100644 --- a/parser.go +++ b/internal/parser/parser.go @@ -1,4 +1,4 @@ -package godog +package parser import ( "bytes" @@ -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 { @@ -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 { @@ -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) diff --git a/internal/parser/parser_test.go b/internal/parser/parser_test.go new file mode 100644 index 0000000..b7f2f7c --- /dev/null +++ b/internal/parser/parser_test.go @@ -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) + } +} diff --git a/run.go b/run.go index 5e73721..de2a0c5 100644 --- a/run.go +++ b/run.go @@ -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" ) @@ -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 } diff --git a/run_test.go b/run_test.go index 94a6a80..8e9a1b9 100644 --- a/run_test.go +++ b/run_test.go @@ -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 diff --git a/suite_context_test.go b/suite_context_test.go index 83eba78..eacad60 100644 --- a/suite_context_test.go +++ b/suite_context_test.go @@ -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" @@ -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 }