Skip to content

Commit c84ffea

Browse files
Lubos KoscoLubos Kosco
authored andcommitted
one more test for #681
1 parent 0a9fe08 commit c84ffea

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

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

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -169,24 +169,21 @@ private void testGetContext(boolean limit, boolean hitList)
169169
+ "abc <b>def</b> ghi</a> <i> type</i> <br/>";
170170
actualOutput = hitList ? hits.get(0).getLine() : out.toString();
171171
assertEquals(expectedOutput, actualOutput);
172-
173-
in = new StringReader("abc def ghi\n");
172+
173+
in = new StringReader("abc def ghi\nbah def foobar");
174174
out = hitList ? null : new StringWriter();
175175
hits = hitList ? new ArrayList<Hit>() : null;
176-
assertTrue(c.getContext(in, out, "", "", "", null, limit, qb.isDefSearch(), hits));
176+
assertTrue(c.getContext(in, out, "", "", "", defs, limit, qb.isDefSearch(), hits));
177177

178178
if (hitList) {
179-
assertEquals(0, hits.size());
179+
assertEquals(1, hits.size());
180+
assertEquals("1", hits.get(0).getLineno());
180181
}
181-
182-
expectedOutput = hitList
183-
? ""
184-
: "";
185-
actualOutput = hitList ? "" : out.toString();
182+
186183
//test case - if this is def search, don't show false results (defs
187184
// weren't defined)
188185
assertEquals(expectedOutput, actualOutput);
189-
186+
190187
// Search with no input (will search definitions)
191188
in = null;
192189
out = hitList ? null : new StringWriter();
@@ -206,6 +203,27 @@ private void testGetContext(boolean limit, boolean hitList)
206203
+ "text</a> <i>type</i><br/>";
207204
actualOutput = hitList ? hits.get(0).getLine() : out.toString();
208205
assertEquals(expectedOutput, actualOutput);
206+
207+
defs = new Definitions();
208+
defs.addTag(2, "def", "type", "text");
209+
in = new StringReader("abc1 def ghi\nabc def ghi\nabc3 def ghi\n");
210+
out = hitList ? null : new StringWriter();
211+
hits = hitList ? new ArrayList<Hit>() : null;
212+
qb = new QueryBuilder().setDefs("def");
213+
c = new Context(qb.build(), qb.getQueries());
214+
assertTrue(c.getContext(in, out, "", "", "", defs, limit, qb.isDefSearch(), hits));
215+
216+
if (hitList) {
217+
assertEquals(1, hits.size());
218+
assertEquals("2", hits.get(0).getLineno());
219+
}
220+
221+
expectedOutput = hitList
222+
? "abc <b>def</b> ghi"
223+
: "<a class=\"s\" href=\"#2\"><span class=\"l\">2</span> "
224+
+ "abc <b>def</b> ghi</a> <i> type</i> <br/>";
225+
actualOutput = hitList ? hits.get(0).getLine() : out.toString();
226+
assertEquals(expectedOutput, actualOutput);
209227

210228
// Search with no results
211229
in = new StringReader("abc def ghi\n");

0 commit comments

Comments
 (0)