Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorPascal Rapicault2015-08-19 18:03:29 -0400
committerPascal Rapicault2015-09-02 15:46:06 -0400
commite1ecbb6bdbe5d9d8d58d9eaaa16a79d609a6b30c (patch)
tree080b1ef452d76f2ae4745bb02e18db7c86b383f2 /tests
parent7d572cec4c7ccc179d0c13ef44998a8d746148cb (diff)
downloadeclipse.platform.team-e1ecbb6bdbe5d9d8d58d9eaaa16a79d609a6b30c.tar.gz
eclipse.platform.team-e1ecbb6bdbe5d9d8d58d9eaaa16a79d609a6b30c.tar.xz
eclipse.platform.team-e1ecbb6bdbe5d9d8d58d9eaaa16a79d609a6b30c.zip
Bug 475427 - [compare] No syntax highlighting when IDocument is passed
in as input Change-Id: If494d46cf5a4ff969976db649d85665e13d10d19 Signed-off-by: Pascal Rapicault <pascal@rapicorp.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/TextMergeViewerTest.java107
1 files changed, 107 insertions, 0 deletions
diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/TextMergeViewerTest.java b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/TextMergeViewerTest.java
index 171d4ac68..6ef6b4277 100644
--- a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/TextMergeViewerTest.java
+++ b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/TextMergeViewerTest.java
@@ -33,8 +33,12 @@ import org.eclipse.compare.structuremergeviewer.Differencer;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.text.Document;
+import org.eclipse.jface.text.DocumentEvent;
import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IDocumentPartitioner;
import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ITypedRegion;
import org.eclipse.jface.text.Region;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
@@ -461,4 +465,107 @@ public class TextMergeViewerTest extends TestCase {
}
}, cc);
}
+
+
+ public void testDocumentAsTypedElement() throws Exception {
+ class DocumentAsTypedElement extends Document implements ITypedElement {
+
+ public String getName() {
+ return "file";
+ }
+
+ public Image getImage() {
+ return null;
+ }
+
+ public String getType() {
+ return ITypedElement.UNKNOWN_TYPE;
+ }
+ }
+ DiffNode parentNode = new DiffNode(new ParentTestElement(), new ParentTestElement());
+ DocumentAsTypedElement leftDoc = new DocumentAsTypedElement();
+ DocumentAsTypedElement rightDoc = new DocumentAsTypedElement();
+ DiffNode testNode = new DiffNode(parentNode, Differencer.DELETION, null, leftDoc, rightDoc);
+ runInDialogWithPartioner(testNode, new Runnable() {
+ public void run() {
+ //Not needed
+ }
+ }, new CompareConfiguration());
+ assertNotNull(leftDoc.getDocumentPartitioner());
+ assertNotNull(rightDoc.getDocumentPartitioner());
+ }
+
+
+ private void runInDialogWithPartioner(Object input, Runnable runnable, final CompareConfiguration cc) throws Exception {
+ Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
+ Dialog dialog = new Dialog(shell) {
+ protected Control createDialogArea(Composite parent) {
+ Composite composite = (Composite) super.createDialogArea(parent);
+ viewer = new TestMergeViewerWithPartitioner(composite, cc);
+ return composite;
+ }
+ };
+ dialog.setBlockOnOpen(false);
+ dialog.open();
+ viewer.setInput(input);
+ try {
+ runnable.run();
+ } catch (WrappedException e) {
+ e.throwException();
+ }
+ dialog.close();
+ viewer = null;
+ }
+
+ //This viewer is used to provide a dummy partitioner
+ public static class TestMergeViewerWithPartitioner extends TestMergeViewer {
+ public class DummyPartitioner implements IDocumentPartitioner {
+ public void connect(IDocument document) {
+ //Nothing to do
+ }
+
+ public void disconnect() {
+ //Nothing to do
+ }
+
+ public void documentAboutToBeChanged(DocumentEvent event) {
+ //Nothing to do
+ }
+
+ public boolean documentChanged(DocumentEvent event) {
+ return false;
+ }
+
+ public String[] getLegalContentTypes() {
+ return null;
+ }
+
+ public String getContentType(int offset) {
+ return null;
+ }
+
+ public ITypedRegion[] computePartitioning(int offset, int length) {
+ return null;
+ }
+
+ public ITypedRegion getPartition(int offset) {
+ return null;
+ }
+
+ }
+ public TestMergeViewerWithPartitioner(Composite parent) {
+ super(parent, new CompareConfiguration());
+ }
+
+ public TestMergeViewerWithPartitioner(Composite parent, CompareConfiguration cc) {
+ super(parent, cc);
+ }
+
+ public void copy(boolean leftToRight) {
+ super.copy(leftToRight);
+ }
+ protected IDocumentPartitioner getDocumentPartitioner() {
+ return new DummyPartitioner();
+ }
+ }
}

Back to the top