Broke out the tag filtering logic to its own file
Этот коммит содержится в:
родитель
0b6b3a7b06
коммит
c5a0a58123
3 изменённых файлов: 44 добавлений и 32 удалений
30
suite.go
30
suite.go
|
@ -812,33 +812,3 @@ func applyTagFilter(tags string, ft *feature) {
|
||||||
|
|
||||||
ft.pickles = pickles
|
ft.pickles = pickles
|
||||||
}
|
}
|
||||||
|
|
||||||
// based on http://behat.readthedocs.org/en/v2.5/guides/6.cli.html#gherkin-filters
|
|
||||||
func matchesTags(filter string, tags []*messages.Pickle_PickleTag) (ok bool) {
|
|
||||||
ok = true
|
|
||||||
for _, andTags := range strings.Split(filter, "&&") {
|
|
||||||
var okComma bool
|
|
||||||
for _, tag := range strings.Split(andTags, ",") {
|
|
||||||
tag = strings.Replace(strings.TrimSpace(tag), "@", "", -1)
|
|
||||||
if tag[0] == '~' {
|
|
||||||
tag = tag[1:]
|
|
||||||
okComma = !hasTag(tags, tag) || okComma
|
|
||||||
} else {
|
|
||||||
okComma = hasTag(tags, tag) || okComma
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ok = ok && okComma
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func hasTag(tags []*messages.Pickle_PickleTag, tag string) bool {
|
|
||||||
for _, t := range tags {
|
|
||||||
tName := strings.Replace(t.Name, "@", "", -1)
|
|
||||||
|
|
||||||
if tName == tag {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
42
tag_filter.go
Обычный файл
42
tag_filter.go
Обычный файл
|
@ -0,0 +1,42 @@
|
||||||
|
package godog
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/cucumber/messages-go/v10"
|
||||||
|
)
|
||||||
|
|
||||||
|
// based on http://behat.readthedocs.org/en/v2.5/guides/6.cli.html#gherkin-filters
|
||||||
|
func matchesTags(filter string, tags []*messages.Pickle_PickleTag) (ok bool) {
|
||||||
|
ok = true
|
||||||
|
|
||||||
|
for _, andTags := range strings.Split(filter, "&&") {
|
||||||
|
var okComma bool
|
||||||
|
|
||||||
|
for _, tag := range strings.Split(andTags, ",") {
|
||||||
|
tag = strings.Replace(strings.TrimSpace(tag), "@", "", -1)
|
||||||
|
|
||||||
|
okComma = hasTag(tags, tag) || okComma
|
||||||
|
if tag[0] == '~' {
|
||||||
|
tag = tag[1:]
|
||||||
|
okComma = !hasTag(tags, tag) || okComma
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ok = ok && okComma
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func hasTag(tags []*messages.Pickle_PickleTag, tag string) bool {
|
||||||
|
for _, t := range tags {
|
||||||
|
tName := strings.Replace(t.Name, "@", "", -1)
|
||||||
|
|
||||||
|
if tName == tag {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
|
@ -6,13 +6,13 @@ import (
|
||||||
"github.com/cucumber/messages-go/v10"
|
"github.com/cucumber/messages-go/v10"
|
||||||
)
|
)
|
||||||
|
|
||||||
func assertNotMatchesTagFilter(tags []*messages.Pickle_PickleTag, filter string, t *testing.T) {
|
func assertNotMatchesTagFilter(tags []*tag, filter string, t *testing.T) {
|
||||||
if matchesTags(filter, tags) {
|
if matchesTags(filter, tags) {
|
||||||
t.Errorf(`expected tags: %v not to match tag filter "%s", but it did`, tags, filter)
|
t.Errorf(`expected tags: %v not to match tag filter "%s", but it did`, tags, filter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func assertMatchesTagFilter(tags []*messages.Pickle_PickleTag, filter string, t *testing.T) {
|
func assertMatchesTagFilter(tags []*tag, filter string, t *testing.T) {
|
||||||
if !matchesTags(filter, tags) {
|
if !matchesTags(filter, tags) {
|
||||||
t.Errorf(`expected tags: %v to match tag filter "%s", but it did not`, tags, filter)
|
t.Errorf(`expected tags: %v to match tag filter "%s", but it did not`, tags, filter)
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче