Broke out the tag filtering logic to its own file

Этот коммит содержится в:
Fredrik Lönnblad 2020-06-07 09:10:56 +02:00
родитель 0b6b3a7b06
коммит c5a0a58123
3 изменённых файлов: 44 добавлений и 32 удалений

Просмотреть файл

@ -812,33 +812,3 @@ func applyTagFilter(tags string, ft *feature) {
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 Обычный файл
Просмотреть файл

@ -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"
)
func assertNotMatchesTagFilter(tags []*messages.Pickle_PickleTag, filter string, t *testing.T) {
func assertNotMatchesTagFilter(tags []*tag, filter string, t *testing.T) {
if matchesTags(filter, tags) {
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) {
t.Errorf(`expected tags: %v to match tag filter "%s", but it did not`, tags, filter)
}