[repo-assist] test(query): cover multi-term search matching (#2938)
test(query): cover multi-term search matching Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
1 parent
63f162762b
commit
caab26bfda
1 file changed
+52
@@ -0,0 +1,52 @@
|
||||
//go:build !integration
|
||||
|
||||
package query
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/Jguer/aur"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestMatchesSearch(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
pkg := &aur.Pkg{
|
||||
Name: "Linux",
|
||||
Description: "The Linux kernel and modules",
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
terms []string
|
||||
want bool
|
||||
}{
|
||||
{
|
||||
name: "all terms match name or description",
|
||||
terms: []string{"linux", "MODULES"},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "missing term rejects package",
|
||||
terms: []string{"linux", "wayland"},
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
name: "symbol term does not bypass text matching",
|
||||
terms: []string{"wayland", "✓"},
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
name: "symbol term is ignored alongside matching text",
|
||||
terms: []string{"kernel", "✓"},
|
||||
want: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
assert.Equal(t, test.want, matchesSearch(pkg, test.terms))
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user