Moved the parser code to a new internal pkg
Этот коммит содержится в:
родитель
783f5e40a3
коммит
813312606f
5 изменённых файлов: 44 добавлений и 32 удалений
|
@ -1,4 +1,4 @@
|
||||||
package godog
|
package parser
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
@ -19,7 +19,8 @@ import (
|
||||||
|
|
||||||
var pathLineRe = regexp.MustCompile(`:([\d]+)$`)
|
var pathLineRe = regexp.MustCompile(`:([\d]+)$`)
|
||||||
|
|
||||||
func extractFeaturePathLine(p string) (string, int) {
|
// ExtractFeaturePathLine ...
|
||||||
|
func ExtractFeaturePathLine(p string) (string, int) {
|
||||||
line := -1
|
line := -1
|
||||||
retPath := p
|
retPath := p
|
||||||
if m := pathLineRe.FindStringSubmatch(p); len(m) > 0 {
|
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) {
|
func parsePath(path string) ([]*models.Feature, error) {
|
||||||
var features []*models.Feature
|
var features []*models.Feature
|
||||||
|
|
||||||
path, line := extractFeaturePathLine(path)
|
path, line := ExtractFeaturePathLine(path)
|
||||||
|
|
||||||
fi, err := os.Stat(path)
|
fi, err := os.Stat(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -112,7 +113,8 @@ func parsePath(path string) ([]*models.Feature, error) {
|
||||||
return append(features, ft), nil
|
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
|
var order int
|
||||||
|
|
||||||
featureIdxs := make(map[string]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/colors"
|
||||||
"github.com/cucumber/godog/internal/models"
|
"github.com/cucumber/godog/internal/models"
|
||||||
|
"github.com/cucumber/godog/internal/parser"
|
||||||
"github.com/cucumber/godog/internal/storage"
|
"github.com/cucumber/godog/internal/storage"
|
||||||
"github.com/cucumber/godog/internal/utils"
|
"github.com/cucumber/godog/internal/utils"
|
||||||
)
|
)
|
||||||
|
@ -180,7 +181,7 @@ func runWithOptions(suiteName string, runner runner, opt Options) int {
|
||||||
runner.fmt = formatter(suiteName, output)
|
runner.fmt = formatter(suiteName, output)
|
||||||
|
|
||||||
var err error
|
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)
|
fmt.Fprintln(os.Stderr, err)
|
||||||
return exitOptionError
|
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) {
|
func Test_RandomizeRun(t *testing.T) {
|
||||||
const noRandomFlag = 0
|
const noRandomFlag = 0
|
||||||
const createRandomSeedFlag = -1
|
const createRandomSeedFlag = -1
|
||||||
|
|
|
@ -17,6 +17,7 @@ import (
|
||||||
"github.com/cucumber/godog/colors"
|
"github.com/cucumber/godog/colors"
|
||||||
"github.com/cucumber/godog/internal/formatters"
|
"github.com/cucumber/godog/internal/formatters"
|
||||||
"github.com/cucumber/godog/internal/models"
|
"github.com/cucumber/godog/internal/models"
|
||||||
|
"github.com/cucumber/godog/internal/parser"
|
||||||
"github.com/cucumber/godog/internal/storage"
|
"github.com/cucumber/godog/internal/storage"
|
||||||
"github.com/cucumber/godog/internal/tags"
|
"github.com/cucumber/godog/internal/tags"
|
||||||
"github.com/cucumber/godog/internal/utils"
|
"github.com/cucumber/godog/internal/utils"
|
||||||
|
@ -418,7 +419,7 @@ func (tc *godogFeaturesScenario) featurePath(path string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tc *godogFeaturesScenario) parseFeatures() error {
|
func (tc *godogFeaturesScenario) parseFeatures() error {
|
||||||
fts, err := parseFeatures("", tc.paths)
|
fts, err := parser.ParseFeatures("", tc.paths)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче