Skip to content

Commit 0a9fe08

Browse files
Lubos KoscoLubos Kosco
authored andcommitted
fix junit after #681 + some special case logic fix
1 parent 16803bc commit 0a9fe08

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

src/org/opensolaris/opengrok/search/context/Context.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,9 @@ public boolean getContext(Reader in, Writer out, String urlPrefix,
253253
if (!isDefSearch) {
254254
tokens.printContext();
255255
}
256+
if (isDefSearch && tokens.tags.containsKey(tokens.markedLine)) {
257+
tokens.printContext();
258+
}
256259
matchedLines++;
257260
//out.write("<br> <i>Matched " + token + " maxlines = " + matchedLines + "</i><br>");
258261
break;

test/org/opensolaris/opengrok/search/context/ContextTest.java

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ private void testGetContext(boolean limit, boolean hitList)
132132
// Search freetext for the term "def"
133133
QueryBuilder qb = new QueryBuilder().setFreetext("def");
134134
Context c = new Context(qb.build(), qb.getQueries());
135-
assertTrue(c.getContext(in, out, "", "", "", null, limit, hits));
135+
assertTrue(c.getContext(in, out, "", "", "", null, limit, qb.isDefSearch(), hits));
136136

137137
if (hitList) {
138138
assertEquals(1, hits.size());
@@ -156,7 +156,7 @@ private void testGetContext(boolean limit, boolean hitList)
156156
hits = hitList ? new ArrayList<Hit>() : null;
157157
qb = new QueryBuilder().setDefs("def");
158158
c = new Context(qb.build(), qb.getQueries());
159-
assertTrue(c.getContext(in, out, "", "", "", defs, limit, hits));
159+
assertTrue(c.getContext(in, out, "", "", "", defs, limit, qb.isDefSearch(), hits));
160160

161161
if (hitList) {
162162
assertEquals(1, hits.size());
@@ -170,13 +170,30 @@ private void testGetContext(boolean limit, boolean hitList)
170170
actualOutput = hitList ? hits.get(0).getLine() : out.toString();
171171
assertEquals(expectedOutput, actualOutput);
172172

173+
in = new StringReader("abc def ghi\n");
174+
out = hitList ? null : new StringWriter();
175+
hits = hitList ? new ArrayList<Hit>() : null;
176+
assertTrue(c.getContext(in, out, "", "", "", null, limit, qb.isDefSearch(), hits));
177+
178+
if (hitList) {
179+
assertEquals(0, hits.size());
180+
}
181+
182+
expectedOutput = hitList
183+
? ""
184+
: "";
185+
actualOutput = hitList ? "" : out.toString();
186+
//test case - if this is def search, don't show false results (defs
187+
// weren't defined)
188+
assertEquals(expectedOutput, actualOutput);
189+
173190
// Search with no input (will search definitions)
174191
in = null;
175192
out = hitList ? null : new StringWriter();
176193
hits = hitList ? new ArrayList<Hit>() : null;
177194
qb = new QueryBuilder().setDefs("def");
178195
c = new Context(qb.build(), qb.getQueries());
179-
assertTrue(c.getContext(in, out, "", "", "", defs, limit, hits));
196+
assertTrue(c.getContext(in, out, "", "", "", defs, limit, qb.isDefSearch(), hits));
180197

181198
if (hitList) {
182199
assertEquals(1, hits.size());
@@ -196,7 +213,7 @@ private void testGetContext(boolean limit, boolean hitList)
196213
hits = hitList ? new ArrayList<Hit>() : null;
197214
qb = new QueryBuilder().setFreetext("no_match");
198215
c = new Context(qb.build(), qb.getQueries());
199-
assertFalse(c.getContext(in, out, "", "", "", null, limit, hits));
216+
assertFalse(c.getContext(in, out, "", "", "", null, limit, qb.isDefSearch(), hits));
200217
if (hitList) {
201218
assertEquals(0, hits.size());
202219
} else {
@@ -209,7 +226,7 @@ private void testGetContext(boolean limit, boolean hitList)
209226
hits = hitList ? new ArrayList<Hit>() : null;
210227
qb = new QueryBuilder().setHist("abc");
211228
c = new Context(qb.build(), qb.getQueries());
212-
assertFalse(c.getContext(in, out, "", "", "", null, limit, hits));
229+
assertFalse(c.getContext(in, out, "", "", "", null, limit, qb.isDefSearch(), hits));
213230
if (hitList) {
214231
assertEquals(0, hits.size());
215232
} else {
@@ -235,7 +252,7 @@ public void testLongLineNearBufferBoundary() throws ParseException {
235252
Context c = new Context(qb.build(), qb.getQueries());
236253
StringWriter out = new StringWriter();
237254
boolean match =
238-
c.getContext(in, out, "", "", "", null, true, null);
255+
c.getContext(in, out, "", "", "", null, true, qb.isDefSearch(),null);
239256
assertTrue("No match found", match);
240257
String s = out.toString();
241258
assertTrue("Match not written to Writer",
@@ -263,7 +280,7 @@ public void testAllLinkWithLongLines() throws ParseException {
263280
Context c = new Context(qb.build(), qb.getQueries());
264281

265282
boolean match =
266-
c.getContext(in, out, "", "", "", null, true, null);
283+
c.getContext(in, out, "", "", "", null, true, qb.isDefSearch(), null);
267284
assertTrue("No match found", match);
268285
String s = out.toString();
269286
assertTrue("No [all...] link", s.contains(">[all...]</a>"));
@@ -290,7 +307,7 @@ public void testLongTruncatedLine() throws ParseException {
290307
Context c = new Context(qb.build(), qb.getQueries());
291308

292309
boolean match =
293-
c.getContext(in, out, "", "", "", null, true, null);
310+
c.getContext(in, out, "", "", "", null, true, qb.isDefSearch(), null);
294311
assertTrue("No match found", match);
295312
String s = out.toString();
296313
assertTrue("Match not listed", s.contains("<b>search_for_me</b>"));
@@ -318,7 +335,7 @@ public void testMultiLineMatch() throws Exception {
318335
Context c = new Context(qb.build(), qb.getQueries());
319336
assertTrue(
320337
"No match found",
321-
c.getContext(in, out, "", "", "", null, true, null));
338+
c.getContext(in, out, "", "", "", null, true, qb.isDefSearch(), null));
322339

323340
// Close the XML document body
324341
out.append("\n</document>");
@@ -353,7 +370,7 @@ public void bug16848() throws Exception {
353370
StringWriter out = new StringWriter();
354371
QueryBuilder qb = new QueryBuilder().setFreetext("mixed");
355372
Context c = new Context(qb.build(), qb.getQueries());
356-
assertTrue(c.getContext(in, out, "", "", "", null, false, null));
373+
assertTrue(c.getContext(in, out, "", "", "", null, false, qb.isDefSearch(), null));
357374
assertEquals("<a class=\"s\" href=\"#0\"><span class=\"l\">0</span> "
358375
+ "<b>Mixed</b> case: abc AbC dEf</a><br/>",
359376
out.toString());
@@ -410,7 +427,7 @@ private void bug17582(QueryBuilder builder, int[] lines, String[] tags)
410427
Context context = new Context(builder.build(), builder.getQueries());
411428
ArrayList<Hit> hits = new ArrayList<Hit>();
412429
assertEquals(lines.length != 0,
413-
context.getContext(in, null, "", "", "", defs, false, hits));
430+
context.getContext(in, null, "", "", "", defs, false, builder.isDefSearch(), hits));
414431
assertEquals("Unexpected number of hits", lines.length, hits.size());
415432
for (int i = 0; i < lines.length; i++) {
416433
assertEquals(Integer.toString(lines[i]), hits.get(i).getLineno());

0 commit comments

Comments
 (0)