@@ -27,11 +27,12 @@ import (
27
27
)
28
28
29
29
type scoreCase struct {
30
- fileName string
31
- content []byte
32
- query query.Q
33
- language string
34
- wantScore float64
30
+ fileName string
31
+ content []byte
32
+ query query.Q
33
+ language string
34
+ wantScore float64
35
+ wantBestLineMatch uint32
35
36
}
36
37
37
38
func TestFileNameMatch (t * testing.T ) {
@@ -79,6 +80,8 @@ func TestBM25(t *testing.T) {
79
80
language : "Java" ,
80
81
// bm25-score: 0.58 <- sum-termFrequencyScore: 14.00, length-ratio: 1.00
81
82
wantScore : 0.58 ,
83
+ // line 5: private final int exampleField;
84
+ wantBestLineMatch : 5 ,
82
85
}, {
83
86
// Matches only on content
84
87
fileName : "example.java" ,
@@ -91,6 +94,8 @@ func TestBM25(t *testing.T) {
91
94
language : "Java" ,
92
95
// bm25-score: 1.81 <- sum-termFrequencyScore: 116.00, length-ratio: 1.00
93
96
wantScore : 1.81 ,
97
+ // line 3: public class InnerClasses {
98
+ wantBestLineMatch : 3 ,
94
99
},
95
100
{
96
101
// Matches only on filename
@@ -130,6 +135,8 @@ func TestJava(t *testing.T) {
130
135
language : "Java" ,
131
136
// 5500 (partial symbol at boundary) + 1000 (Java class) + 50 (partial word)
132
137
wantScore : 6550 ,
138
+ // line 37: public class InnerClass implements InnerInterface<Integer, Integer> {
139
+ wantBestLineMatch : 37 ,
133
140
},
134
141
{
135
142
fileName : "example.java" ,
@@ -138,6 +145,8 @@ func TestJava(t *testing.T) {
138
145
language : "Java" ,
139
146
// 5500 (partial symbol at boundary) + 1000 (Java class) + 500 (word)
140
147
wantScore : 7000 ,
148
+ // line 32: public static class InnerStaticClass {
149
+ wantBestLineMatch : 32 ,
141
150
},
142
151
{
143
152
fileName : "example.java" ,
@@ -146,6 +155,8 @@ func TestJava(t *testing.T) {
146
155
language : "Java" ,
147
156
// 7000 (symbol) + 900 (Java enum) + 500 (word)
148
157
wantScore : 8400 ,
158
+ // line 16: public enum InnerEnum {
159
+ wantBestLineMatch : 16 ,
149
160
},
150
161
{
151
162
fileName : "example.java" ,
@@ -154,6 +165,8 @@ func TestJava(t *testing.T) {
154
165
language : "Java" ,
155
166
// 7000 (symbol) + 800 (Java interface) + 500 (word)
156
167
wantScore : 8300 ,
168
+ // line 22: public interface InnerInterface<A, B> {
169
+ wantBestLineMatch : 22 ,
157
170
},
158
171
{
159
172
fileName : "example.java" ,
@@ -162,6 +175,8 @@ func TestJava(t *testing.T) {
162
175
language : "Java" ,
163
176
// 7000 (symbol) + 700 (Java method) + 500 (word)
164
177
wantScore : 8200 ,
178
+ // line 44: public void innerMethod() {
179
+ wantBestLineMatch : 44 ,
165
180
},
166
181
{
167
182
fileName : "example.java" ,
@@ -170,6 +185,8 @@ func TestJava(t *testing.T) {
170
185
language : "Java" ,
171
186
// 7000 (symbol) + 600 (Java field) + 500 (word)
172
187
wantScore : 8100 ,
188
+ // line 38: private final int field;
189
+ wantBestLineMatch : 38 ,
173
190
},
174
191
{
175
192
fileName : "example.java" ,
@@ -178,6 +195,8 @@ func TestJava(t *testing.T) {
178
195
language : "Java" ,
179
196
// 7000 (symbol) + 500 (Java enum constant) + 500 (word)
180
197
wantScore : 8000 ,
198
+ // line 18: B,
199
+ wantBestLineMatch : 18 ,
181
200
},
182
201
// 2 Atoms (1x content and 1x filename)
183
202
{
@@ -187,6 +206,8 @@ func TestJava(t *testing.T) {
187
206
language : "Java" ,
188
207
// 5500 (edge symbol) + 600 (Java field) + 500 (word) + 200 (atom)
189
208
wantScore : 6800 ,
209
+ // line 5: private final int exampleField;
210
+ wantBestLineMatch : 5 ,
190
211
},
191
212
// 3 Atoms (2x content, 1x filename)
192
213
{
@@ -199,6 +220,8 @@ func TestJava(t *testing.T) {
199
220
language : "Java" ,
200
221
// 7000 (symbol) + 700 (Java method) + 500 (word) + 266.67 (atom)
201
222
wantScore : 8466 ,
223
+ // line 54: private static <A, B> B runInnerInterface(InnerInterface<A, B> fn, A a) {
224
+ wantBestLineMatch : 54 ,
202
225
},
203
226
// 4 Atoms (4x content)
204
227
{
@@ -213,6 +236,8 @@ func TestJava(t *testing.T) {
213
236
language : "Java" ,
214
237
// 7000 (symbol) + 900 (Java enum) + 500 (word) + 300 (atom)
215
238
wantScore : 8700 ,
239
+ // line 16: public enum InnerEnum {
240
+ wantBestLineMatch : 16 ,
216
241
},
217
242
{
218
243
fileName : "example.java" ,
@@ -221,6 +246,8 @@ func TestJava(t *testing.T) {
221
246
language : "Java" ,
222
247
// 4000 (overlap Symbol) + 700 (Java method) + 50 (partial word)
223
248
wantScore : 4750 ,
249
+ // line 54: private static <A, B> B runInnerInterface(InnerInterface<A, B> fn, A a) {
250
+ wantBestLineMatch : 54 ,
224
251
},
225
252
{
226
253
fileName : "example.java" ,
@@ -229,6 +256,8 @@ func TestJava(t *testing.T) {
229
256
language : "Java" ,
230
257
// 7000 (Symbol) + 900 (Java enum) + 500 (word)
231
258
wantScore : 8400 ,
259
+ // line 16: public enum InnerEnum {
260
+ wantBestLineMatch : 16 ,
232
261
},
233
262
{
234
263
fileName : "example.java" ,
@@ -237,6 +266,8 @@ func TestJava(t *testing.T) {
237
266
language : "Java" ,
238
267
// 5500 (edge Symbol) + 900 (Java enum) + 500 (word)
239
268
wantScore : 6900 ,
269
+ // line 16: public enum InnerEnum {
270
+ wantBestLineMatch : 16 ,
240
271
},
241
272
{
242
273
fileName : "example.java" ,
@@ -245,6 +276,8 @@ func TestJava(t *testing.T) {
245
276
language : "Java" ,
246
277
// 4000 (overlap Symbol) + 900 (Java enum) + 500 (word)
247
278
wantScore : 5400 ,
279
+ // line 16: public enum InnerEnum {
280
+ wantBestLineMatch : 16 ,
248
281
},
249
282
}
250
283
@@ -640,6 +673,16 @@ func checkScoring(t *testing.T, c scoreCase, useBM25 bool, parserType ctags.CTag
640
673
t .Fatalf ("score: want %f, got %f\n debug: %s\n debugscore: %s" , c .wantScore , got , srs .Files [0 ].Debug , srs .Files [0 ].ChunkMatches [0 ].DebugScore )
641
674
}
642
675
676
+ if c .wantBestLineMatch != 0 {
677
+ if len (srs .Files [0 ].ChunkMatches ) == 0 {
678
+ t .Fatalf ("want BestLineMatch %d, but no chunk matches were returned" , c .wantBestLineMatch )
679
+ }
680
+ chunkMatch := srs .Files [0 ].ChunkMatches [0 ]
681
+ if chunkMatch .BestLineMatch != c .wantBestLineMatch {
682
+ t .Fatalf ("want BestLineMatch %d, got %d" , c .wantBestLineMatch , chunkMatch .BestLineMatch )
683
+ }
684
+ }
685
+
643
686
if got := srs .Files [0 ].Language ; got != c .language {
644
687
t .Fatalf ("want %s, got %s" , c .language , got )
645
688
}
0 commit comments