Skip to content

Commit

Permalink
[eclipse#902] Do not split line endings in edits
Browse files Browse the repository at this point in the history
Adds unit test to validate change.

fixes eclipse#902
  • Loading branch information
ghentschke authored and mickaelistria committed Jan 29, 2024
1 parent 4806ce8 commit a82c8c8
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,26 @@ public void testTextEditInsertSameOffset() throws Exception {
LSPEclipseUtils.applyEdits(document, Arrays.asList(edits));
Assert.assertEquals(" throws Exception", document.get());
}

@Test
public void testTextEditSplittedLineEndings() throws Exception {
IProject project = null;
IEditorPart editor = null;
project = TestUtils.createProject(getClass().getSimpleName() + System.currentTimeMillis());
IFile file = TestUtils.createUniqueTestFile(project, "line1\r\nline2\r\nline3\r\n");
editor = TestUtils.openEditor(file);
ITextViewer viewer = LSPEclipseUtils.getTextViewer(editor);
// GIVEN a TextEdit which splits the '\r\n' line ending in the third line:
TextEdit[] edits = new TextEdit[] { new TextEdit(new Range(new Position(0, 0), new Position(2, 6)), "line3\r\nline2\r\nline1\r") };
IDocument document = viewer.getDocument();
int linesBeforeApplyEdits = document.getNumberOfLines();
// WHEN the TextEdit gets applied to the document:
LSPEclipseUtils.applyEdits(document, Arrays.asList(edits));
// THEN line1 has been swapped with line 3:
Assert.assertEquals("line3\r\nline2\r\nline1\r\n", document.get());
// AND the number of lines is still the same, because we have not appended a line:
Assert.assertEquals(linesBeforeApplyEdits, document.getNumberOfLines());
}

@Test
public void testURICreationUnix() {
Expand Down

0 comments on commit a82c8c8

Please sign in to comment.