forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathngram_test.go
61 lines (55 loc) · 1.41 KB
/
ngram_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
package searchV2
import (
"reflect"
"testing"
"github.com/stretchr/testify/require"
)
func Test_punctuationCharFilter_Filter(t1 *testing.T) {
type args struct {
input []byte
}
tests := []struct {
name string
args args
want []byte
}{
{
name: "1",
args: args{
input: []byte("x-Rays"),
},
want: []byte("x Rays"),
},
{
name: "2",
args: args{
input: []byte("x.Rays"),
},
want: []byte("x Rays"),
},
{
name: "3",
args: args{
input: []byte("[x,Rays]"),
},
want: []byte(" x Rays "),
},
}
for _, tt := range tests {
t1.Run(tt.name, func(t1 *testing.T) {
t := &punctuationCharFilter{}
if got := t.Filter(tt.args.input); !reflect.DeepEqual(got, tt.want) {
t1.Errorf("Filter() = %v, want %v", string(got), string(tt.want))
}
})
}
}
func TestNgramIndexAnalyzer(t *testing.T) {
stream := ngramIndexAnalyzer.Analyze([]byte("x-rays.and.xRays, and НемногоКириллицы"))
expectedTerms := []string{"x", "r", "ra", "ray", "rays", "a", "an", "and", "x", "r", "ra", "ray", "rays", "a", "an", "and", "н", "не", "нем", "немн", "немно", "немног", "немного", "к", "ки", "кир", "кири", "кирил", "кирилл", "кирилли"}
actualTerms := make([]string, 0, len(stream))
for _, t := range stream {
actualTerms = append(actualTerms, string(t.Term))
}
require.Equal(t, expectedTerms, actualTerms)
}