Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDani Megert2004-04-14 15:46:14 +0000
committerDani Megert2004-04-14 15:46:14 +0000
commit8048882152e3dd8bb9dd4d25ae2968c9aba05fdb (patch)
tree11941e4c47f030341fa942a532f882605d089677 /org.eclipse.jface.text.tests
parentfeec0ceb0b6a70b3211729f5051a965caf07b8c3 (diff)
downloadeclipse.platform.text-8048882152e3dd8bb9dd4d25ae2968c9aba05fdb.tar.gz
eclipse.platform.text-8048882152e3dd8bb9dd4d25ae2968c9aba05fdb.tar.xz
eclipse.platform.text-8048882152e3dd8bb9dd4d25ae2968c9aba05fdb.zip
Initial Release - work in progressInitial_Release
Diffstat (limited to 'org.eclipse.jface.text.tests')
-rw-r--r--org.eclipse.jface.text.tests/.classpath7
-rw-r--r--org.eclipse.jface.text.tests/.cvsignore1
-rw-r--r--org.eclipse.jface.text.tests/.project28
-rw-r--r--org.eclipse.jface.text.tests/JFaceTextSuite.launch10
-rw-r--r--org.eclipse.jface.text.tests/about.html30
-rw-r--r--org.eclipse.jface.text.tests/build.properties15
-rw-r--r--org.eclipse.jface.text.tests/plugin.properties13
-rw-r--r--org.eclipse.jface.text.tests/plugin.xml24
-rw-r--r--org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/JFaceTextSuite.java37
-rw-r--r--org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TestTextEvent.java26
-rw-r--r--org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TestTextViewer.java440
-rw-r--r--org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TextHoverPopupTest.java73
-rw-r--r--org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TextPresentationTest.java572
-rw-r--r--org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TextUtilitiesTest.java277
-rw-r--r--org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/UndoManagerTest.java218
15 files changed, 1771 insertions, 0 deletions
diff --git a/org.eclipse.jface.text.tests/.classpath b/org.eclipse.jface.text.tests/.classpath
new file mode 100644
index 000000000..065ac06e1
--- /dev/null
+++ b/org.eclipse.jface.text.tests/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/org.eclipse.jface.text.tests/.cvsignore b/org.eclipse.jface.text.tests/.cvsignore
new file mode 100644
index 000000000..c5e82d745
--- /dev/null
+++ b/org.eclipse.jface.text.tests/.cvsignore
@@ -0,0 +1 @@
+bin \ No newline at end of file
diff --git a/org.eclipse.jface.text.tests/.project b/org.eclipse.jface.text.tests/.project
new file mode 100644
index 000000000..57bacfcc0
--- /dev/null
+++ b/org.eclipse.jface.text.tests/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.jface.text.tests</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/org.eclipse.jface.text.tests/JFaceTextSuite.launch b/org.eclipse.jface.text.tests/JFaceTextSuite.launch
new file mode 100644
index 000000000..1908eb88d
--- /dev/null
+++ b/org.eclipse.jface.text.tests/JFaceTextSuite.launch
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<launchConfiguration type="org.eclipse.jdt.junit.launchconfig">
+<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/>
+<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.eclipse.jface.text.tests.JFaceTextSuite"/>
+<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.jface.text.tests"/>
+<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Djava.library.path=${workspace_loc}\org.eclipse.swt.win32\os\win32\x86"/>
+<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value=""/>
+<booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/>
+<stringAttribute key="org.eclipse.debug.core.source_locator_id" value="org.eclipse.jdt.debug.ui.javaSourceLocator"/>
+</launchConfiguration>
diff --git a/org.eclipse.jface.text.tests/about.html b/org.eclipse.jface.text.tests/about.html
new file mode 100644
index 000000000..9db411aab
--- /dev/null
+++ b/org.eclipse.jface.text.tests/about.html
@@ -0,0 +1,30 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
+<html>
+<head>
+<title>About</title>
+<meta http-equiv=Content-Type content="text/html; charset=ISO-8859-1">
+</head>
+<body lang="EN-US">
+<h2>About This Content</h2>
+
+<p>20th June, 2002</p>
+<h3>License</h3>
+<p>Eclipse.org makes available all content in this plug-in (&quot;Content&quot;). Unless otherwise indicated below, the Content is provided to you under the terms and conditions of the
+Common Public License Version 1.0 (&quot;CPL&quot;). A copy of the CPL is available at <a href="http://www.eclipse.org/legal/cpl-v10.html">http://www.eclipse.org/legal/cpl-v10.html</a>.
+For purposes of the CPL, &quot;Program&quot; will mean the Content.</p>
+
+<h3>Contributions</h3>
+
+<p>If this Content is licensed to you under the terms and conditions of the CPL, any Contributions, as defined in the CPL, uploaded, submitted, or otherwise
+made available to Eclipse.org, members of Eclipse.org and/or the host of Eclipse.org web site, by you that relate to such
+Content are provided under the terms and conditions of the CPL and can be made available to others under the terms of the CPL.</p>
+
+<p>If this Content is licensed to you under license terms and conditions other than the CPL (&quot;Other License&quot;), any modifications, enhancements and/or
+other code and/or documentation (&quot;Modifications&quot;) uploaded, submitted, or otherwise made available to Eclipse.org, members of Eclipse.org and/or the
+host of Eclipse.org, by you that relate to such Content are provided under terms and conditions of the Other License and can be made available
+to others under the terms of the Other License. In addition, with regard to Modifications for which you are the copyright holder, you are also
+providing the Modifications under the terms and conditions of the CPL and such Modifications can be made available to others under the terms of
+the CPL.</p>
+
+</body>
+</html> \ No newline at end of file
diff --git a/org.eclipse.jface.text.tests/build.properties b/org.eclipse.jface.text.tests/build.properties
new file mode 100644
index 000000000..1e3de6203
--- /dev/null
+++ b/org.eclipse.jface.text.tests/build.properties
@@ -0,0 +1,15 @@
+###############################################################################
+# Copyright (c) 2000, 2004 IBM Corporation and others.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Common Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/cpl-v10.html
+#
+# Contributors:
+# IBM Corporation - initial API and implementation
+###############################################################################
+bin.includes = plugin.xml,\
+ test.xml,\
+ about.html,\
+ *.jar,\
+source.jfacetexttests.jar = src/
diff --git a/org.eclipse.jface.text.tests/plugin.properties b/org.eclipse.jface.text.tests/plugin.properties
new file mode 100644
index 000000000..2f0f27478
--- /dev/null
+++ b/org.eclipse.jface.text.tests/plugin.properties
@@ -0,0 +1,13 @@
+###############################################################################
+# Copyright (c) 2000, 2004 IBM Corporation and others.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Common Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/cpl-v10.html
+#
+# Contributors:
+# IBM Corporation - initial API and implementation
+###############################################################################
+
+Plugin.name= JFace Text Test Plug-in
+Plugin.providerName= Eclipse.org
diff --git a/org.eclipse.jface.text.tests/plugin.xml b/org.eclipse.jface.text.tests/plugin.xml
new file mode 100644
index 000000000..47e2386d5
--- /dev/null
+++ b/org.eclipse.jface.text.tests/plugin.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.0"?>
+<plugin
+ id="org.eclipse.jface.text.tests"
+ name="%Plugin.name"
+ version="3.0.0"
+ provider-name="%Plugin.providerName"
+ class="">
+
+ <runtime>
+ <library name="jfacetexttests.jar">
+ <export name="*"/>
+ </library>
+ </runtime>
+ <requires>
+ <import plugin="org.eclipse.core.runtime.compatibility"/>
+ <import plugin="org.eclipse.text"/>
+ <import plugin="org.eclipse.jface.text"/>
+ <import plugin="org.eclipse.jface"/>
+ <import plugin="org.junit"/>
+ </requires>
+
+
+</plugin>
diff --git a/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/JFaceTextSuite.java b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/JFaceTextSuite.java
new file mode 100644
index 000000000..3afee0cef
--- /dev/null
+++ b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/JFaceTextSuite.java
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jface.text.tests;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Test JFace/Text.
+ */
+public class JFaceTextSuite extends TestSuite {
+
+ /**
+ * Returns the suite. This is required to use the JUnit Launcher.
+ */
+ public static Test suite() {
+ return new JFaceTextSuite();
+ }
+
+ /**
+ * Construct the test suite.
+ */
+ public JFaceTextSuite() {
+ addTest(TextHoverPopupTest.suite());
+ addTest(TextPresentationTest.suite());
+ addTest(TextUtilitiesTest.suite());
+ addTest(UndoManagerTest.suite());
+ }
+}
diff --git a/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TestTextEvent.java b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TestTextEvent.java
new file mode 100644
index 000000000..9b0f7b6d5
--- /dev/null
+++ b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TestTextEvent.java
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jface.text.tests;
+
+import org.eclipse.jface.text.DocumentEvent;
+import org.eclipse.jface.text.TextEvent;
+
+
+public class TestTextEvent extends TextEvent {
+
+ TestTextEvent(DocumentEvent event, String replacedText) {
+ super(event.getOffset(), event.getLength(), event.getText(), replacedText, event, true);
+ }
+
+ TestTextEvent(String text) {
+ super(0, 0, text, (String) null, (DocumentEvent) null, true);
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TestTextViewer.java b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TestTextViewer.java
new file mode 100644
index 000000000..e74f81488
--- /dev/null
+++ b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TestTextViewer.java
@@ -0,0 +1,440 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jface.text.tests;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Point;
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.DocumentEvent;
+import org.eclipse.jface.text.IAutoIndentStrategy;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IDocumentListener;
+import org.eclipse.jface.text.IEventConsumer;
+import org.eclipse.jface.text.IFindReplaceTarget;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ITextDoubleClickStrategy;
+import org.eclipse.jface.text.ITextHover;
+import org.eclipse.jface.text.ITextInputListener;
+import org.eclipse.jface.text.ITextListener;
+import org.eclipse.jface.text.ITextOperationTarget;
+import org.eclipse.jface.text.IUndoManager;
+import org.eclipse.jface.text.IViewportListener;
+import org.eclipse.jface.text.TextEvent;
+import org.eclipse.jface.text.TextPresentation;
+import org.eclipse.jface.text.source.Annotation;
+import org.eclipse.jface.text.source.IAnnotationHover;
+import org.eclipse.jface.text.source.IAnnotationModel;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.jface.text.source.SourceViewerConfiguration;
+import org.eclipse.jface.viewers.ISelectionProvider;
+
+
+
+
+public class TestTextViewer implements ISourceViewer, IDocumentListener {
+
+
+ protected IDocument fDocument;
+ protected List fInputListeners= new ArrayList();
+ protected List fTextListeners= new ArrayList();
+ protected TextPresentation fTextPresentation;
+ protected Point fSelection= new Point(-1, -1);
+ protected String fDeletion;
+
+ /**
+ * @see ITextViewer#setDocument(IDocument, int, int)
+ */
+ public void setDocument(IDocument document, int p1, int p2) {
+ setDocument(document);
+ }
+
+ /**
+ * @see ITextViewer#getDocument()
+ */
+ public IDocument getDocument() {
+ return fDocument;
+ }
+
+ /**
+ * @see ITextViewer#setDocument(IDocument)
+ */
+ public void setDocument(IDocument document) {
+ IDocument oldDoc= fDocument;
+ fireTextInputChanged(oldDoc, document, true);
+
+ if (oldDoc != null)
+ oldDoc.removeDocumentListener(this);
+
+ fDocument= document;
+
+ if (fDocument != null) {
+ fireTextChanged(new TestTextEvent(fDocument.get()));
+ fDocument.addDocumentListener(this);
+ }
+
+ fireTextInputChanged(oldDoc, document, false);
+ }
+
+ /**
+ * @see ITextViewer#removeTextInputListener(ITextInputListener)
+ */
+ public void removeTextInputListener(ITextInputListener listener) {
+ fInputListeners.remove(listener);
+ }
+
+ /**
+ * @see ITextViewer#addTextInputListener(ITextInputListener)
+ */
+ public void addTextInputListener(ITextInputListener listener) {
+ if (!fInputListeners.contains(listener))
+ fInputListeners.add(listener);
+ }
+
+ protected void fireTextInputChanged(IDocument oldDoc, IDocument newDoc, boolean about) {
+ Iterator e= new ArrayList(fInputListeners).iterator();
+ while (e.hasNext()) {
+ ITextInputListener l= (ITextInputListener) e.next();
+ if (about)
+ l.inputDocumentAboutToBeChanged(oldDoc, newDoc);
+ else
+ l.inputDocumentChanged(oldDoc, newDoc);
+ }
+ }
+
+ /**
+ * @see ITextViewer#changeTextPresentation(TextPresentation, boolean)
+ */
+ public void changeTextPresentation(TextPresentation presentation, boolean p1) {
+ fTextPresentation= presentation;
+ }
+
+ /**
+ * @see ITextViewer#invalidateTextPresentation()
+ */
+ public void invalidateTextPresentation() {
+ }
+
+ public TextPresentation getTextPresentation() {
+ return fTextPresentation;
+ }
+
+ public void documentAboutToBeChanged(DocumentEvent event) {
+ try {
+ fDeletion= fDocument.get(event.getOffset(), event.getLength());
+ } catch (BadLocationException x) {
+ }
+ }
+
+ public void documentChanged(DocumentEvent event) {
+ fireTextChanged(new TestTextEvent(event, fDeletion));
+ }
+
+ /**
+ * @see ITextViewer#getFindReplaceTarget()
+ */
+ public IFindReplaceTarget getFindReplaceTarget() {
+ return null;
+ }
+
+ /**
+ * @see ITextViewer#getTextOperationTarget()
+ */
+ public ITextOperationTarget getTextOperationTarget() {
+ return null;
+ }
+
+ /**
+ * @see ITextViewer#setTextColor(Color, int, int, boolean)
+ */
+ public void setTextColor(Color p0, int p1, int p2, boolean p3) {
+ }
+
+ /**
+ * @see ITextViewer#setTextColor(Color)
+ */
+ public void setTextColor(Color p0) {
+ }
+
+ /**
+ * @see ITextViewer#adjustVisibleRegion(int, int)
+ */
+ public void adjustVisibleRegion(int p0, int p1) {
+ }
+
+ /**
+ * @see ITextViewer#overlapsWithVisibleRegion(int, int)
+ */
+ public boolean overlapsWithVisibleRegion(int p0, int p1) {
+ return false;
+ }
+
+ /**
+ * @see ITextViewer#getVisibleRegion()
+ */
+ public IRegion getVisibleRegion() {
+ return null;
+ }
+
+ /**
+ * @see ITextViewer#resetVisibleRegion()
+ */
+ public void resetVisibleRegion() {
+ }
+
+ /**
+ * @see ITextViewer#setVisibleRegion(int, int)
+ */
+ public void setVisibleRegion(int p0, int p1) {
+ }
+
+ /**
+ * @see ITextViewer#setIndentPrefixes(String[], String)
+ */
+ public void setIndentPrefixes(String[] p0, String p1) {
+ }
+
+ /**
+ * @see ITextViewer#setDefaultPrefixes(String, String)
+ */
+ public void setDefaultPrefixes(String[] p0, String p1) {
+ }
+
+ /**
+ * @see ITextViewer#setAutoIndentStrategy(IAutoIndentStrategy, String)
+ */
+ public void setAutoIndentStrategy(IAutoIndentStrategy p0, String p1) {
+ }
+
+ /**
+ * @see ITextViewer#setTextDoubleClickStrategy(ITextDoubleClickStrategy, String)
+ */
+ public void setTextDoubleClickStrategy(ITextDoubleClickStrategy p0, String p1) {
+ }
+
+ /**
+ * @see ITextViewer#setUndoManager(IUndoManager)
+ */
+ public void setUndoManager(IUndoManager p0) {
+ }
+
+ /**
+ * @see ITextViewer#getTextWidget()
+ */
+ public StyledText getTextWidget() {
+ return null;
+ }
+
+ public void setTextHover(ITextHover p0, String p1) {
+ }
+
+ /**
+ * @see ITextViewer#activatePlugins()
+ */
+ public void activatePlugins() {
+ }
+
+ /**
+ * @see ITextViewer#resetPlugins()
+ */
+ public void resetPlugins() {
+ }
+
+ /**
+ * @see ITextViewer#getTopInset()
+ */
+ public int getTopInset() {
+ return 0;
+ }
+
+ /**
+ * @see ITextViewer#getBottomIndexEndOffset()
+ */
+ public int getBottomIndexEndOffset() {
+ return 0;
+ }
+
+ /**
+ * @see ITextViewer#getBottomIndex()
+ */
+ public int getBottomIndex() {
+ return 0;
+ }
+
+ /**
+ * @see ITextViewer#getTopIndexStartOffset()
+ */
+ public int getTopIndexStartOffset() {
+ return 0;
+ }
+
+ /**
+ * @see ITextViewer#getTopIndex()
+ */
+ public int getTopIndex() {
+ return 0;
+ }
+
+ /**
+ * @see ITextViewer#setTopIndex(int)
+ */
+ public void setTopIndex(int p0) {
+ }
+
+ /**
+ * @see ITextViewer#revealRange(int, int)
+ */
+ public void revealRange(int p0, int p1) {
+ }
+
+ /**
+ * @see ITextViewer#getSelectedRange()
+ */
+ public Point getSelectedRange() {
+ return fSelection;
+ }
+
+ /**
+ * @see ITextViewer#setSelectedRange(int, int)
+ */
+ public void setSelectedRange(int offset, int length) {
+ fSelection.x= offset;
+ fSelection.y= length;
+ }
+
+ /**
+ * @see ITextViewer#isEditable()
+ */
+ public boolean isEditable() {
+ return true;
+ }
+
+ /**
+ * @see ITextViewer#setEditable(boolean)
+ */
+ public void setEditable(boolean p0) {
+ }
+
+ /**
+ * @see ITextViewer#setEventConsumer(IEventConsumer)
+ */
+ public void setEventConsumer(IEventConsumer p0) {
+ }
+
+ /**
+ * @see ITextViewer#removeTextListener(ITextListener)
+ */
+ public void removeTextListener(ITextListener listener) {
+ fTextListeners.remove(listener);
+ }
+
+ protected void fireTextChanged(TextEvent event) {
+ Iterator e= new ArrayList(fTextListeners).iterator();
+ while (e.hasNext()) {
+ ITextListener l= (ITextListener) e.next();
+ l.textChanged(event);
+ }
+ }
+
+ /**
+ * @see ITextViewer#addTextListener(ITextListener)
+ */
+ public void addTextListener(ITextListener listener) {
+ if (!fTextListeners.contains(listener))
+ fTextListeners.add(listener);
+ }
+
+ /**
+ * @see ITextViewer#removeViewportListener(IViewportListener)
+ */
+ public void removeViewportListener(IViewportListener p0) {
+ }
+
+ /**
+ * @see ITextViewer#addViewportListener(IViewportListener)
+ */
+ public void addViewportListener(IViewportListener p0) {
+ }
+
+ /**
+ * @see ISourceViewer#getSelectionProvider()
+ */
+ public ISelectionProvider getSelectionProvider() {
+ return null;
+ }
+
+ /**
+ * @see ISourceViewer#showAnnotations(boolean)
+ */
+ public void showAnnotations(boolean p0) {
+ }
+
+ /**
+ * @see ISourceViewer#removeRangeIndication()
+ */
+ public void removeRangeIndication() {
+ }
+
+ /**
+ * @see ISourceViewer#getRangeIndication()
+ */
+ public IRegion getRangeIndication() {
+ return null;
+ }
+
+ /**
+ * @see ISourceViewer#setRangeIndication(int, int, boolean)
+ */
+ public void setRangeIndication(int p0, int p1, boolean p2) {
+ }
+
+ /**
+ * @see ISourceViewer#setRangeIndicator(Annotation)
+ */
+ public void setRangeIndicator(Annotation p0) {
+ }
+
+ /**
+ * @see ISourceViewer#getAnnotationModel()
+ */
+ public IAnnotationModel getAnnotationModel() {
+ return null;
+ }
+
+ /**
+ * @see ISourceViewer#setDocument(IDocument, IAnnotationModel, int, int)
+ */
+ public void setDocument(IDocument p0, IAnnotationModel p1, int p2, int p3) {
+ }
+
+ /**
+ * @see ISourceViewer#setDocument(IDocument, IAnnotationModel)
+ */
+ public void setDocument(IDocument p0, IAnnotationModel p1) {
+ }
+
+ /**
+ * @see ISourceViewer#setAnnotationHover(IAnnotationHover)
+ */
+ public void setAnnotationHover(IAnnotationHover p0) {
+ }
+
+ /**
+ * @see ISourceViewer#configure(SourceViewerConfiguration)
+ */
+ public void configure(SourceViewerConfiguration p0) {
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TextHoverPopupTest.java b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TextHoverPopupTest.java
new file mode 100644
index 000000000..ecb93b13d
--- /dev/null
+++ b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TextHoverPopupTest.java
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jface.text.tests;
+
+import junit.awtui.TestRunner;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+
+public class TextHoverPopupTest extends TestCase {
+
+
+ public TextHoverPopupTest(String name) {
+ super(name);
+ }
+
+ public static void main(String args[]) {
+ String a[] = { "org.eclipse.jface.text.tests.TextHoverPopupTest" };
+ TestRunner.main(a);
+ }
+
+ protected void setUp() {
+ }
+
+ public static Test suite() {
+ return new TestSuite(TextHoverPopupTest.class);
+ }
+
+ protected void tearDown() {
+ }
+
+
+ protected int search(int[] array, int x) {
+ int low= 0;
+ int high= array.length -1;
+
+ while (high > low) {
+ int offset= (low + high) / 2;
+ int lookup= array[offset];
+ if (lookup > x)
+ high= offset - 1;
+ else if (lookup < x)
+ low= offset + 1;
+ else
+ low= high= offset;
+ }
+
+ return high;
+ }
+
+ public void testSearch() {
+ int[] values= { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
+ for (int i= 0; i < 10; i++) {
+ int result= search(values, i);
+ assertTrue(i == result);
+ }
+
+ int[] values2= { 0, 3, 6, 9, 12, 15, 18, 21, 24, 27 };
+ for (int i= 0; i < 10; i++) {
+ int result= search(values2, i * 3);
+ assertTrue(i == result);
+ }
+ }
+}
diff --git a/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TextPresentationTest.java b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TextPresentationTest.java
new file mode 100644
index 000000000..0b8348bf9
--- /dev/null
+++ b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TextPresentationTest.java
@@ -0,0 +1,572 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jface.text.tests;
+
+import java.util.Iterator;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyleRange;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.widgets.Display;
+
+import org.eclipse.jface.text.Region;
+import org.eclipse.jface.text.TextPresentation;
+
+public class TextPresentationTest extends TestCase {
+
+ private static final int NORMAL= SWT.NORMAL;
+ private static final int BOLD= SWT.BOLD;
+// private static final int ITALIC= SWT.ITALIC;
+
+ private TextPresentation fTextPresentation;
+ private StyleRange[] fAllRanges;
+ private StyleRange[] fNonDefaultRanges;
+
+ public static Test suite() {
+ return new TestSuite(TextPresentationTest.class);
+ }
+
+ protected void setUp() {
+ setUpStyleRanges();
+ setUpTextPresentation();
+ }
+
+ private void setUpStyleRanges() {
+ fAllRanges= new StyleRange[] {
+ createStyleRange( 0, 4, NORMAL),
+ createStyleRange( 4, 20, BOLD),
+ createStyleRange( 20, 47, NORMAL),
+ createStyleRange( 47, 54, BOLD),
+ createStyleRange( 54, 96, NORMAL),
+ createStyleRange( 96, 102, BOLD),
+ createStyleRange(102, 140, NORMAL)
+ };
+
+ fNonDefaultRanges= new StyleRange[] {
+ createStyleRange( 4, 20, BOLD),
+ createStyleRange( 47, 54, BOLD),
+ createStyleRange( 96, 102, BOLD)
+ };
+ }
+
+ private void setUpTextPresentation() {
+ fTextPresentation= new TextPresentation();
+ fTextPresentation.setDefaultStyleRange(createStyleRange(0, 140, NORMAL));
+ for (int i= 0; i < fAllRanges.length; i++)
+ fTextPresentation.addStyleRange(fAllRanges[i]);
+ }
+
+ /**
+ * @param end is exclusive
+ */
+ private StyleRange createStyleRange(int start, int end, int style) {
+ return createStyleRange(start, end, null, null, style);
+ }
+
+ /**
+ * @param end is exclusive
+ */
+ private StyleRange createStyleRange(int start, int end, Color foreground, Color background, int style) {
+ return new StyleRange(start, end - start, foreground, background, style);
+ }
+
+ /**
+ * @param end is exclusive
+ */
+ private StyleRange createStyleRange(int start, int end, int foreground, int background, int style) {
+ return createStyleRange(start, end, createColor(foreground, foreground, foreground), createColor(background, background, background), style);
+ }
+
+ private static Display fDisplay= new Display();
+
+ /**
+ * @return <code>null</code> if any of the parameters is smaller than 0 or greater than 255
+ */
+ private Color createColor(int red, int green, int blue) {
+ if (red < 0 || red > 255 || green < 0 || green > 255 || blue < 0 || blue > 255)
+ return null;
+ return new Color(fDisplay, red, green, blue);
+ }
+
+ private void checkRegions(StyleRange[] expectedAllRanges, StyleRange[] expectedNonDefaultRanges) {
+ Iterator e= fTextPresentation.getAllStyleRangeIterator();
+ for (int i= 0; i < expectedAllRanges.length; i++) {
+ assertTrue(e.hasNext());
+ assertEquals(expectedAllRanges[i], e.next());
+ }
+ assertTrue(!e.hasNext());
+
+ e= fTextPresentation.getNonDefaultStyleRangeIterator();
+ for (int i= 0; i < expectedNonDefaultRanges.length; i++) {
+ assertTrue(e.hasNext());
+ assertEquals(expectedNonDefaultRanges[i], e.next());
+ }
+ assertTrue(!e.hasNext());
+ }
+
+ public void testUnclippedRegions() {
+ checkRegions(fAllRanges, fNonDefaultRanges);
+ }
+
+ public void testClippedRegions1() {
+ fTextPresentation.setResultWindow(new Region(0, 140));
+ checkRegions(fAllRanges, fNonDefaultRanges);
+ }
+
+ public void testClippedRegions2() {
+
+ fTextPresentation.setResultWindow(new Region(30, 70));
+
+ StyleRange[] expectedAllRanges= new StyleRange[] {
+ createStyleRange( 0, 17, NORMAL),
+ createStyleRange( 17, 24, BOLD),
+ createStyleRange( 24, 66, NORMAL),
+ createStyleRange( 66, 70, BOLD)
+ };
+
+ StyleRange[] expectedNonDefaultRanges= new StyleRange[] {
+ createStyleRange( 17, 24, BOLD),
+ createStyleRange( 66, 70, BOLD)
+ };
+
+ checkRegions(expectedAllRanges, expectedNonDefaultRanges);
+ }
+
+ /**
+ * Merge range at start of first existing range.
+ */
+ public void testMergeStyleRange1() {
+ StyleRange range= createStyleRange(0, 2, 1, -1, NORMAL);
+ fTextPresentation.mergeStyleRange(range);
+
+ StyleRange[] expectedAllRanges= new StyleRange[] {
+ createStyleRange(0, 2, 1, -1, NORMAL),
+ createStyleRange( 2, 4, NORMAL),
+ createStyleRange( 4, 20, BOLD),
+ createStyleRange( 20, 47, NORMAL),
+ createStyleRange( 47, 54, BOLD),
+ createStyleRange( 54, 96, NORMAL),
+ createStyleRange( 96, 102, BOLD),
+ createStyleRange(102, 140, NORMAL),
+ };
+
+ StyleRange[] expectedNonDefaultRanges= new StyleRange[] {
+ createStyleRange(0, 2, 1, -1, NORMAL),
+ createStyleRange( 4, 20, BOLD),
+ createStyleRange( 47, 54, BOLD),
+ createStyleRange( 96, 102, BOLD),
+ };
+
+ checkRegions(expectedAllRanges, expectedNonDefaultRanges);
+ }
+
+ /**
+ * Merge range at end of last existing range.
+ */
+ public void testMergeStyleRange2() {
+ StyleRange range= createStyleRange(138, 140, 1, -1, NORMAL);
+ fTextPresentation.mergeStyleRange(range);
+
+ StyleRange[] expectedAllRanges= new StyleRange[] {
+ createStyleRange( 0, 4, NORMAL),
+ createStyleRange( 4, 20, BOLD),
+ createStyleRange( 20, 47, NORMAL),
+ createStyleRange( 47, 54, BOLD),
+ createStyleRange( 54, 96, NORMAL),
+ createStyleRange( 96, 102, BOLD),
+ createStyleRange(102, 138, NORMAL),
+ createStyleRange(138, 140, 1, -1, NORMAL),
+ };
+
+ StyleRange[] expectedNonDefaultRanges= new StyleRange[] {
+ createStyleRange( 4, 20, BOLD),
+ createStyleRange( 47, 54, BOLD),
+ createStyleRange( 96, 102, BOLD),
+ createStyleRange(138, 140, 1, -1, NORMAL),
+ };
+
+ checkRegions(expectedAllRanges, expectedNonDefaultRanges);
+ }
+
+ /**
+ * Merge range at start of existing default range.
+ */
+ public void testMergeStyleRange3() {
+ StyleRange range= createStyleRange(20, 22, 1, -1, NORMAL);
+ fTextPresentation.mergeStyleRange(range);
+
+ StyleRange[] expectedAllRanges= new StyleRange[] {
+ createStyleRange( 0, 4, NORMAL),
+ createStyleRange( 4, 20, BOLD),
+ createStyleRange(20, 22, 1, -1, NORMAL),
+ createStyleRange( 22, 47, NORMAL),
+ createStyleRange( 47, 54, BOLD),
+ createStyleRange( 54, 96, NORMAL),
+ createStyleRange( 96, 102, BOLD),
+ createStyleRange(102, 140, NORMAL),
+ };
+
+ StyleRange[] expectedNonDefaultRanges= new StyleRange[] {
+ createStyleRange( 4, 20, BOLD),
+ createStyleRange(20, 22, 1, -1, NORMAL),
+ createStyleRange( 47, 54, BOLD),
+ createStyleRange( 96, 102, BOLD),
+ };
+
+ checkRegions(expectedAllRanges, expectedNonDefaultRanges);
+ }
+
+ /**
+ * Merge range within existing default range.
+ */
+ public void testMergeStyleRange4() {
+ StyleRange range= createStyleRange(22, 24, 1, -1, NORMAL);
+ fTextPresentation.mergeStyleRange(range);
+
+ StyleRange[] expectedAllRanges= new StyleRange[] {
+ createStyleRange( 0, 4, NORMAL),
+ createStyleRange( 4, 20, BOLD),
+ createStyleRange( 20, 22, NORMAL),
+ createStyleRange(22, 24, 1, -1, NORMAL),
+ createStyleRange( 24, 47, NORMAL),
+ createStyleRange( 47, 54, BOLD),
+ createStyleRange( 54, 96, NORMAL),
+ createStyleRange( 96, 102, BOLD),
+ createStyleRange(102, 140, NORMAL),
+ };
+
+ StyleRange[] expectedNonDefaultRanges= new StyleRange[] {
+ createStyleRange( 4, 20, BOLD),
+ createStyleRange(22, 24, 1, -1, NORMAL),
+ createStyleRange( 47, 54, BOLD),
+ createStyleRange( 96, 102, BOLD),
+ };
+
+ checkRegions(expectedAllRanges, expectedNonDefaultRanges);
+ }
+
+ /**
+ * Merge range at end of existing default range.
+ */
+ public void testMergeStyleRange5() {
+ StyleRange range= createStyleRange(45, 47, 1, -1, NORMAL);
+ fTextPresentation.mergeStyleRange(range);
+
+ StyleRange[] expectedAllRanges= new StyleRange[] {
+ createStyleRange( 0, 4, NORMAL),
+ createStyleRange( 4, 20, BOLD),
+ createStyleRange( 20, 45, NORMAL),
+ createStyleRange(45, 47, 1, -1, NORMAL),
+ createStyleRange( 47, 54, BOLD),
+ createStyleRange( 54, 96, NORMAL),
+ createStyleRange( 96, 102, BOLD),
+ createStyleRange(102, 140, NORMAL),
+ };
+
+ StyleRange[] expectedNonDefaultRanges= new StyleRange[] {
+ createStyleRange( 4, 20, BOLD),
+ createStyleRange(45, 47, 1, -1, NORMAL),
+ createStyleRange( 47, 54, BOLD),
+ createStyleRange( 96, 102, BOLD),
+ };
+
+ checkRegions(expectedAllRanges, expectedNonDefaultRanges);
+ }
+
+ /**
+ * Merge range at start of existing non-default range.
+ */
+ public void testMergeStyleRange6() {
+ StyleRange range= createStyleRange(47, 49, 1, -1, NORMAL);
+ fTextPresentation.mergeStyleRange(range);
+
+ StyleRange[] expectedAllRanges= new StyleRange[] {
+ createStyleRange( 0, 4, NORMAL),
+ createStyleRange( 4, 20, BOLD),
+ createStyleRange( 20, 47, NORMAL),
+ createStyleRange(47, 49, 1, -1, BOLD),
+ createStyleRange( 49, 54, BOLD),
+ createStyleRange( 54, 96, NORMAL),
+ createStyleRange( 96, 102, BOLD),
+ createStyleRange(102, 140, NORMAL),
+ };
+
+ StyleRange[] expectedNonDefaultRanges= new StyleRange[] {
+ createStyleRange( 4, 20, BOLD),
+ createStyleRange(47, 49, 1, -1, BOLD),
+ createStyleRange( 49, 54, BOLD),
+ createStyleRange( 96, 102, BOLD),
+ };
+
+ checkRegions(expectedAllRanges, expectedNonDefaultRanges);
+ }
+
+ /**
+ * Merge range within existing non-default range.
+ */
+ public void testMergeStyleRange7() {
+ StyleRange range= createStyleRange(49, 51, 1, -1, NORMAL);
+ fTextPresentation.mergeStyleRange(range);
+
+ StyleRange[] expectedAllRanges= new StyleRange[] {
+ createStyleRange( 0, 4, NORMAL),
+ createStyleRange( 4, 20, BOLD),
+ createStyleRange( 20, 47, NORMAL),
+ createStyleRange( 47, 49, BOLD),
+ createStyleRange(49, 51, 1, -1, BOLD),
+ createStyleRange( 51, 54, BOLD),
+ createStyleRange( 54, 96, NORMAL),
+ createStyleRange( 96, 102, BOLD),
+ createStyleRange(102, 140, NORMAL),
+ };
+
+ StyleRange[] expectedNonDefaultRanges= new StyleRange[] {
+ createStyleRange( 4, 20, BOLD),
+ createStyleRange( 47, 49, BOLD),
+ createStyleRange(49, 51, 1, -1, BOLD),
+ createStyleRange( 51, 54, BOLD),
+ createStyleRange( 96, 102, BOLD),
+ };
+
+ checkRegions(expectedAllRanges, expectedNonDefaultRanges);
+ }
+
+ /**
+ * Merge range at end of existing non-default range.
+ */
+ public void testMergeStyleRange8() {
+ StyleRange range= createStyleRange(52, 54, 1, -1, NORMAL);
+ fTextPresentation.mergeStyleRange(range);
+
+ StyleRange[] expectedAllRanges= new StyleRange[] {
+ createStyleRange( 0, 4, NORMAL),
+ createStyleRange( 4, 20, BOLD),
+ createStyleRange( 20, 47, NORMAL),
+ createStyleRange( 47, 52, BOLD),
+ createStyleRange(52, 54, 1, -1, BOLD),
+ createStyleRange( 54, 96, NORMAL),
+ createStyleRange( 96, 102, BOLD),
+ createStyleRange(102, 140, NORMAL),
+ };
+
+ StyleRange[] expectedNonDefaultRanges= new StyleRange[] {
+ createStyleRange( 4, 20, BOLD),
+ createStyleRange( 47, 52, BOLD),
+ createStyleRange(52, 54, 1, -1, BOLD),
+ createStyleRange( 96, 102, BOLD),
+ };
+
+ checkRegions(expectedAllRanges, expectedNonDefaultRanges);
+ }
+
+ /**
+ * Merge range from existing default to non-default range.
+ */
+ public void testMergeStyleRange9() {
+ StyleRange range= createStyleRange(45, 49, 1, -1, NORMAL);
+ fTextPresentation.mergeStyleRange(range);
+
+ StyleRange[] expectedAllRanges= new StyleRange[] {
+ createStyleRange( 0, 4, NORMAL),
+ createStyleRange( 4, 20, BOLD),
+ createStyleRange( 20, 45, NORMAL),
+ createStyleRange(45, 47, 1, -1, NORMAL),
+ createStyleRange(47, 49, 1, -1, BOLD),
+ createStyleRange( 49, 54, BOLD),
+ createStyleRange( 54, 96, NORMAL),
+ createStyleRange( 96, 102, BOLD),
+ createStyleRange(102, 140, NORMAL),
+ };
+
+ StyleRange[] expectedNonDefaultRanges= new StyleRange[] {
+ createStyleRange( 4, 20, BOLD),
+ createStyleRange(45, 47, 1, -1, NORMAL),
+ createStyleRange(47, 49, 1, -1, BOLD),
+ createStyleRange( 49, 54, BOLD),
+ createStyleRange( 96, 102, BOLD),
+ };
+
+ checkRegions(expectedAllRanges, expectedNonDefaultRanges);
+ }
+
+ /**
+ * Merge range from existing non-default to default range.
+ */
+ public void testMergeStyleRange10() {
+ StyleRange range= createStyleRange(52, 56, 1, -1, NORMAL);
+ fTextPresentation.mergeStyleRange(range);
+
+ StyleRange[] expectedAllRanges= new StyleRange[] {
+ createStyleRange( 0, 4, NORMAL),
+ createStyleRange( 4, 20, BOLD),
+ createStyleRange( 20, 47, NORMAL),
+ createStyleRange( 47, 52, BOLD),
+ createStyleRange(52, 54, 1, -1, BOLD),
+ createStyleRange(54, 56, 1, -1, NORMAL),
+ createStyleRange( 56, 96, NORMAL),
+ createStyleRange( 96, 102, BOLD),
+ createStyleRange(102, 140, NORMAL),
+ };
+
+ StyleRange[] expectedNonDefaultRanges= new StyleRange[] {
+ createStyleRange( 4, 20, BOLD),
+ createStyleRange( 47, 52, BOLD),
+ createStyleRange(52, 54, 1, -1, BOLD),
+ createStyleRange(54, 56, 1, -1, NORMAL),
+ createStyleRange( 96, 102, BOLD),
+ };
+
+ checkRegions(expectedAllRanges, expectedNonDefaultRanges);
+ }
+
+ /**
+ * Merge range from existing default over non-default to default range.
+ */
+ public void testMergeStyleRange11() {
+ StyleRange range= createStyleRange(45, 56, 1, -1, NORMAL);
+ fTextPresentation.mergeStyleRange(range);
+
+ StyleRange[] expectedAllRanges= new StyleRange[] {
+ createStyleRange( 0, 4, NORMAL),
+ createStyleRange( 4, 20, BOLD),
+ createStyleRange( 20, 45, NORMAL),
+ createStyleRange(45, 47, 1, -1, NORMAL),
+ createStyleRange(47, 54, 1, -1, BOLD),
+ createStyleRange(54, 56, 1, -1, NORMAL),
+ createStyleRange( 56, 96, NORMAL),
+ createStyleRange( 96, 102, BOLD),
+ createStyleRange(102, 140, NORMAL),
+ };
+
+ StyleRange[] expectedNonDefaultRanges= new StyleRange[] {
+ createStyleRange( 4, 20, BOLD),
+ createStyleRange(45, 47, 1, -1, NORMAL),
+ createStyleRange(47, 54, 1, -1, BOLD),
+ createStyleRange(54, 56, 1, -1, NORMAL),
+ createStyleRange( 96, 102, BOLD),
+ };
+
+ checkRegions(expectedAllRanges, expectedNonDefaultRanges);
+ }
+
+ /**
+ * Merge range from existing non-default over default to non-default range.
+ */
+ public void testMergeStyleRange12() {
+ StyleRange range= createStyleRange(52, 98, 1, -1, NORMAL);
+ fTextPresentation.mergeStyleRange(range);
+
+ StyleRange[] expectedAllRanges= new StyleRange[] {
+ createStyleRange( 0, 4, NORMAL),
+ createStyleRange( 4, 20, BOLD),
+ createStyleRange( 20, 47, NORMAL),
+ createStyleRange( 47, 52, BOLD),
+ createStyleRange(52, 54, 1, -1, BOLD),
+ createStyleRange(54, 96, 1, -1, NORMAL),
+ createStyleRange(96, 98, 1, -1, BOLD),
+ createStyleRange( 98, 102, BOLD),
+ createStyleRange(102, 140, NORMAL),
+ };
+
+ StyleRange[] expectedNonDefaultRanges= new StyleRange[] {
+ createStyleRange( 4, 20, BOLD),
+ createStyleRange( 47, 52, BOLD),
+ createStyleRange(52, 54, 1, -1, BOLD),
+ createStyleRange(54, 96, 1, -1, NORMAL),
+ createStyleRange(96, 98, 1, -1, BOLD),
+ createStyleRange( 98, 102, BOLD),
+ };
+
+ checkRegions(expectedAllRanges, expectedNonDefaultRanges);
+ }
+
+ /**
+ * Merge range over existing default range.
+ */
+ public void testMergeStyleRange13() {
+ StyleRange range= createStyleRange(20, 47, 1, -1, NORMAL);
+ fTextPresentation.mergeStyleRange(range);
+
+ StyleRange[] expectedAllRanges= new StyleRange[] {
+ createStyleRange( 0, 4, NORMAL),
+ createStyleRange( 4, 20, BOLD),
+ createStyleRange(20, 47, 1, -1, NORMAL),
+ createStyleRange( 47, 54, BOLD),
+ createStyleRange( 54, 96, NORMAL),
+ createStyleRange( 96, 102, BOLD),
+ createStyleRange(102, 140, NORMAL),
+ };
+
+ StyleRange[] expectedNonDefaultRanges= new StyleRange[] {
+ createStyleRange( 4, 20, BOLD),
+ createStyleRange(20, 47, 1, -1, NORMAL),
+ createStyleRange( 47, 54, BOLD),
+ createStyleRange( 96, 102, BOLD),
+ };
+
+ checkRegions(expectedAllRanges, expectedNonDefaultRanges);
+ }
+
+ /**
+ * Merge range over existing non-default range.
+ */
+ public void testMergeStyleRange14() {
+ StyleRange range= createStyleRange(47, 54, 1, -1, NORMAL);
+ fTextPresentation.mergeStyleRange(range);
+
+ StyleRange[] expectedAllRanges= new StyleRange[] {
+ createStyleRange( 0, 4, NORMAL),
+ createStyleRange( 4, 20, BOLD),
+ createStyleRange( 20, 47, NORMAL),
+ createStyleRange(47, 54, 1, -1, BOLD),
+ createStyleRange( 54, 96, NORMAL),
+ createStyleRange( 96, 102, BOLD),
+ createStyleRange(102, 140, NORMAL),
+ };
+
+ StyleRange[] expectedNonDefaultRanges= new StyleRange[] {
+ createStyleRange( 4, 20, BOLD),
+ createStyleRange(47, 54, 1, -1, BOLD),
+ createStyleRange( 96, 102, BOLD),
+ };
+
+ checkRegions(expectedAllRanges, expectedNonDefaultRanges);
+ }
+
+// Template
+//
+// public void testMergeStyleRange0() {
+//// StyleRange range= createStyleRange(0, 2, 1, -1, NORMAL);
+//// fTextPresentation.mergeStyleRange(range);
+//
+// StyleRange[] expectedAllRanges= new StyleRange[] {
+// createStyleRange( 0, 4, NORMAL),
+// createStyleRange( 4, 20, BOLD),
+// createStyleRange( 20, 47, NORMAL),
+// createStyleRange( 47, 54, BOLD),
+// createStyleRange( 54, 96, NORMAL),
+// createStyleRange( 96, 102, BOLD),
+// createStyleRange(102, 140, NORMAL),
+// };
+//
+// StyleRange[] expectedNonDefaultRanges= new StyleRange[] {
+// createStyleRange( 4, 20, BOLD),
+// createStyleRange( 47, 54, BOLD),
+// createStyleRange( 96, 102, BOLD),
+// };
+//
+// checkRegions(expectedAllRanges, expectedNonDefaultRanges);
+// }
+}
diff --git a/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TextUtilitiesTest.java b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TextUtilitiesTest.java
new file mode 100644
index 000000000..37154402d
--- /dev/null
+++ b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TextUtilitiesTest.java
@@ -0,0 +1,277 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jface.text.tests;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import junit.framework.Assert;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.Document;
+import org.eclipse.jface.text.DocumentEvent;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IDocumentListener;
+import org.eclipse.jface.text.TextUtilities;
+
+
+/**
+ * A test case for text utilities.
+ */
+public class TextUtilitiesTest extends TestCase {
+
+ public static Test suite() {
+ return new TestSuite(TextUtilitiesTest.class);
+ }
+
+ /**
+ * A document which is a copy of another document.
+ * Implementation uses old document state.
+ */
+ private static class LazilyMirroredDocument extends Document {
+
+ private final class DocumentListener implements IDocumentListener {
+ public void documentAboutToBeChanged(DocumentEvent event) {}
+ public void documentChanged(DocumentEvent event) {
+ fEvents.add(event);
+ }
+ }
+
+ /** The document listener. */
+ private final DocumentListener fDocumentListener= new DocumentListener();
+
+ /** The buffered events. */
+ private final List fEvents= new ArrayList();
+
+ public LazilyMirroredDocument(IDocument document) {
+ document.addDocumentListener(fDocumentListener);
+ }
+
+ private void flush() throws BadLocationException {
+ DocumentEvent event= TextUtilities.mergeUnprocessedDocumentEvents(this, fEvents);
+ if (event == null)
+ return;
+
+ replace(event.getOffset(), event.getLength(), event.getText());
+ fEvents.clear();
+ }
+
+ /*
+ * Should override all other getXXX() methods as well, but it's sufficient for the test.
+ *
+ * @see org.eclipse.jface.text.IDocument#get()
+ */
+ public String get() {
+ try {
+ flush();
+ } catch (BadLocationException e) {
+ assertFalse(true);
+ }
+ return super.get();
+ }
+ }
+
+ /**
+ * A document which is a copy of another document.
+ * Implementation uses new document state.
+ */
+ private static class LazilyMirroredDocument2 extends Document {
+
+ private final class DocumentListener implements IDocumentListener {
+ public void documentAboutToBeChanged(DocumentEvent event) {}
+ public void documentChanged(DocumentEvent event) {
+ event= new DocumentEvent(event.getDocument(), event.getOffset(), event.getLength(), event.getText());
+ fEvents.add(event);
+ }
+ }
+
+ /** The document listener. */
+ private final DocumentListener fDocumentListener= new DocumentListener();
+
+ /** The buffered events. */
+ private final List fEvents= new ArrayList();
+
+ public LazilyMirroredDocument2(IDocument document) {
+ document.addDocumentListener(fDocumentListener);
+ }
+
+ private void flush() throws BadLocationException {
+ DocumentEvent event= TextUtilities.mergeProcessedDocumentEvents(fEvents);
+ if (event == null)
+ return;
+
+ replace(event.getOffset(), event.getLength(), event.getText());
+ fEvents.clear();
+ }
+
+ /*
+ * Should override all other getXXX() methods as well, but it's sufficient for the test.
+ *
+ * @see org.eclipse.jface.text.IDocument#get()
+ */
+ public String get() {
+ try {
+ flush();
+ } catch (BadLocationException e) {
+ Assert.fail("bad implementation");
+ }
+ return super.get();
+ }
+ }
+
+
+ /**
+ * Constructor for UtilitiesTest.
+ * @param name
+ */
+ public TextUtilitiesTest(String name) {
+ super(name);
+ }
+
+ private static DocumentEvent createRandomEvent(IDocument document, int maxLength, char character) {
+
+ int index0= (int) (Math.random() * (maxLength + 1));
+ int index1= (int) (Math.random() * (maxLength + 1));
+
+ int offset= Math.min(index0, index1);
+ int length= Math.max(index0, index1) - offset;
+
+ int stringLength= (int) (Math.random() * 10);
+ StringBuffer buffer= new StringBuffer(stringLength);
+ for (int i= 0; i < stringLength; ++i)
+ buffer.append(character);
+
+ return new DocumentEvent(document, offset, length, buffer.toString());
+ }
+
+ public void testMergeEvents1() {
+ IDocument reference= new Document();
+ LazilyMirroredDocument testee= new LazilyMirroredDocument(reference);
+
+ try {
+ reference.replace(0, 0, "01234567890123");
+ check(reference, testee);
+
+ reference.replace(4, 3, "moo ");
+ reference.replace(9, 2, "asd");
+ check(reference, testee);
+
+ } catch (BadLocationException e) {
+ Assert.fail("bad location exception");
+ }
+ }
+
+ public void testMergeEvents() {
+ IDocument reference= new Document();
+ LazilyMirroredDocument testee= new LazilyMirroredDocument(reference);
+
+ try {
+
+ List events= new ArrayList();
+ int currentLength= 0;
+
+ events.add(new DocumentEvent(reference, 0, 0, "foo bar goo haa"));
+ events.add(new DocumentEvent(reference, 0, "foo bar goo haa".length(), "foo bar goo haa"));
+ events.add(new DocumentEvent(reference, 4, 4, "xxxx"));
+ events.add(new DocumentEvent(reference, 4, 4, "yyy"));
+ events.add(new DocumentEvent(reference, 4, 3, "moo "));
+ events.add(new DocumentEvent(reference, 9, 2, "asd"));
+ events.add(new DocumentEvent(reference, 0, 2, "asd"));
+
+ for (Iterator iterator= events.iterator(); iterator.hasNext();) {
+ DocumentEvent event= (DocumentEvent) iterator.next();
+ currentLength += event.getText().length() - event.getLength();
+ }
+
+ for (int i= 0; i < 500; i++) {
+ char character= (char) (32 + i % 95);
+ DocumentEvent event= createRandomEvent(reference, currentLength, character);
+ currentLength += event.getText().length() - event.getLength();
+ events.add(event);
+ }
+
+ for (Iterator iterator= events.iterator(); iterator.hasNext();) {
+ DocumentEvent event= (DocumentEvent) iterator.next();
+
+// System.err.println(event.getOffset() + ", " + event.getLength() + ", [" + event.getText() + "]") ;
+
+ reference.replace(event.getOffset(), event.getLength(), event.getText());
+ if (Math.random() < 0.3) {
+// System.err.println("check");
+ check(reference, testee);
+// System.err.println("length = " + reference.getLength());
+ }
+ }
+
+ check(reference, testee);
+
+// System.out.println("[" + reference.get() + "]");
+// System.out.println("[" + testee.get() + "]");
+
+ } catch (BadLocationException e) {
+ Assert.fail("bad location exception");
+ }
+ }
+
+ public void testMergeEvents2() {
+ IDocument reference= new Document();
+ LazilyMirroredDocument2 testee= new LazilyMirroredDocument2(reference);
+
+ try {
+
+ List events= new ArrayList();
+ int currentLength= 0;
+
+ events.add(new DocumentEvent(reference, 0, 0, "foo bar goo haa"));
+ events.add(new DocumentEvent(reference, 0, "foo bar goo haa".length(), "foo bar goo haa"));
+ events.add(new DocumentEvent(reference, 4, 4, "xxxx"));
+ events.add(new DocumentEvent(reference, 4, 4, "yyy"));
+ events.add(new DocumentEvent(reference, 4, 3, "moo "));
+ events.add(new DocumentEvent(reference, 9, 2, "asd"));
+ events.add(new DocumentEvent(reference, 0, 2, "asd"));
+
+ for (Iterator iterator= events.iterator(); iterator.hasNext();) {
+ DocumentEvent event= (DocumentEvent) iterator.next();
+ currentLength += event.getText().length() - event.getLength();
+ }
+
+ for (int i= 0; i < 500; i++) {
+ char character= (char) (32 + i % 95);
+ DocumentEvent event= createRandomEvent(reference, currentLength, character);
+ currentLength += event.getText().length() - event.getLength();
+ events.add(event);
+ }
+
+ for (Iterator iterator= events.iterator(); iterator.hasNext();) {
+ DocumentEvent event= (DocumentEvent) iterator.next();
+
+ reference.replace(event.getOffset(), event.getLength(), event.getText());
+ if (Math.random() < 0.3) {
+ check(reference, testee);
+ }
+ }
+
+ check(reference, testee);
+
+ } catch (BadLocationException e) {
+ Assert.fail("bad location exception");
+ }
+ }
+
+ private static void check(IDocument reference, IDocument testee) throws BadLocationException {
+ Assert.assertEquals(reference.get(), testee.get());
+ }
+
+}
diff --git a/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/UndoManagerTest.java b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/UndoManagerTest.java
new file mode 100644
index 000000000..17959a298
--- /dev/null
+++ b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/UndoManagerTest.java
@@ -0,0 +1,218 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jface.text.tests;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Shell;
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.DefaultUndoManager;
+import org.eclipse.jface.text.Document;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.IUndoManager;
+import org.eclipse.jface.text.Position;
+import org.eclipse.jface.text.TextViewer;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Test for DefaultUndoManager
+ */
+public class UndoManagerTest extends TestCase {
+
+ /** The maximum undo level. */
+ private static final int MAX_UNDO_LEVEL = 256;
+
+ /** The shell. */
+ private Shell fShell;
+ /** The text viewer. */
+ private ITextViewer fTextViewer;
+ /** The undo manager. */
+ private IUndoManager fUndoManager;
+
+ public static Test suite() {
+ return new TestSuite(UndoManagerTest.class);
+ }
+
+ /*
+ * @see TestCase#TestCase(String)
+ */
+ public UndoManagerTest(final String name) {
+ super(name);
+ }
+
+ /*
+ * @see TestCase#setUp()
+ */
+ protected void setUp() {
+ fShell = new Shell();
+ fUndoManager = new DefaultUndoManager(MAX_UNDO_LEVEL);
+ fTextViewer = new TextViewer(fShell, SWT.NONE);
+ fTextViewer.setUndoManager(fUndoManager);
+ fUndoManager.connect(fTextViewer);
+ }
+
+ /**
+ * Test for line delimiter conversion.
+ */
+ public void testConvertLineDelimiters() {
+ final String original= "a\r\nb\r\n";
+ final IDocument document= new Document(original);
+ fTextViewer.setDocument(document);
+
+ try {
+ document.replace(1, 2, "\n");
+ document.replace(3, 2, "\n");
+ } catch (BadLocationException e) {
+ assertTrue(false);
+ }
+
+ assertTrue(fUndoManager.undoable());
+ fUndoManager.undo();
+ assertTrue(fUndoManager.undoable());
+ fUndoManager.undo();
+
+ final String reverted= document.get();
+
+ assertEquals(original, reverted);
+ }
+
+ /**
+ * Randomly applies document changes.
+ */
+ public void testRandomAccess() {
+ final int RANDOM_STRING_LENGTH= 50;
+ final int RANDOM_REPLACE_COUNT= 100;
+
+ assertTrue(RANDOM_REPLACE_COUNT >= 1);
+ assertTrue(RANDOM_REPLACE_COUNT <= MAX_UNDO_LEVEL);
+
+ String original= createRandomString(RANDOM_STRING_LENGTH);
+ final IDocument document= new Document(original);
+ fTextViewer.setDocument(document);
+
+ doChange(document, RANDOM_REPLACE_COUNT);
+
+ assertTrue(fUndoManager.undoable());
+ while (fUndoManager.undoable())
+ fUndoManager.undo();
+
+ final String reverted= document.get();
+
+ assertEquals(original, reverted);
+ }
+
+ private void doChange(IDocument document, int count) {
+ try {
+ for (int i= 0; i < count; i++) {
+ final Position position= createRandomPositionPoisson(document.getLength());
+ final String string= createRandomStringPoisson(4);
+ document.replace(position.getOffset(), position.getLength(), string);
+// System.out.println("replace length = " + position.getLength());
+// System.out.println("string length = " + string.length());
+ }
+ } catch (BadLocationException e) {
+ assertTrue(false);
+ }
+ }
+
+ public void testRandomAccessAsCompound() {
+ final int RANDOM_STRING_LENGTH= 50;
+ final int RANDOM_REPLACE_COUNT= 100;
+
+ assertTrue(RANDOM_REPLACE_COUNT >= 1);
+ assertTrue(RANDOM_REPLACE_COUNT <= MAX_UNDO_LEVEL);
+
+ String original= createRandomString(RANDOM_STRING_LENGTH);
+ final IDocument document= new Document(original);
+ fTextViewer.setDocument(document);
+
+ fUndoManager.beginCompoundChange();
+ doChange(document, RANDOM_REPLACE_COUNT);
+ fUndoManager.endCompoundChange();
+
+ assertTrue(fUndoManager.undoable());
+ while (fUndoManager.undoable())
+ fUndoManager.undo();
+ assertTrue(!fUndoManager.undoable());
+
+ final String reverted= document.get();
+
+ assertEquals(original, reverted);
+ }
+
+ private static String createRandomString(int length) {
+ final StringBuffer buffer= new StringBuffer();
+
+ for (int i= 0; i < length; i++)
+ buffer.append(getRandomCharacter());
+
+ return buffer.toString();
+ }
+
+ private static final char getRandomCharacter() {
+// return Math.random() < 0.5
+// ? '\r'
+// : '\n';
+
+ // XXX must include \r, \n, \t
+ return (char) (32 + 95 * Math.random());
+ }
+
+ private static String createRandomStringPoisson(int mean) {
+ final int length= getRandomPoissonValue(2);
+ return createRandomString(length);
+ }
+
+ private static Position createRandomPositionPoisson(int documentLength) {
+
+ final float random= (float) Math.random();
+ final int offset= (int) (random * (documentLength + 1));
+
+ int length= getRandomPoissonValue(2);
+ if (offset + length > documentLength)
+ length= documentLength - offset;
+
+ return new Position(offset, length);
+ }
+
+ private static int getRandomPoissonValue(int mean) {
+ final int MAX_VALUE= 10;
+
+ final float random= (float) Math.random();
+ float probability= 0;
+ int i= 0;
+ while (probability < 1 && i < MAX_VALUE) {
+ probability += getPoissonDistribution(mean, i);
+ if (random <= probability)
+ break;
+ i++;
+ }
+ return i;
+ }
+
+ private static float getPoissonDistribution(float lambda, int k) {
+ return (float) (Math.exp(-lambda) * Math.pow(lambda, k) / faculty(k));
+ }
+
+ /**
+ * Returns the faculty of k.
+ */
+ private static final int faculty(int k) {
+ return k == 0
+ ? 1
+ : k * faculty(k - 1);
+ }
+
+}

Back to the top