mirror of
https://github.com/jesseduffield/lazygit.git
synced 2024-12-04 10:34:55 +02:00
da3b0bf7c8
switch to other fuzzy package with no dependencies
54 lines
1.1 KiB
Go
54 lines
1.1 KiB
Go
package utils
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
// TestFuzzySearch is a function.
|
|
func TestFuzzySearch(t *testing.T) {
|
|
type scenario struct {
|
|
needle string
|
|
haystack []string
|
|
expected []string
|
|
}
|
|
|
|
scenarios := []scenario{
|
|
{
|
|
needle: "",
|
|
haystack: []string{"test"},
|
|
expected: []string{},
|
|
},
|
|
{
|
|
needle: "test",
|
|
haystack: []string{"test"},
|
|
expected: []string{"test"},
|
|
},
|
|
{
|
|
needle: "o",
|
|
haystack: []string{"a", "o", "e"},
|
|
expected: []string{"o"},
|
|
},
|
|
{
|
|
needle: "mybranch",
|
|
haystack: []string{"my_branch", "mybranch", "branch", "this is my branch"},
|
|
expected: []string{"mybranch", "my_branch", "this is my branch"},
|
|
},
|
|
{
|
|
needle: "test",
|
|
haystack: []string{"not a good match", "this 'test' is a good match", "test"},
|
|
expected: []string{"test", "this 'test' is a good match"},
|
|
},
|
|
{
|
|
needle: "test",
|
|
haystack: []string{"Test"},
|
|
expected: []string{"Test"},
|
|
},
|
|
}
|
|
|
|
for _, s := range scenarios {
|
|
assert.EqualValues(t, s.expected, FuzzySearch(s.needle, s.haystack))
|
|
}
|
|
}
|