// Environment.
AppContext appContext = new MockAppContext();
Editor editor = Editor.create(appContext);
editor.setDocument(document);
MockCubeClient cubeClient = MockCubeClient.create();
cubeClient.setPath(filePath.getPathString());
ReferenceStore referenceStore = null;
try {
referenceStore = new ReferenceStore(cubeClient);
referenceStore.onDocumentChanged(document, null);
referenceStore.updateReferences(
new CubeData(filePath.getPathString(), null, null, null, null, fileReferences));
LineInfo line1 = document.getLineFinder().findLine(1);
// Check that there's reference at positions 12 to 17 inclusive (line 2).
assertNotNull(referenceStore.findReference(line1, 12, true));
assertNotNull(referenceStore.findReference(line1, 17, true));
// Make some edits. Just insert some whitespaces before reference.
// Now the second line is: "var myvar = defvar;\n"
document.insertText(document.getFirstLine().getNextLine(), 3, " ");
// Test!
// Now there's nothing at position 13.
assertNull(referenceStore.findReference(line1, 13, true));
// And there's reference at 18.
assertNotNull(referenceStore.findReference(line1, 18, true));
// Make some more edits, add whitespace inside reference.
// This should break it.
// Now the second line is: "var myvar = d efvar;\n"
document.insertText(document.getFirstLine().getNextLine(), 16, " ");
// Now there should be nothing at positions 15-23.
assertNull(referenceStore.findReference(line1, 15, true));
assertNull(referenceStore.findReference(line1, 18, true));
assertNull(referenceStore.findReference(line1, 21, true));
referenceStore.onDocumentChanged(Document.createEmpty(), null);
} finally {
if (referenceStore != null) {
referenceStore.cleanup();
}
cubeClient.cleanup();
}
}