Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
153 lines
2.2 KiB
Go
153 lines
2.2 KiB
Go
package slice
|
|
|
|
import (
|
|
"github.com/stretchr/testify/assert"
|
|
"testing"
|
|
)
|
|
|
|
func TestIntersectStrings(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
a []string
|
|
b []string
|
|
c []string
|
|
}{
|
|
{
|
|
"empty",
|
|
[]string{},
|
|
[]string{},
|
|
[]string{},
|
|
},
|
|
{
|
|
"none",
|
|
[]string{"a"},
|
|
[]string{"b"},
|
|
[]string{},
|
|
},
|
|
{
|
|
"some",
|
|
[]string{"a", "b"},
|
|
[]string{"a", "c"},
|
|
[]string{"a"},
|
|
},
|
|
{
|
|
"all",
|
|
[]string{"a", "b"},
|
|
[]string{"a", "b"},
|
|
[]string{"a", "b"},
|
|
},
|
|
{
|
|
"dups",
|
|
[]string{"a", "b", "b", "b"},
|
|
[]string{"a", "b"},
|
|
[]string{"a", "b"},
|
|
},
|
|
}
|
|
for _, c := range cases {
|
|
t.Run(c.name, func(t *testing.T) {
|
|
assert.EqualValues(t, IntersectStrings(c.a, c.b), c.c)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestToStringBoolMap(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
i []string
|
|
o map[string]bool
|
|
}{
|
|
{
|
|
"empty",
|
|
[]string{},
|
|
map[string]bool{},
|
|
},
|
|
{
|
|
"some",
|
|
[]string{"a"},
|
|
map[string]bool{"a": true},
|
|
},
|
|
{
|
|
"many",
|
|
[]string{"a", "b", "c", "c", "d"},
|
|
map[string]bool{"a": true, "b": true, "c": true, "d": true},
|
|
},
|
|
}
|
|
for _, c := range cases {
|
|
t.Run(c.name, func(t *testing.T) {
|
|
assert.EqualValues(t, ToStringBoolMap(c.i), c.o)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestHasString(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
ss []string
|
|
s string
|
|
o bool
|
|
}{
|
|
{
|
|
"empty",
|
|
[]string{},
|
|
"a",
|
|
false,
|
|
},
|
|
{
|
|
"has not",
|
|
[]string{"a"},
|
|
"b",
|
|
false,
|
|
},
|
|
{
|
|
"has",
|
|
[]string{"a"},
|
|
"a",
|
|
true,
|
|
},
|
|
}
|
|
for _, c := range cases {
|
|
t.Run(c.name, func(t *testing.T) {
|
|
assert.EqualValues(t, HasString(c.ss, c.s), c.o)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestPluckStrung(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
ss []string
|
|
ff []string
|
|
o []string
|
|
}{
|
|
{
|
|
"empty",
|
|
[]string{},
|
|
[]string{},
|
|
[]string{},
|
|
},
|
|
{
|
|
"some",
|
|
[]string{"a", "b"},
|
|
[]string{"a"},
|
|
[]string{"b"},
|
|
},
|
|
{
|
|
"all",
|
|
[]string{"a", "b"},
|
|
[]string{"a", "b"},
|
|
[]string{},
|
|
},
|
|
{
|
|
"not there",
|
|
[]string{"a"},
|
|
[]string{"b"},
|
|
[]string{"a"},
|
|
},
|
|
}
|
|
for _, c := range cases {
|
|
t.Run(c.name, func(t *testing.T) {
|
|
assert.EqualValues(t, PluckString(c.ss, c.ff...), c.o)
|
|
})
|
|
}
|
|
}
|