summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorangelozerr2018-08-02 05:32:22 -0400
committerangelozerr2018-08-02 05:51:10 -0400
commit191fdca089cad6440d11dbdf726431711d9024c3 (patch)
treee5ddb44f5cbe34a4afc6cb4d2c76a552c5fbbffc
parentc4a95379dcef14524c9bc4cc6b1c8d1cc159e1c7 (diff)
downloadeclipse.platform.text-191fdca089cad6440d11dbdf726431711d9024c3.tar.gz
eclipse.platform.text-191fdca089cad6440d11dbdf726431711d9024c3.tar.xz
eclipse.platform.text-191fdca089cad6440d11dbdf726431711d9024c3.zip
Bug 321410 - [EditorMgmt][navigation] Provide Mini-map of text in editor
Add Minimap tests. Change-Id: I989369bf649d915409f4148364cad289e061d777 Signed-off-by: angelozerr <angelo.zerr@gmail.com>
-rw-r--r--org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/workbench/texteditor/tests/WorkbenchTextEditorTestSuite.java6
-rw-r--r--org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/workbench/texteditor/tests/minimap/MinimapPageTest.java89
-rw-r--r--org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/workbench/texteditor/tests/minimap/MinimapWidgetTest.java102
3 files changed, 196 insertions, 1 deletions
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 08aac2c3c..b096ce68c 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
@@ -14,6 +14,8 @@ import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
+import org.eclipse.ui.workbench.texteditor.tests.minimap.MinimapPageTest;
+import org.eclipse.ui.workbench.texteditor.tests.minimap.MinimapWidgetTest;
import org.eclipse.ui.workbench.texteditor.tests.revisions.ChangeRegionTest;
import org.eclipse.ui.workbench.texteditor.tests.revisions.HunkComputerTest;
import org.eclipse.ui.workbench.texteditor.tests.revisions.RangeTest;
@@ -35,7 +37,9 @@ import org.eclipse.ui.workbench.texteditor.tests.rulers.RulerTestSuite;
HunkComputerTest.class,
ScreenshotTest.class,
AbstractTextZoomHandlerTest.class,
- DocumentLineDifferTest.class
+ DocumentLineDifferTest.class,
+ MinimapPageTest.class,
+ MinimapWidgetTest.class
})
public class WorkbenchTextEditorTestSuite {
// see @SuiteClasses
diff --git a/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/workbench/texteditor/tests/minimap/MinimapPageTest.java b/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/workbench/texteditor/tests/minimap/MinimapPageTest.java
new file mode 100644
index 000000000..bd902072d
--- /dev/null
+++ b/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/workbench/texteditor/tests/minimap/MinimapPageTest.java
@@ -0,0 +1,89 @@
+/*******************************************************************************
+ * Copyright (c) 2018 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr <angelo.zerr@gmail.com> - [minimap] Initialize minimap view - Bug 535450
+ *******************************************************************************/
+package org.eclipse.ui.workbench.texteditor.tests.minimap;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Shell;
+
+import org.eclipse.jface.text.ITextOperationTarget;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.TextViewer;
+
+import org.eclipse.ui.internal.views.minimap.MinimapPage;
+
+import org.eclipse.ui.texteditor.ITextEditor;
+import org.eclipse.ui.texteditor.StatusTextEditor;
+
+/**
+ * Test create of Minimap page which is possible only if {@link ITextViewer} can be get from the
+ * {@link ITextEditor}.
+ *
+ * @since 3.11
+ */
+public class MinimapPageTest {
+
+ enum TextVieverAdapterKind {
+ None, ITextViewer, ITextOperationTarget
+ }
+
+ class MyTextEditor extends StatusTextEditor {
+
+ private final TextVieverAdapterKind kind;
+
+ public MyTextEditor(TextVieverAdapterKind kind) {
+ this.kind= kind;
+ }
+
+ @Override
+ public <T> T getAdapter(Class<T> required) {
+ switch (kind) {
+ case None:
+ return null;
+ case ITextViewer:
+ if (ITextViewer.class.equals(required)) {
+ Composite parent= new Shell();
+ return (T) new TextViewer(parent, SWT.NONE);
+ }
+ case ITextOperationTarget:
+ if (ITextOperationTarget.class.equals(required)) {
+ Composite parent= new Shell();
+ return (T) new TextViewer(parent, SWT.NONE);
+ }
+ }
+ return null;
+ }
+ }
+
+ @Test
+ public void createNoneMinimapPage() {
+ ITextEditor textEditor= new MyTextEditor(TextVieverAdapterKind.None);
+ MinimapPage page= MinimapPage.createMinimapPage(textEditor);
+ Assert.assertNull(page);
+ }
+
+ @Test
+ public void createMinimapPageWithITextViewerAdapter() {
+ ITextEditor textEditor= new MyTextEditor(TextVieverAdapterKind.ITextViewer);
+ MinimapPage page= MinimapPage.createMinimapPage(textEditor);
+ Assert.assertNotNull(page);
+ }
+
+ @Test
+ public void createMinimapPageWithITextOperationTargetAdapter() {
+ ITextEditor textEditor= new MyTextEditor(TextVieverAdapterKind.ITextOperationTarget);
+ MinimapPage page= MinimapPage.createMinimapPage(textEditor);
+ Assert.assertNotNull(page);
+ }
+}
diff --git a/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/workbench/texteditor/tests/minimap/MinimapWidgetTest.java b/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/workbench/texteditor/tests/minimap/MinimapWidgetTest.java
new file mode 100644
index 000000000..629e9c9dc
--- /dev/null
+++ b/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/workbench/texteditor/tests/minimap/MinimapWidgetTest.java
@@ -0,0 +1,102 @@
+/*******************************************************************************
+ * Copyright (c) 2018 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr <angelo.zerr@gmail.com> - [minimap] Initialize minimap view - Bug 535450
+ *******************************************************************************/
+package org.eclipse.ui.workbench.texteditor.tests.minimap;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyleRange;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Shell;
+
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.TextPresentation;
+import org.eclipse.jface.text.TextViewer;
+
+import org.eclipse.ui.internal.views.minimap.MinimapWidget;
+
+/**
+ * Minimap widget tests to check that changed of {@link ITextViewer} of the editor update the
+ * {@link StyledText} of the Minimap:
+ *
+ * <ul>
+ * <li>check that {@link StyledText} content of minimap is synchronized with the text of the
+ * {@link ITextViewer} of the editor.</li>
+ * <li>check that {@link StyledText} styles of minimap is synchronized with the styles of the
+ * {@link ITextViewer} of the editor.</li>
+ * </ul>
+ *
+ * @since 3.11
+ */
+public class MinimapWidgetTest {
+
+ private ITextViewer editorViewer;
+
+ private StyledText editorStyledText;
+
+ private StyledText minimapStyledText;
+
+ @Before
+ public void createMinimap() {
+ Composite parent= new Shell();
+ editorViewer= new TextViewer(parent, SWT.NONE);
+ MinimapWidget minimapWidget= new MinimapWidget(parent, editorViewer);
+ minimapWidget.install();
+
+ editorStyledText= editorViewer.getTextWidget();
+ minimapStyledText= (StyledText) minimapWidget.getControl();
+
+ }
+
+ @Test
+ public void testMinimapContent() {
+ editorStyledText.setText("abcd");
+ Assert.assertEquals("abcd", minimapStyledText.getText());
+
+ editorStyledText.replaceTextRange(1, 0, "ABCD");
+ Assert.assertEquals("aABCDbcd", minimapStyledText.getText());
+ }
+
+ @Test
+ public void testMinimapSetStyles() {
+ // As it doesn't exists listener to track styles changed of StyledText, update styles directly in StyledText of the editor doesn't update the styles of StyledText of the minimap.
+ StyleRange[] orginalMinimapStyles = minimapStyledText.getStyleRanges();
+ editorStyledText.setText("abcd");
+ StyleRange[] ranges= new StyleRange[] { new StyleRange(0, 1, editorStyledText.getDisplay().getSystemColor(SWT.COLOR_BLACK), null) };
+ editorStyledText.setStyleRanges(ranges);
+ // Styles of minimap doesn't changed
+ Assert.assertArrayEquals(orginalMinimapStyles, minimapStyledText.getStyleRanges());
+ }
+
+ @Test
+ public void testMinimapSetStylesWithTextPresentation() {
+ // Track styles changed of TextPresentation, update the styles of StyledText of the minimap.
+ editorStyledText.setText("abcd");
+
+ StyleRange[] ranges= new StyleRange[] { new StyleRange(0, 1, editorStyledText.getDisplay().getSystemColor(SWT.COLOR_BLACK), null) };
+ TextPresentation presentation= new TextPresentation();
+ presentation.mergeStyleRanges(ranges);
+ editorViewer.changeTextPresentation(presentation, false);
+ StyleRange[] expectedRanges= new StyleRange[] { new StyleRange(0, 1, editorStyledText.getDisplay().getSystemColor(SWT.COLOR_BLACK), null) };
+ Assert.assertArrayEquals(expectedRanges, minimapStyledText.getStyleRanges());
+
+ ranges= new StyleRange[] { new StyleRange(1, 1, editorStyledText.getDisplay().getSystemColor(SWT.COLOR_RED), null) };
+ presentation= new TextPresentation();
+ presentation.mergeStyleRanges(ranges);
+ editorViewer.changeTextPresentation(presentation, false);
+ expectedRanges= new StyleRange[] { new StyleRange(0, 1, editorStyledText.getDisplay().getSystemColor(SWT.COLOR_BLACK), null),
+ new StyleRange(1, 1, editorStyledText.getDisplay().getSystemColor(SWT.COLOR_RED), null) };
+ Assert.assertArrayEquals(expectedRanges, minimapStyledText.getStyleRanges());
+ }
+}