Resources mockResources = createMockResource();
SearchMatchRenderer renderer = new SearchMatchRenderer(mockResources, mockSearchModel);
// Now ask it about each line in our document and check to see if its right
Document doc = SearchTestsUtil.createDocument();
LineInfo lineInfo = doc.getFirstLineInfo();
for (int i = 0; i < 6; i++) {
assertFalse(renderer.resetToBeginningOfLine(lineInfo.line(), lineInfo.number()));
lineInfo.moveToNext();
}
// Check that this line is parsed correctly
ImmutableList<Integer> lengthList = ImmutableList.of(41, 4);
Target mockTarget = createMockTarget(lengthList, false);
assertTrue(renderer.resetToBeginningOfLine(lineInfo.line(), lineInfo.number()));
for (int i = 0; i < lengthList.size(); i++) {
renderer.renderNextChunk(mockTarget);
}
lineInfo.moveToNext();
verify(mockTarget);
assertFalse(renderer.resetToBeginningOfLine(lineInfo.line(), lineInfo.number()));
lineInfo.moveToNext();
// The next fun line
lengthList = ImmutableList.of(4,1,4,4,4,1,4,1,4,3,4,1,4);
mockTarget = createMockTarget(lengthList, true);
assertTrue(renderer.resetToBeginningOfLine(lineInfo.line(), lineInfo.number()));
for (int i = 0; i < lengthList.size(); i++) {
renderer.renderNextChunk(mockTarget);
}
lineInfo.moveToNext();
verify(mockTarget);
assertFalse(renderer.resetToBeginningOfLine(lineInfo.line(), lineInfo.number()));
lineInfo.moveToNext();
assertFalse(renderer.resetToBeginningOfLine(lineInfo.line(), lineInfo.number()));
}