3 Star 0 Fork 1

Gitee 极速下载/ntt

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/nokia/ntt
克隆/下载
basket_test.go 4.63 KB
一键复制 编辑 原始数据 按行查看 历史
package main
import (
"os"
"strings"
"testing"
"github.com/nokia/ntt/ttcn3/doc"
)
func TestBasketMatch(t *testing.T) {
tests := []struct {
basket string
name string
tags []string
want bool
}{
{basket: "", name: "", want: true},
{basket: "", name: "", tags: []string{"@wip"}, want: true},
{basket: "", name: "foo", want: true},
{basket: "", name: "foo", tags: []string{"@wip"}, want: true},
{basket: "-r fo.", name: "foobar", want: true},
{basket: "-r foo|bar", name: "bar", want: true},
{basket: "-r foo", name: "bar", want: false},
{basket: "-x fo.", name: "foo", want: false},
{basket: "-r foo -r bar", name: "foo", want: false},
{basket: "-r foo -r bar", name: "foobar", want: true},
{basket: "-r foo -x bar", name: "foobar", want: false},
{basket: "-x foo -r bar", name: "foobar", want: false},
{basket: "-x foo|bar", name: "bar", want: false},
{basket: "-x foo", name: "bar", want: true},
{basket: "-X @foo|@bar", want: true},
{basket: "-R foo", tags: []string{"@foo bar"}, want: true},
{basket: "-R foo:bar", tags: []string{"@foo bar"}, want: true},
{basket: "-R :bar", tags: []string{"@foo bar"}, want: true},
{basket: "-R :bar", tags: []string{"@foo", "@bar"}, want: false},
{basket: "-R bar", tags: []string{"@foo bar"}, want: false},
{basket: "-R bar", tags: []string{"@foo", "@bar"}, want: true},
{basket: "-R foo|bar", tags: []string{"@foo", "@bar"}, want: true},
{basket: "-R foo -R bar", tags: []string{"@foo", "@bar"}, want: true},
{basket: "-R foo -R wip", tags: []string{"@foo", "@bar"}, want: false},
{basket: "-R foo -R bar|wip", tags: []string{"@foo", "@bar"}, want: true},
{basket: "-R foo -X bar", tags: []string{"@foo", "@bar"}, want: false},
{basket: "-X bar -R foo", tags: []string{"@foo", "@bar"}, want: false},
{basket: "-R foo -X wip", tags: []string{"@foo", "@bar"}, want: true},
{basket: "-R foo -X foo", tags: []string{"@foo", "@bar"}, want: false},
{basket: "-R foo|wip -R bar", tags: []string{"@foo", "@bar"}, want: true},
{basket: "-r foo -X @wip", name: "foo", tags: []string{"@foo"}, want: true},
{basket: "-r foo -X @foo", name: "foo", tags: []string{"@foo"}, want: false},
{basket: "-x foo -X @foo", name: "foo", tags: []string{"@foo"}, want: false},
{basket: "-x foo -X @wip", name: "foo", tags: []string{"@foo"}, want: false},
{basket: "-x foo -R @foo", name: "foo", tags: []string{"@foo"}, want: false},
}
for _, tt := range tests {
b, err := NewBasket("testBasket", strings.Fields(tt.basket)...)
if err != nil {
t.Fatal(err)
}
actual := b.Match(tt.name, doc.FindAllTags(strings.Join(tt.tags, "\n")))
if actual != tt.want {
t.Errorf("Basket(%q).Match(%q, %q) = %v, want %v", tt.basket, tt.name, tt.tags, actual, tt.want)
}
}
}
func TestSubBaskets(t *testing.T) {
tests := []struct {
basket string
name string
tags []string
want bool
}{
{basket: "-r foo:-r bar", name: "foo", want: true},
{basket: "-r foo:-r bar", name: "bar", want: true},
{basket: "-r foo:-x foo", name: "foo", want: true},
{basket: "-r foo -x bar:-x foo", name: "foobar", want: false},
{basket: "-r foo:-x foo:-x foo", name: "foobar", want: true},
{basket: "-r foo:-x foo:-x bar", name: "foobar", want: true},
}
for _, tt := range tests {
b, err := NewBasket("testBasket")
if err != nil {
t.Fatal(err)
}
for _, s := range strings.Split(tt.basket, ":") {
sb, err := NewBasket("subBasket", strings.Fields(s)...)
if err != nil {
t.Fatal(err)
}
b.Baskets = append(b.Baskets, sb)
}
actual := b.Match(tt.name, doc.FindAllTags(strings.Join(tt.tags, "\n")))
if actual != tt.want {
t.Errorf("Basket(%q).Match(%q, %q) = %v, want %v", tt.basket, tt.name, tt.tags, actual, tt.want)
}
}
}
func TestLoadFromEnv(t *testing.T) {
os.Setenv("TEST_BASKET", "stable:wip")
os.Setenv("TEST_BASKET_stable", "-X @wip|@flaky")
defer func() {
os.Unsetenv("TEST_BASKET")
os.Unsetenv("TEST_BASKET_stable")
}()
b, err := NewBasket("testBasket", "-r", "foo")
if err != nil {
t.Fatal(err)
}
b.LoadFromEnvOrConfig(nil, "TEST_BASKET")
test := []struct {
name string
tags []string
want bool
}{
{name: "foo", want: true},
{name: "foo", tags: []string{"@wip"}, want: true},
{name: "foo", tags: []string{"@flaky"}, want: false},
{name: "bar", want: false},
{name: "bar", tags: []string{"@wip"}, want: false},
{name: "bar", tags: []string{"@false"}, want: false},
}
for _, tt := range test {
t.Run(tt.name, func(t *testing.T) {
actual := b.Match(tt.name, doc.FindAllTags(strings.Join(tt.tags, "\n")))
if actual != tt.want {
t.Errorf("Basket.Match(%q, %q) = %v, want %v", tt.name, tt.tags, actual, tt.want)
}
})
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors/ntt.git
git@gitee.com:mirrors/ntt.git
mirrors
ntt
ntt
master

搜索帮助