diff options
author | Markus Keller | 2010-11-17 13:01:50 +0000 |
---|---|---|
committer | Markus Keller | 2010-11-17 13:01:50 +0000 |
commit | d58c732c310e04a893baa3ead2bbdd5a84608df8 (patch) | |
tree | 0fd71a0b3f110180935b3cedd057f3efb0b6ae3e /org.eclipse.text.tests | |
parent | fdd07c4fa38a94ec7a53529f6cf80cc4e4b4b629 (diff) | |
download | eclipse.platform.text-d58c732c310e04a893baa3ead2bbdd5a84608df8.tar.gz eclipse.platform.text-d58c732c310e04a893baa3ead2bbdd5a84608df8.tar.xz eclipse.platform.text-d58c732c310e04a893baa3ead2bbdd5a84608df8.zip |
Bug 329614: [linked mode] Incorrect selection and caret position after rename in file
Diffstat (limited to 'org.eclipse.text.tests')
-rw-r--r-- | org.eclipse.text.tests/src/org/eclipse/text/tests/ExclusivePositionUpdaterTest.java | 209 | ||||
-rw-r--r-- | org.eclipse.text.tests/src/org/eclipse/text/tests/PositionUpdatingCornerCasesTest.java | 42 |
2 files changed, 198 insertions, 53 deletions
diff --git a/org.eclipse.text.tests/src/org/eclipse/text/tests/ExclusivePositionUpdaterTest.java b/org.eclipse.text.tests/src/org/eclipse/text/tests/ExclusivePositionUpdaterTest.java index c6cf8de8325..4037d37e415 100644 --- a/org.eclipse.text.tests/src/org/eclipse/text/tests/ExclusivePositionUpdaterTest.java +++ b/org.eclipse.text.tests/src/org/eclipse/text/tests/ExclusivePositionUpdaterTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2010 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 @@ -23,6 +23,7 @@ import org.eclipse.jface.text.IPositionUpdater; import org.eclipse.jface.text.Position; /** + * Tests DefaultPositionUpdater. Does NOT test one of the ExclusivePositionUpdaters. * @since 3.3 */ public class ExclusivePositionUpdaterTest extends TestCase { @@ -41,6 +42,7 @@ public class ExclusivePositionUpdaterTest extends TestCase { fUpdater= new DefaultPositionUpdater(CATEGORY); fDoc= new Document("ccccccccccccccccccccccccccccccccccccccccccccc"); fPos= new Position(5, 5); + // 01234[fPo]0123456789 fDoc.addPositionUpdater(fUpdater); fDoc.addPositionCategory(CATEGORY); fDoc.addPosition(CATEGORY, fPos); @@ -53,99 +55,218 @@ public class ExclusivePositionUpdaterTest extends TestCase { fDoc.removePositionUpdater(fUpdater); fDoc.removePositionCategory(CATEGORY); } + + // Delete, ascending by offset, length: - public void testDeleteAfter() throws BadLocationException { - fDoc.replace(20, 2, ""); - Assert.assertEquals(5, fPos.offset); + public void testDeleteBefore() throws BadLocationException { + fDoc.replace(2, 2, ""); + Assert.assertEquals(3, fPos.offset); Assert.assertEquals(5, fPos.length); + Assert.assertFalse(fPos.isDeleted); + } + + public void testDeleteRightBefore() throws BadLocationException { + fDoc.replace(3, 2, ""); + Assert.assertEquals(3, fPos.offset); + Assert.assertEquals(5, fPos.length); + Assert.assertFalse(fPos.isDeleted); + } + + public void testDeleteOverLeftBorder() throws BadLocationException { + fDoc.replace(3, 6, ""); + Assert.assertEquals(3, fPos.offset); + Assert.assertEquals(1, fPos.length); + Assert.assertFalse(fPos.isDeleted); } - public void testAddAfter() throws BadLocationException { - fDoc.replace(20, 0, "yy"); + public void testDeleteOverLeftBorderTillRight() throws BadLocationException { + fDoc.replace(4, 6, ""); + Assert.assertEquals(4, fPos.offset); + Assert.assertEquals(0, fPos.length); + Assert.assertFalse(fPos.isDeleted); + } + + public void testDeleted() throws BadLocationException { + fDoc.replace(4, 7, ""); + Assert.assertTrue(fPos.isDeleted); + } + + public void testDeleteAtOffset() throws BadLocationException { + fDoc.replace(5, 1, ""); + Assert.assertEquals(5, fPos.offset); + Assert.assertEquals(4, fPos.length); + Assert.assertFalse(fPos.isDeleted); + } + + public void testDeleteAtOffset2() throws BadLocationException { + fDoc.replace(5, 2, ""); + Assert.assertEquals(5, fPos.offset); + Assert.assertEquals(3, fPos.length); + Assert.assertFalse(fPos.isDeleted); + } + + public void testDeleteAtOffsetTillRight() throws BadLocationException { + fDoc.replace(5, 5, ""); + Assert.assertEquals(5, fPos.offset); + Assert.assertEquals(0, fPos.length); + Assert.assertFalse(fPos.isDeleted); + } + + public void testDeleteAtOffsetOverRightBorder() throws BadLocationException { + fDoc.replace(5, 6, ""); + Assert.assertEquals(5, fPos.offset); + Assert.assertEquals(0, fPos.length); + Assert.assertFalse(fPos.isDeleted); + } + + public void testDeleteWithin() throws BadLocationException { + fDoc.replace(6, 2, ""); + Assert.assertEquals(5, fPos.offset); + Assert.assertEquals(3, fPos.length); + Assert.assertFalse(fPos.isDeleted); + } + + public void testDeleteAtRight() throws BadLocationException { + fDoc.replace(8, 2, ""); + Assert.assertEquals(5, fPos.offset); + Assert.assertEquals(3, fPos.length); + Assert.assertFalse(fPos.isDeleted); + } + + public void testDeleteOverRightBorder() throws BadLocationException { + fDoc.replace(9, 2, ""); + Assert.assertEquals(5, fPos.offset); + Assert.assertEquals(4, fPos.length); + Assert.assertFalse(fPos.isDeleted); + } + + public void testDeleteRightAfter() throws BadLocationException { + fDoc.replace(10, 2, ""); Assert.assertEquals(5, fPos.offset); Assert.assertEquals(5, fPos.length); + Assert.assertFalse(fPos.isDeleted); } - - public void testDeleteBefore() throws BadLocationException { - fDoc.replace(2, 2, ""); - Assert.assertEquals(3, fPos.offset); + + public void testDeleteAfter() throws BadLocationException { + fDoc.replace(20, 2, ""); + Assert.assertEquals(5, fPos.offset); Assert.assertEquals(5, fPos.length); + Assert.assertFalse(fPos.isDeleted); } + // Add, ascending by offset: + public void testAddBefore() throws BadLocationException { fDoc.replace(2, 0, "yy"); Assert.assertEquals(7, fPos.offset); Assert.assertEquals(5, fPos.length); } - + public void testAddRightBefore() throws BadLocationException { fDoc.replace(5, 0, "yy"); Assert.assertEquals(7, fPos.offset); Assert.assertEquals(5, fPos.length); } - public void testDeleteAtOffset() throws BadLocationException { - fDoc.replace(5, 2, ""); + public void testAddWithin() throws BadLocationException { + fDoc.replace(6, 0, "yy"); Assert.assertEquals(5, fPos.offset); - Assert.assertEquals(3, fPos.length); + Assert.assertEquals(7, fPos.length); } - - public void testDeleteRightBefore() throws BadLocationException { - fDoc.replace(3, 2, ""); - Assert.assertEquals(3, fPos.offset); - Assert.assertEquals(5, fPos.length); + + public void testAddWithin2() throws BadLocationException { + fDoc.replace(9, 0, "yy"); + Assert.assertEquals(5, fPos.offset); + Assert.assertEquals(7, fPos.length); } - + public void testAddRightAfter() throws BadLocationException { fDoc.replace(10, 0, "yy"); Assert.assertEquals(5, fPos.offset); Assert.assertEquals(5, fPos.length); } - - public void testDeleteRightAfter() throws BadLocationException { - fDoc.replace(10, 2, ""); + + public void testAddAfter() throws BadLocationException { + fDoc.replace(20, 0, "yy"); Assert.assertEquals(5, fPos.offset); Assert.assertEquals(5, fPos.length); } - public void testAddWithin() throws BadLocationException { - fDoc.replace(6, 0, "yy"); - Assert.assertEquals(5, fPos.offset); - Assert.assertEquals(7, fPos.length); + // Replace, ascending by offset, length: + + public void testReplaceBefore() throws BadLocationException { + fDoc.replace(2, 2, "y"); + Assert.assertEquals(4, fPos.offset); + Assert.assertEquals(5, fPos.length); } - public void testDeleteWithin() throws BadLocationException { - fDoc.replace(6, 2, ""); - Assert.assertEquals(5, fPos.offset); - Assert.assertEquals(3, fPos.length); + public void testReplaceRightBefore() throws BadLocationException { + fDoc.replace(2, 3, "y"); + Assert.assertEquals(3, fPos.offset); + Assert.assertEquals(5, fPos.length); } - + public void testReplaceLeftBorder() throws BadLocationException { fDoc.replace(4, 2, "yy"); Assert.assertEquals(6, fPos.offset); Assert.assertEquals(4, fPos.length); } + public void testReplaceLeftBorderTillRight() throws BadLocationException { + fDoc.replace(4, 6, "yy"); + Assert.assertEquals(6, fPos.offset); + Assert.assertEquals(0, fPos.length); + } + + public void testReplaced() throws BadLocationException { + fDoc.replace(4, 7, "yyyyyyy"); + Assert.assertTrue(fPos.isDeleted); + } + + public void testReplaceAtOffset1() throws BadLocationException { + fDoc.replace(5, 1, "yy"); + // 01234[fPo]0123456789 + Assert.assertEquals(7, fPos.offset); + Assert.assertEquals(4, fPos.length); + } + + public void testReplaceAtOffset2() throws BadLocationException { + fDoc.replace(5, 4, "yy"); + // 01234[fPo]0123456789 + Assert.assertEquals(7, fPos.offset); + Assert.assertEquals(1, fPos.length); + } + + public void testReplaceAtOffsetTillRight() throws BadLocationException { + fDoc.replace(5, 5, "yy"); + // 01234[fPo]0123456789 + Assert.assertEquals(5, fPos.offset); + Assert.assertEquals(0, fPos.length); + Assert.assertFalse(fPos.isDeleted); + } + + public void testReplaceAtRight() throws BadLocationException { + fDoc.replace(6, 4, "yy"); + Assert.assertEquals(5, fPos.offset); + Assert.assertEquals(1, fPos.length); + } + public void testReplaceRightBorder() throws BadLocationException { fDoc.replace(9, 2, "yy"); Assert.assertEquals(5, fPos.offset); Assert.assertEquals(4, fPos.length); } - public void testDeleteOverRightBorder() throws BadLocationException { - fDoc.replace(9, 2, ""); + public void testReplaceRightAfter() throws BadLocationException { + fDoc.replace(10, 2, "y"); Assert.assertEquals(5, fPos.offset); - Assert.assertEquals(4, fPos.length); - } - - public void testDeleted() throws BadLocationException { - fDoc.replace(4, 7, ""); - Assert.assertTrue(fPos.isDeleted); + Assert.assertEquals(5, fPos.length); } - - public void testReplaced() throws BadLocationException { - fDoc.replace(4, 7, "yyyyyyy"); - Assert.assertTrue(fPos.isDeleted); + + public void testReplaceAfter() throws BadLocationException { + fDoc.replace(20, 2, "y"); + Assert.assertEquals(5, fPos.offset); + Assert.assertEquals(5, fPos.length); } } diff --git a/org.eclipse.text.tests/src/org/eclipse/text/tests/PositionUpdatingCornerCasesTest.java b/org.eclipse.text.tests/src/org/eclipse/text/tests/PositionUpdatingCornerCasesTest.java index 194011f83a6..07d80a7ab06 100644 --- a/org.eclipse.text.tests/src/org/eclipse/text/tests/PositionUpdatingCornerCasesTest.java +++ b/org.eclipse.text.tests/src/org/eclipse/text/tests/PositionUpdatingCornerCasesTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. + * Copyright (c) 2000, 2010 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 @@ -41,14 +41,6 @@ public class PositionUpdatingCornerCasesTest extends TestCase { return "[" + p.getOffset() + "," + p.getLength() + "]"; } - protected void setUp() throws Exception { - fDocument= new Document("x-x-x-x-x-x-x-x-x-x-x"); - fDocument.addPosition(new Position(0, 0)); - fDocument.addPosition(new Position(0, 1)); - fDocument.addPosition(new Position(5, 0)); - fDocument.addPosition(new Position(5, 3)); - } - public static Test suite() { return new TestSuite(PositionUpdatingCornerCasesTest.class); } @@ -58,6 +50,12 @@ public class PositionUpdatingCornerCasesTest extends TestCase { } public void testInsert() throws Exception { + fDocument= new Document("x-x-x-x-x-x-x-x-x-x-x"); + fDocument.addPosition(new Position(0, 0)); + fDocument.addPosition(new Position(0, 1)); + fDocument.addPosition(new Position(5, 0)); + fDocument.addPosition(new Position(5, 3)); + fDocument.replace(0, 0, "yy"); Position[] positions= new Position[] { @@ -69,4 +67,30 @@ public class PositionUpdatingCornerCasesTest extends TestCase { checkPositions(positions); } + + public void testInsert2() throws Exception { + fDocument= new Document("x-x-x-x-x-x-x-x-x-x-x"); + fDocument.addPosition(new Position(0, 0)); + fDocument.addPosition(new Position(0, 1)); + fDocument.addPosition(new Position(4, 1)); + fDocument.addPosition(new Position(5, 0)); + fDocument.addPosition(new Position(5, 3)); + fDocument.addPosition(new Position(10, 0)); + fDocument.addPosition(new Position(10, 2)); + + fDocument.replace(5, 0, "yy"); + + Position[] positions= new Position[] { + new Position(0, 1), + new Position(0, 0), + new Position(4, 1), + new Position(7, 3), + new Position(7, 0), + new Position(12, 2), + new Position(12, 0), + }; + + checkPositions(positions); + + } } |