diff options
author | teicher | 2004-04-20 15:26:55 +0000 |
---|---|---|
committer | teicher | 2004-04-20 15:26:55 +0000 |
commit | 2bec930be293dafa43e9a54f6817f7317c1ecb60 (patch) | |
tree | 1141b0718deb6e3a8e69678e2f73153439b8a0bd /org.eclipse.jface.text.tests | |
parent | 10f953ff47d635e4d0cc47b065994027443f507b (diff) | |
download | eclipse.platform.text-2bec930be293dafa43e9a54f6817f7317c1ecb60.tar.gz eclipse.platform.text-2bec930be293dafa43e9a54f6817f7317c1ecb60.tar.xz eclipse.platform.text-2bec930be293dafa43e9a54f6817f7317c1ecb60.zip |
commiting fix by Christof for wrong zero-length partitioning
Diffstat (limited to 'org.eclipse.jface.text.tests')
2 files changed, 63 insertions, 13 deletions
diff --git a/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/rules/DefaultPartitionerTest.java b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/rules/DefaultPartitionerTest.java index 4b6ad2ad9c2..d19427814ae 100644 --- a/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/rules/DefaultPartitionerTest.java +++ b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/rules/DefaultPartitionerTest.java @@ -135,19 +135,44 @@ public class DefaultPartitionerTest extends TestCase { assertComputePartitioning_InterleavingPartitions(offsets); } + public void testComputePartitioningSubrangeBeforeBoundaries() { + fDoc.set("docu ment/* comment *//* comment */docu ment"); + + int[] offsets= new int[] { 13, 26, 26 }; + assertComputePartitioning_InterleavingPartitions(12, 38, offsets, DEFAULT); + } + + public void testComputePartitioningSubrangeOnBoundaries() { + fDoc.set("docu ment/* comment *//* comment */docu ment"); + + int[] offsets= new int[] { 13, 26, 26, 39 }; + assertComputePartitioning_InterleavingPartitions(13, 39, offsets, DEFAULT); + } + + public void testComputePartitioningSubrangeAfterBoundaries() { + fDoc.set("docu ment/* comment *//* comment */docu ment"); + + int[] offsets= new int[] { 26, 26, 39 }; + assertComputePartitioning_InterleavingPartitions(14, 40, offsets, COMMENT); + } + private void assertComputePartitioning_InterleavingPartitions(int[] offsets) { - ITypedRegion[] regions= fPartitioner.computePartitioning(0, fDoc.getLength()); + assertComputePartitioning_InterleavingPartitions(0, fDoc.getLength(), offsets, DEFAULT); + } + + private void assertComputePartitioning_InterleavingPartitions(int startOffset, int endOffset, int[] offsets, String startType) { + ITypedRegion[] regions= fPartitioner.computePartitioning(startOffset, endOffset - startOffset); - String type= DEFAULT; - int previousOffset= 0; + String type= startType; + int previousOffset= startOffset; int j= 0; for (int i= 0; i <= offsets.length; i++) { - int offset= (i == offsets.length) ? fDoc.getLength() : offsets[i]; - if (offset - previousOffset != 0) { // don't do empty partitions + int currentOffset= (i == offsets.length) ? endOffset : offsets[i]; + if (currentOffset - previousOffset != 0) { // don't do empty partitions ITypedRegion region= regions[j++]; - assertTypedRegion(region, previousOffset, offset, type); + assertTypedRegion(region, previousOffset, currentOffset, type); } // advance @@ -155,7 +180,7 @@ public class DefaultPartitionerTest extends TestCase { type= COMMENT; else type= DEFAULT; - previousOffset= offset; + previousOffset= currentOffset; } } diff --git a/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/rules/DefaultPartitionerZeroLengthTest.java b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/rules/DefaultPartitionerZeroLengthTest.java index 3c00b5a419e..73567aca162 100644 --- a/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/rules/DefaultPartitionerZeroLengthTest.java +++ b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/rules/DefaultPartitionerZeroLengthTest.java @@ -135,25 +135,50 @@ public class DefaultPartitionerZeroLengthTest extends TestCase { assertComputeZeroLengthPartitioning_InterleavingPartitions(offsets); } + public void testComputePartitioningSubrangeBeforeBoundaries() { + fDoc.set("docu ment/* comment *//* comment */docu ment"); + + int[] offsets= new int[] { 13, 26, 26 }; + assertComputeZeroLengthPartitioning_InterleavingPartitions(12, 38, offsets, DEFAULT); + } + + public void testComputePartitioningSubrangeOnBoundaries() { + fDoc.set("docu ment/* comment *//* comment */docu ment"); + + int[] offsets= new int[] { 13, 26, 26, 39 }; + assertComputeZeroLengthPartitioning_InterleavingPartitions(13, 39, offsets, DEFAULT); + } + + public void testComputePartitioningSubrangeAfterBoundaries() { + fDoc.set("docu ment/* comment *//* comment */docu ment"); + + int[] offsets= new int[] { 26, 26, 39 }; + assertComputeZeroLengthPartitioning_InterleavingPartitions(14, 40, offsets, COMMENT); + } + private void assertComputeZeroLengthPartitioning_InterleavingPartitions(int[] offsets) { - ITypedRegion[] regions= fPartitioner.computePartitioning(0, fDoc.getLength(), true); + assertComputeZeroLengthPartitioning_InterleavingPartitions(0, fDoc.getLength(), offsets, DEFAULT); + } + + private void assertComputeZeroLengthPartitioning_InterleavingPartitions(int startOffset, int endOffset, int[] offsets, String startType) { + ITypedRegion[] regions= fPartitioner.computePartitioning(startOffset, endOffset - startOffset, true); - String type= DEFAULT; - int previousOffset= 0; + String type= startType; + int previousOffset= startOffset; assertEquals(offsets.length + 1, regions.length); for (int i= 0; i <= offsets.length; i++) { - int offset= (i == offsets.length) ? fDoc.getLength() : offsets[i]; + int currentOffset= (i == offsets.length) ? endOffset : offsets[i]; ITypedRegion region= regions[i]; - assertTypedRegion(region, previousOffset, offset, type); + assertTypedRegion(region, previousOffset, currentOffset, type); // advance if (type == DEFAULT) type= COMMENT; else type= DEFAULT; - previousOffset= offset; + previousOffset= currentOffset; } } |