aboutsummaryrefslogtreecommitdiff
path: root/internal/fulltext/bleve_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/fulltext/bleve_test.go')
-rw-r--r--internal/fulltext/bleve_test.go46
1 files changed, 30 insertions, 16 deletions
diff --git a/internal/fulltext/bleve_test.go b/internal/fulltext/bleve_test.go
index bd8289d5..a77c2393 100644
--- a/internal/fulltext/bleve_test.go
+++ b/internal/fulltext/bleve_test.go
@@ -160,14 +160,16 @@ func TestSearch(t *testing.T) {
roomIndex []int
}
tests := []struct {
- name string
- args args
- wantCount int
- wantErr bool
+ name string
+ args args
+ wantCount int
+ wantErr bool
+ wantHighlights []string
}{
{
- name: "Can search for many results in one room",
- wantCount: 16,
+ name: "Can search for many results in one room",
+ wantCount: 16,
+ wantHighlights: []string{"lorem"},
args: args{
term: "lorem",
roomIndex: []int{0},
@@ -175,8 +177,9 @@ func TestSearch(t *testing.T) {
},
},
{
- name: "Can search for one result in one room",
- wantCount: 1,
+ name: "Can search for one result in one room",
+ wantCount: 1,
+ wantHighlights: []string{"lorem"},
args: args{
term: "lorem",
roomIndex: []int{16},
@@ -184,8 +187,9 @@ func TestSearch(t *testing.T) {
},
},
{
- name: "Can search for many results in multiple rooms",
- wantCount: 17,
+ name: "Can search for many results in multiple rooms",
+ wantCount: 17,
+ wantHighlights: []string{"lorem"},
args: args{
term: "lorem",
roomIndex: []int{0, 16},
@@ -193,8 +197,9 @@ func TestSearch(t *testing.T) {
},
},
{
- name: "Can search for many results in all rooms, reversed",
- wantCount: 30,
+ name: "Can search for many results in all rooms, reversed",
+ wantCount: 30,
+ wantHighlights: []string{"lorem"},
args: args{
term: "lorem",
limit: 30,
@@ -202,8 +207,9 @@ func TestSearch(t *testing.T) {
},
},
{
- name: "Can search for specific search room name",
- wantCount: 1,
+ name: "Can search for specific search room name",
+ wantCount: 1,
+ wantHighlights: []string{"testing"},
args: args{
term: "testing",
roomIndex: []int{},
@@ -212,8 +218,9 @@ func TestSearch(t *testing.T) {
},
},
{
- name: "Can search for specific search room topic",
- wantCount: 1,
+ name: "Can search for specific search room topic",
+ wantCount: 1,
+ wantHighlights: []string{"fulltext"},
args: args{
term: "fulltext",
roomIndex: []int{},
@@ -222,6 +229,7 @@ func TestSearch(t *testing.T) {
},
},
}
+
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
f, ctx := mustOpenIndex(t, "")
@@ -238,6 +246,12 @@ func TestSearch(t *testing.T) {
t.Errorf("Search() error = %v, wantErr %v", err, tt.wantErr)
return
}
+
+ highlights := f.GetHighlights(got)
+ if !reflect.DeepEqual(highlights, tt.wantHighlights) {
+ t.Errorf("Search() got highligts = %v, want %v", highlights, tt.wantHighlights)
+ }
+
if !reflect.DeepEqual(len(got.Hits), tt.wantCount) {
t.Errorf("Search() got = %v, want %v", len(got.Hits), tt.wantCount)
}