This repository has been archived by the owner on Mar 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautocompletions_test.go
86 lines (81 loc) · 1.72 KB
/
autocompletions_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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package main
import (
"fmt"
"reflect"
"regexp"
"testing"
)
func TestNewHaystack(t *testing.T) {
tests := []struct {
input []string
want *haystack
}{
{input: []string{"hello", "world"}, want: &haystack{
search: []byte("helloworld"),
domain: []byte("helloworld"),
spans: []span{
{start: 0, end: 5},
{start: 5, end: 10},
},
}},
}
for _, tt := range tests {
t.Run(fmt.Sprintf("%v", tt.input), func(t *testing.T) {
got := NewHaystack(tt.input)
if !reflect.DeepEqual(tt.want, got) {
t.Errorf("want [%+v], got [%+v]", tt.want, got)
}
})
}
}
func TestHaystackFindAll(t *testing.T) {
tests := []struct {
domain []string
needle string
want map[string]struct{}
}{
{
domain: []string{"hello", "world"},
needle: "wor",
want: map[string]struct{}{
"world": {},
},
},
{
domain: []string{"The Official Go Blog", "Kubernetes Feed"},
needle: "go",
want: map[string]struct{}{
"The Official Go Blog": {},
},
},
{
domain: []string{"The Official Go Blog", "Go Weekly"},
needle: "go",
want: map[string]struct{}{
"The Official Go Blog": {},
"Go Weekly": {},
},
},
{
domain: []string{"The Official Go Blog", "Go Weekly"},
needle: "o",
want: map[string]struct{}{
"The Official Go Blog": {},
"Go Weekly": {},
},
},
}
for _, tt := range tests {
t.Run(fmt.Sprintf("find %s in %v", tt.needle, tt.domain), func(t *testing.T) {
h := NewHaystack(tt.domain)
gotList := h.FindAll(regexp.MustCompile(tt.needle))
got := make(map[string]struct{})
for _, g := range gotList {
got[g] = struct{}{}
}
if !reflect.DeepEqual(tt.want, got) {
t.Errorf("want %v, got %v", tt.want, got)
}
})
}
}