diff options
author | Pierre-Yves Bigourdan | 2020-08-09 07:52:01 +0000 |
---|---|---|
committer | Alexander Kurtakov | 2020-08-10 11:34:41 +0000 |
commit | 6952968d00477c57c6feaea28c7690824b78e77b (patch) | |
tree | 61a17e35e1fb90c8031ca6b48b866bf509d3a7a7 | |
parent | 3e34b7b4bba37eb85580cb6474d10590a286e7d5 (diff) | |
download | eclipse.platform.text-6952968d00477c57c6feaea28c7690824b78e77b.tar.gz eclipse.platform.text-6952968d00477c57c6feaea28c7690824b78e77b.tar.xz eclipse.platform.text-6952968d00477c57c6feaea28c7690824b78e77b.zip |
Bug 564929 - Delete line shortcut does not delete last editor lineY20200811-1200Y20200810-1200I20200810-1800
Add unit tests for TextViewerDeleteLineTarget.
Change-Id: Ic382d1010ad88fddfb61ccd679d55f9401df5fb2
Signed-off-by: Pierre-Yves Bigourdan <PyvesDev@gmail.com>
2 files changed, 110 insertions, 2 deletions
diff --git a/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/workbench/texteditor/tests/TextViewerDeleteLineTargetTest.java b/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/workbench/texteditor/tests/TextViewerDeleteLineTargetTest.java new file mode 100644 index 00000000000..3abb872f2aa --- /dev/null +++ b/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/workbench/texteditor/tests/TextViewerDeleteLineTargetTest.java @@ -0,0 +1,107 @@ +/******************************************************************************* + * Copyright (c) 2020 Pierre-Yves Bigourdan and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Pierre-Yves Bigourdan - initial API and implementation + *******************************************************************************/ +package org.eclipse.ui.workbench.texteditor.tests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThrows; + +import org.junit.Before; +import org.junit.Test; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.dnd.Clipboard; +import org.eclipse.swt.dnd.TextTransfer; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; + +import org.eclipse.jface.action.IAction; + +import org.eclipse.jface.text.Document; +import org.eclipse.jface.text.TextSelection; +import org.eclipse.jface.text.TextViewer; + +import org.eclipse.ui.texteditor.DeleteLineAction; +import org.eclipse.ui.texteditor.TextViewerDeleteLineTarget; + +public class TextViewerDeleteLineTargetTest { + + private Document document; + + private TextViewerDeleteLineTarget underTest; + + @Before + public void setUp() { + document= new Document("first line\n" + + "\n" + + "third line\n"); + + TextViewer textViewer= new TextViewer(new Shell(), SWT.NONE); + textViewer.setDocument(document); + + underTest= new TextViewerDeleteLineTarget(textViewer); + } + + @Test + public void testWholeLineDeletion() throws Exception { + underTest.deleteLine(document, new TextSelection(document, 1, 3), DeleteLineAction.WHOLE, false); + + assertEquals("\n" + + "third line\n", document.get()); + } + + @Test + public void testWholeLineDeletionOnLastEmptyLine() throws Exception { + underTest.deleteLine(document, new TextSelection(document, 23, 0), DeleteLineAction.WHOLE, false); + + assertEquals("first line\n" + + "\n" + + "third line", document.get()); + } + + @Test + public void testWholeLineDeletionWithCopyToClipboard() throws Exception { + Clipboard clipboard= new Clipboard(Display.getCurrent()); + try { + underTest.deleteLine(document, new TextSelection(document, 1, 4), DeleteLineAction.WHOLE, true); + + assertEquals("first line\n", clipboard.getContents(TextTransfer.getInstance())); + } finally { + clipboard.dispose(); + } + } + + @Test + public void testLineDeletionToBeginning() throws Exception { + underTest.deleteLine(document, new TextSelection(document, 6, 0), DeleteLineAction.TO_BEGINNING, false); + + assertEquals("line\n" + + "\n" + + "third line\n", document.get()); + } + + @Test + public void testLineDeletionToEnd() throws Exception { + underTest.deleteLine(document, new TextSelection(document, 17, 0), DeleteLineAction.TO_END, false); + + assertEquals("first line\n" + + "\n" + + "third\n", document.get()); + } + + @Test + public void testThrowsExceptionWithUnsupportedDeleteLineActionType() throws Exception { + assertThrows(IllegalArgumentException.class, () -> underTest.deleteLine(document, 0, 0, IAction.AS_RADIO_BUTTON, false)); + } + +} diff --git a/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/workbench/texteditor/tests/WorkbenchTextEditorTestSuite.java b/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/workbench/texteditor/tests/WorkbenchTextEditorTestSuite.java index c6f03ab0862..c1b2c55bd49 100644 --- a/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/workbench/texteditor/tests/WorkbenchTextEditorTestSuite.java +++ b/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/workbench/texteditor/tests/WorkbenchTextEditorTestSuite.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2016 IBM Corporation and others. + * Copyright (c) 2000, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -43,7 +43,8 @@ import org.eclipse.ui.workbench.texteditor.tests.rulers.RulerTestSuite; DocumentLineDifferTest.class, MinimapPageTest.class, MinimapWidgetTest.class, - TextEditorPluginTest.class + TextEditorPluginTest.class, + TextViewerDeleteLineTargetTest.class }) public class WorkbenchTextEditorTestSuite { // see @SuiteClasses |