-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
fuzz_test.go
32 lines (26 loc) · 1.57 KB
/
fuzz_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package fuzzyfinder_test
import (
"errors"
"testing"
"github.com/gdamore/tcell/v2"
fuzzyfinder "github.com/ktr0731/go-fuzzyfinder"
)
func FuzzPreviewWindow(f *testing.F) {
slice := []string{"foo"}
f.Add("Lorem ipsum dolor sit amet, consectetur adipiscing elit")
f.Add("Sed eget dui libero.\nVivamus tempus, magna nec mollis convallis, ipsum justo tincidunt ligula, ut varius est mi id nisl.\nMorbi commodo turpis risus, nec vehicula leo auctor sit amet.\nUt imperdiet suscipit massa ac vehicula.\nInterdum et malesuada fames ac ante ipsum primis in faucibus.\nPraesent ligula orci, facilisis pulvinar varius eget, iaculis in erat.\nProin pellentesque arcu sed nisl consectetur tristique.\nQuisque tempus blandit dignissim.\nPhasellus dignissim sollicitudin mauris, sed gravida arcu luctus tincidunt.\nNunc rhoncus sed eros vel molestie.\nAenean sodales tortor eu libero rutrum, et lobortis orci scelerisque.\nPraesent sollicitudin, nunc ut consequat commodo, risus velit consectetur nibh, quis pretium nunc elit et erat.")
f.Add("foo\x1b[31;1;44;0;90;105;38;5;12;48;5;226;38;2;10;20;30;48;2;200;100;50mbar")
f.Fuzz(func(t *testing.T, s string) {
finder, term := fuzzyfinder.NewWithMockedTerminal()
events := []tcell.Event{key(input{tcell.KeyEsc, rune(tcell.KeyEsc), tcell.ModNone})}
term.SetEventsV2(events...)
_, err := finder.Find(
slice,
func(int) string { return slice[0] },
fuzzyfinder.WithPreviewWindow(func(i, width, height int) string { return s }),
)
if !errors.Is(err, fuzzyfinder.ErrAbort) {
t.Fatalf("Find must return ErrAbort, but got '%s'", err)
}
})
}