Merge pull request #329 from cucumber/internal-parser-pkg
Moved the parser code to a new internal pkg
Этот коммит содержится в:
коммит
eb6779c4ac
5 изменённых файлов: 44 добавлений и 32 удалений
|
@ -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)
|
34
internal/parser/parser_test.go
Обычный файл
34
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)
|
||||
}
|
||||
}
|
3
run.go
3
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
|
||||
}
|
||||
|
|
26
run_test.go
26
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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче