Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMateusz Matela2019-07-06 10:42:30 +0000
committerMickael Istria2019-09-17 09:56:22 +0000
commit5f90916aa35368e9894d559308845c7f5c5d6a23 (patch)
treebb5b657380376356dd8e3509466421f9f4d7f585 /org.eclipse.jface.text.tests/src
parent812fe47c98daf733d10a208cfe4717109fdd59f7 (diff)
downloadeclipse.platform.text-5f90916aa35368e9894d559308845c7f5c5d6a23.tar.gz
eclipse.platform.text-5f90916aa35368e9894d559308845c7f5c5d6a23.tar.xz
eclipse.platform.text-5f90916aa35368e9894d559308845c7f5c5d6a23.zip
Bug 483846 - [typing] Spaces only mode: backspace key to remove manyI20190918-0300I20190917-1800
spaces Change-Id: I162b412281bc0028aba4e763a859410d86f34aa6 Signed-off-by: Mateusz Matela <mateusz.matela@gmail.com>
Diffstat (limited to 'org.eclipse.jface.text.tests/src')
-rw-r--r--org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/JFaceTextTestSuite.java6
-rw-r--r--org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TabsToSpacesConverterTest.java201
-rw-r--r--org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TextViewerTest.java2
3 files changed, 206 insertions, 3 deletions
diff --git a/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/JFaceTextTestSuite.java b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/JFaceTextTestSuite.java
index 3a481804467..5790030af85 100644
--- a/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/JFaceTextTestSuite.java
+++ b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/JFaceTextTestSuite.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2016 IBM Corporation and others.
+ * Copyright (c) 2000, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -62,7 +62,9 @@ import org.eclipse.jface.text.tests.templates.persistence.TemplatePersistenceDat
LineContentBoundsDrawingTest.class,
AnnotationOnTabTest.class,
CodeMiningTest.class,
- CodeMiningProjectionViewerTest.class
+ CodeMiningProjectionViewerTest.class,
+
+ TabsToSpacesConverterTest.class,
})
public class JFaceTextTestSuite {
// see @SuiteClasses
diff --git a/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TabsToSpacesConverterTest.java b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TabsToSpacesConverterTest.java
new file mode 100644
index 00000000000..b2617626bff
--- /dev/null
+++ b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TabsToSpacesConverterTest.java
@@ -0,0 +1,201 @@
+/*******************************************************************************
+ * Copyright (c) 2019 Mateusz Matela 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:
+ * Mateusz Matela - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jface.text.tests;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Shell;
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.DefaultLineTracker;
+import org.eclipse.jface.text.Document;
+import org.eclipse.jface.text.Position;
+import org.eclipse.jface.text.TabsToSpacesConverter;
+import org.eclipse.jface.text.TextViewer;
+import org.eclipse.jface.text.source.projection.ProjectionAnnotation;
+import org.eclipse.jface.text.source.projection.ProjectionAnnotationModel;
+import org.eclipse.jface.text.source.projection.ProjectionViewer;
+
+public class TabsToSpacesConverterTest {
+
+ private void doTest(String input, String output, int keyCode, int tabWidth) {
+ Shell shell= new Shell();
+ TextViewer textViewer= new TextViewer(shell, SWT.NONE);
+
+ TabsToSpacesConverter tabToSpacesConverter= new TabsToSpacesConverter();
+ tabToSpacesConverter.setLineTracker(new DefaultLineTracker());
+ tabToSpacesConverter.setNumberOfSpacesPerTab(tabWidth);
+ tabToSpacesConverter.setDeleteSpacesAsTab(true);
+ textViewer.setTabsToSpacesConverter(tabToSpacesConverter);
+
+ int selectionFrom= input.indexOf('|');
+ int selectionTo= input.indexOf('|', selectionFrom + 1) - 1;
+ Document document= new Document(input.replace("|", ""));
+ textViewer.setDocument(document);
+ textViewer.setSelectedRange(selectionFrom, selectionTo - selectionFrom);
+
+ TextViewerTest.postKeyEvent(textViewer.getTextWidget(), keyCode, SWT.NONE, SWT.KeyDown);
+
+ assertEquals(output, document.get());
+ }
+
+ @Test
+ public void testDelete1() {
+ doTest("|| ABC", " ABC", SWT.DEL, 4);
+ }
+
+ @Test
+ public void testDelete2() {
+ doTest(" || ABC", " ABC", SWT.DEL, 4);
+ }
+
+ @Test
+ public void testDelete3() {
+ doTest(" || ABC", " ABC", SWT.DEL, 4);
+ }
+
+ @Test
+ public void testDelete4() {
+ doTest(" || ABC", " ABC", SWT.DEL, 4);
+ }
+
+ @Test
+ public void testDeleteRange1() {
+ doTest(" | | ABC", " ABC", SWT.DEL, 4);
+ }
+
+ @Test
+ public void testDeleteRange2() {
+ doTest(" | | ABC", " ABC", SWT.DEL, 4);
+ }
+
+ @Test
+ public void testDeleteInside1() {
+ doTest(" ABCD|| EFG", " ABCDEFG", SWT.DEL, 4);
+ }
+
+ @Test
+ public void testDeleteInside2() {
+ doTest(" ABCD || EFG", " ABCD EFG", SWT.DEL, 4);
+ }
+
+ @Test
+ public void testDeleteInside3() {
+ doTest(" ABCD|| EFG", " ABCDEFG", SWT.DEL, 4);
+ }
+
+ @Test
+ public void testDeleteLargeWidth1() {
+ doTest(" || ABC", " ABC", SWT.DEL, 10);
+ }
+
+ @Test
+ public void testDeleteLargeWidth2() {
+ doTest(" || ABC", " ABC", SWT.DEL, 10);
+ }
+
+ @Test
+ public void testDeleteSmallWidth() {
+ doTest(" || ABC", " ABC", SWT.DEL, 2);
+ }
+
+ @Test
+ public void testBackspace1() {
+ doTest(" || ABC", " ABC", SWT.BS, 4);
+ }
+
+ @Test
+ public void testBackspace2() {
+ doTest(" ||ABC", " ABC", SWT.BS, 4);
+ }
+
+ @Test
+ public void testBackspace3() {
+ doTest(" || ABC", " ABC", SWT.BS, 4);
+ }
+
+ @Test
+ public void testBackspace4() {
+ doTest(" || ABC", " ABC", SWT.BS, 4);
+ }
+
+ @Test
+ public void testBackspaceRange1() {
+ doTest(" | | ABC", " ABC", SWT.BS, 4);
+ }
+
+ @Test
+ public void testBackspaceRange2() {
+ doTest(" | | ABC", " ABC", SWT.BS, 4);
+ }
+
+ @Test
+ public void testBackspaceInside1() {
+ doTest(" ABCD ||EFG", " ABCDEFG", SWT.BS, 4);
+ }
+
+ @Test
+ public void testBackspaceInside2() {
+ doTest(" ABCD ||EFG", " ABCD EFG", SWT.BS, 4);
+ }
+
+ @Test
+ public void testBackspaceInside3() {
+ doTest(" ABCDEF ||G", " ABCDEFG", SWT.BS, 4);
+ }
+
+ @Test
+ public void testBackspaceLargeWidth1() {
+ doTest(" || ABC", " ABC", SWT.BS, 10);
+ }
+
+ @Test
+ public void testBackspaceLargeWidth2() {
+ doTest(" || ABC", " ABC", SWT.BS, 10);
+ }
+
+ @Test
+ public void testBackspaceSmallWidth() {
+ doTest(" || ABC", " ABC", SWT.BS, 2);
+ }
+
+ @Test
+ public void testDeleteAfterCollapsedRegion() throws BadLocationException {
+ Shell shell= new Shell();
+ ProjectionViewer textViewer= new ProjectionViewer(shell, null, null, false, SWT.NONE);
+
+ TabsToSpacesConverter tabToSpacesConverter= new TabsToSpacesConverter();
+ tabToSpacesConverter.setLineTracker(new DefaultLineTracker());
+ tabToSpacesConverter.setNumberOfSpacesPerTab(4);
+ tabToSpacesConverter.setDeleteSpacesAsTab(true);
+ textViewer.setTabsToSpacesConverter(tabToSpacesConverter);
+
+ Document document= new Document(" COLLAPSED!!!\n REGION!!!\n VISIBLE\n REGION");
+ int caretPosition= document.get().indexOf("VISIBLE") - 4;
+ textViewer.setDocument(document, new ProjectionAnnotationModel());
+ textViewer.enableProjection();
+ textViewer.setSelectedRange(caretPosition, 0);
+
+ ProjectionAnnotation annotation= new ProjectionAnnotation(true);
+ textViewer.getProjectionAnnotationModel().addAnnotation(annotation, new Position(0, document.getLineOffset(2)));
+ textViewer.doOperation(ProjectionViewer.COLLAPSE_ALL);
+
+ TextViewerTest.postKeyEvent(textViewer.getTextWidget(), SWT.DEL, SWT.NONE, SWT.KeyDown);
+
+ assertEquals(" COLLAPSED!!!\n REGION!!!\nVISIBLE\n REGION", document.get());
+ }
+}
diff --git a/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TextViewerTest.java b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TextViewerTest.java
index a53a00dfc2e..2ee51f54302 100644
--- a/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TextViewerTest.java
+++ b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TextViewerTest.java
@@ -292,7 +292,7 @@ public class TextViewerTest {
postKeyEvent(viewer.getTextWidget(), SWT.HOME, SWT.CTRL, SWT.KeyDown);
}
- private static void postKeyEvent(Control widget, int keyCode, int stateMask, int type) {
+ static void postKeyEvent(Control widget, int keyCode, int stateMask, int type) {
Display display= widget.getDisplay();
widget.setFocus();
DisplayHelper.driveEventQueue(display);

Back to the top