Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Zarna2009-01-26 09:44:27 +0000
committerTomasz Zarna2009-01-26 09:44:27 +0000
commitd455d0965d52f800dd2e24690ec3e5046b70c0ac (patch)
tree5e78355c6d1b5db59a9d80489ed24834d0f12c0b
parent0d45e39d0ac2d4018c3bc67c9f62339ec8bb32c4 (diff)
downloadeclipse.platform.team-d455d0965d52f800dd2e24690ec3e5046b70c0ac.tar.gz
eclipse.platform.team-d455d0965d52f800dd2e24690ec3e5046b70c0ac.tar.xz
eclipse.platform.team-d455d0965d52f800dd2e24690ec3e5046b70c0ac.zip
bug 259422: DocLineComparator behaves ambiguous with empty fileRoot_branch_20090126_LocalDiff
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/DocLineComparator.java39
-rw-r--r--tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/DocLineComparatorTest.java53
2 files changed, 70 insertions, 22 deletions
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/DocLineComparator.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/DocLineComparator.java
index 85f1cbe72..52dff2fbc 100644
--- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/DocLineComparator.java
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/DocLineComparator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * Copyright (c) 2000, 2009 IBM Corporation and others.
* 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
@@ -45,30 +45,27 @@ public class DocLineComparator implements ITokenComparator {
fIgnoreWhiteSpace= ignoreWhiteSpace;
fLineOffset= 0;
- if (region != null) {
- fLength= region.getLength();
- int start= region.getOffset();
+ if (region == null) {
+ region = new Region(0, fDocument.getLength());
+ }
+ fLength= region.getLength();
+ int start= region.getOffset();
+ try {
+ fLineOffset= fDocument.getLineOfOffset(start);
+ } catch (BadLocationException ex) {
+ // silently ignored
+ }
+
+ if (fLength == 0)
+ fLineCount= 0;
+ else {
+ int endLine= fDocument.getNumberOfLines();
try {
- fLineOffset= fDocument.getLineOfOffset(start);
+ endLine= fDocument.getLineOfOffset(start + fLength);
} catch (BadLocationException ex) {
// silently ignored
}
-
- if (fLength == 0)
- fLineCount= 0;
- else {
- int endLine= fDocument.getNumberOfLines();
- try {
- endLine= fDocument.getLineOfOffset(start + fLength);
- } catch (BadLocationException ex) {
- // silently ignored
- }
- fLineCount= endLine - fLineOffset + 1;
- }
-
- } else {
- fLength= document.getLength();
- fLineCount= fDocument.getNumberOfLines();
+ fLineCount= endLine - fLineOffset + 1;
}
}
diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/DocLineComparatorTest.java b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/DocLineComparatorTest.java
index 264d05053..b72cc3f91 100644
--- a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/DocLineComparatorTest.java
+++ b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/DocLineComparatorTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * Copyright (c) 2000, 2009 IBM Corporation and others.
* 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
@@ -17,6 +17,7 @@ import org.eclipse.compare.internal.DocLineComparator;
import org.eclipse.compare.rangedifferencer.IRangeComparator;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.Region;
public class DocLineComparatorTest extends TestCase {
@@ -70,4 +71,54 @@ public class DocLineComparatorTest extends TestCase {
Assert.assertTrue(comp1.rangesEqual(0, comp2, 0));
}
+
+ public void testNoContent() {
+ IDocument doc= new Document();
+
+ IRangeComparator comp1= new DocLineComparator(doc, null, true);
+ IRangeComparator comp2= new DocLineComparator(doc, new Region(0, doc.getLength()), true);
+
+ Assert.assertTrue(comp1.rangesEqual(0, comp2, 0));
+ Assert.assertEquals(comp1.getRangeCount(), comp2.getRangeCount());
+ Assert.assertEquals(0, comp2.getRangeCount());
+ }
+
+ public void testOneLine() {
+ IDocument doc = new Document();
+ doc.set("line1"); //$NON-NLS-1$
+
+ IRangeComparator comp1= new DocLineComparator(doc, null, true);
+ IRangeComparator comp2= new DocLineComparator(doc, new Region(0, doc.getLength()), true);
+
+ Assert.assertEquals(comp1.getRangeCount(), comp2.getRangeCount());
+ Assert.assertEquals(1, comp2.getRangeCount());
+ }
+
+ public void testTwoLines() {
+ IDocument doc = new Document();
+ doc.set("line1\nline2"); //$NON-NLS-1$
+
+ IRangeComparator comp1= new DocLineComparator(doc, null, true);
+ IRangeComparator comp2= new DocLineComparator(doc, new Region(0, doc.getLength()), true);
+
+ Assert.assertEquals(comp1.getRangeCount(), comp2.getRangeCount());
+ Assert.assertEquals(2, comp2.getRangeCount());
+
+ IRangeComparator comp3= new DocLineComparator(doc, new Region(0, "line1".length()), true);
+ Assert.assertEquals(1, comp3.getRangeCount());
+
+ comp3= new DocLineComparator(doc, new Region(0, "line1".length()+1), true);
+ Assert.assertEquals(2, comp3.getRangeCount()); // two lines
+ }
+
+ public void testBug259422() {
+ IDocument doc = new Document();
+ doc.set(""); //$NON-NLS-1$
+
+ IRangeComparator comp1= new DocLineComparator(doc, null, true);
+ IRangeComparator comp2= new DocLineComparator(doc, new Region(0, doc.getLength()), true);
+
+ Assert.assertEquals(comp1.getRangeCount(), comp2.getRangeCount());
+ }
+
}

Back to the top