| Index: dart/editor/tools/plugins/com.google.dart.tools.ui_test/src/com/google/dart/tools/ui/internal/text/dart/DartReconcilingRegionTest.java
|
| ===================================================================
|
| --- dart/editor/tools/plugins/com.google.dart.tools.ui_test/src/com/google/dart/tools/ui/internal/text/dart/DartReconcilingRegionTest.java (revision 29808)
|
| +++ dart/editor/tools/plugins/com.google.dart.tools.ui_test/src/com/google/dart/tools/ui/internal/text/dart/DartReconcilingRegionTest.java (working copy)
|
| @@ -17,75 +17,130 @@
|
|
|
| public class DartReconcilingRegionTest extends TestCase {
|
|
|
| - public void test_add_disjoint_after() throws Exception {
|
| - DartReconcilingRegion target = new DartReconcilingRegion(3, 2, 6);
|
| - DartReconcilingRegion result = target.add(10, 7, 20);
|
| + public void test_add_contiguous() throws Exception {
|
| + DartReconcilingRegion target = new DartReconcilingRegion(5, 12, 25);
|
| + DartReconcilingRegion result = target.add(30, 0, 6);
|
| + assertResult(target, new DartReconcilingRegion(30, 0, 6), result);
|
| + assertEquals(5, result.getOffset());
|
| + assertEquals(12, result.getOldLength());
|
| + assertEquals(31, result.getNewLength());
|
| + assertFalse(result.isEmpty());
|
| + }
|
| +
|
| + public void test_add_contiguousDelete() throws Exception {
|
| + DartReconcilingRegion target = new DartReconcilingRegion(5, 12, 25);
|
| + DartReconcilingRegion result = target.add(3, 2, 0);
|
| + assertResult(target, new DartReconcilingRegion(3, 2, 0), result);
|
| assertEquals(3, result.getOffset());
|
| assertEquals(14, result.getOldLength());
|
| - assertEquals(27, result.getNewLength());
|
| + assertEquals(25, result.getNewLength());
|
| assertFalse(result.isEmpty());
|
| }
|
|
|
| - public void test_add_disjoint_before() throws Exception {
|
| - DartReconcilingRegion target = new DartReconcilingRegion(10, 7, 20);
|
| + public void test_add_contiguousDelete2() throws Exception {
|
| + DartReconcilingRegion target = new DartReconcilingRegion(5, 12, 25);
|
| + DartReconcilingRegion result = target.add(4, 2, 0);
|
| + assertResult(target, new DartReconcilingRegion(4, 2, 0), result);
|
| + assertEquals(4, result.getOffset());
|
| + assertEquals(13, result.getOldLength());
|
| + assertEquals(24, result.getNewLength());
|
| + assertFalse(result.isEmpty());
|
| + }
|
| +
|
| + public void test_add_contiguousReplace() throws Exception {
|
| + DartReconcilingRegion target = new DartReconcilingRegion(5, 12, 25);
|
| + DartReconcilingRegion result = target.add(28, 2, 6);
|
| + assertResult(target, new DartReconcilingRegion(28, 2, 6), result);
|
| + assertEquals(5, result.getOffset());
|
| + assertEquals(12, result.getOldLength());
|
| + assertEquals(29, result.getNewLength());
|
| + assertFalse(result.isEmpty());
|
| + }
|
| +
|
| + public void test_add_contiguousReplace2() throws Exception {
|
| + DartReconcilingRegion target = new DartReconcilingRegion(5, 12, 25);
|
| + DartReconcilingRegion result = target.add(10, 2, 6);
|
| + assertResult(target, new DartReconcilingRegion(28, 2, 6), result);
|
| + assertEquals(5, result.getOffset());
|
| + assertEquals(12, result.getOldLength());
|
| + assertEquals(29, result.getNewLength());
|
| + assertFalse(result.isEmpty());
|
| + }
|
| +
|
| + public void test_add_contiguousReplaceBefore() throws Exception {
|
| + DartReconcilingRegion target = new DartReconcilingRegion(5, 12, 25);
|
| DartReconcilingRegion result = target.add(3, 2, 6);
|
| + assertResult(target, new DartReconcilingRegion(3, 2, 6), result);
|
| assertEquals(3, result.getOffset());
|
| assertEquals(14, result.getOldLength());
|
| - assertEquals(27, result.getNewLength());
|
| + assertEquals(31, result.getNewLength());
|
| assertFalse(result.isEmpty());
|
| }
|
|
|
| + public void test_add_disjointAfter() throws Exception {
|
| + DartReconcilingRegion target = new DartReconcilingRegion(3, 2, 6);
|
| + DartReconcilingRegion result = target.add(10, 7, 20);
|
| + assertNull(result);
|
| + }
|
| +
|
| + public void test_add_disjointBefore() throws Exception {
|
| + DartReconcilingRegion target = new DartReconcilingRegion(10, 7, 20);
|
| + DartReconcilingRegion result = target.add(3, 2, 6);
|
| + assertNull(result);
|
| + }
|
| +
|
| public void test_add_empty() throws Exception {
|
| DartReconcilingRegion target = new DartReconcilingRegion(3, 2, 6);
|
| DartReconcilingRegion result = target.add(10, 0, 0);
|
| + assertResult(target, new DartReconcilingRegion(10, 0, 0), result);
|
| assertEquals(3, result.getOffset());
|
| assertEquals(2, result.getOldLength());
|
| assertEquals(6, result.getNewLength());
|
| assertFalse(result.isEmpty());
|
| }
|
|
|
| - public void test_add_overlapping_after() throws Exception {
|
| + public void test_add_overlappingAfter() throws Exception {
|
| DartReconcilingRegion target = new DartReconcilingRegion(3, 2, 6);
|
| - DartReconcilingRegion result = target.add(5, 12, 25);
|
| - assertEquals(3, result.getOffset());
|
| - assertEquals(14, result.getOldLength());
|
| - assertEquals(27, result.getNewLength());
|
| - assertFalse(result.isEmpty());
|
| + DartReconcilingRegion result = target.add(5, 5, 25);
|
| + assertNull(result);
|
| }
|
|
|
| - public void test_add_overlapping_before() throws Exception {
|
| + public void test_add_overlappingBefore() throws Exception {
|
| DartReconcilingRegion target = new DartReconcilingRegion(5, 12, 25);
|
| - DartReconcilingRegion result = target.add(3, 2, 6);
|
| - assertEquals(3, result.getOffset());
|
| - assertEquals(14, result.getOldLength());
|
| - assertEquals(27, result.getNewLength());
|
| - assertFalse(result.isEmpty());
|
| + DartReconcilingRegion result = target.add(3, 1, 6);
|
| + assertNull(result);
|
| }
|
|
|
| - public void test_add_to_empty() throws Exception {
|
| + public void test_add_toEmpty1() throws Exception {
|
| DartReconcilingRegion target = new DartReconcilingRegion(0, 0, 0);
|
| DartReconcilingRegion result = target.add(3, 2, 6);
|
| + assertResult(target, new DartReconcilingRegion(3, 2, 6), result);
|
| assertEquals(3, result.getOffset());
|
| assertEquals(2, result.getOldLength());
|
| assertEquals(6, result.getNewLength());
|
| assertFalse(result.isEmpty());
|
| + }
|
|
|
| - target = new DartReconcilingRegion(10, 0, 0);
|
| - result = target.add(3, 2, 6);
|
| + public void test_add_toEmpty2() throws Exception {
|
| + DartReconcilingRegion target = new DartReconcilingRegion(10, 0, 0);
|
| + DartReconcilingRegion result = target.add(3, 2, 6);
|
| + assertResult(target, new DartReconcilingRegion(3, 2, 6), result);
|
| assertEquals(3, result.getOffset());
|
| assertEquals(2, result.getOldLength());
|
| assertEquals(6, result.getNewLength());
|
| assertFalse(result.isEmpty());
|
| }
|
|
|
| - public void test_new_empty() {
|
| + public void test_new_empty1() {
|
| DartReconcilingRegion target = new DartReconcilingRegion(0, 0, 0);
|
| assertEquals(0, target.getOffset());
|
| assertEquals(0, target.getOldLength());
|
| assertEquals(0, target.getNewLength());
|
| assertTrue(target.isEmpty());
|
| + }
|
|
|
| - target = new DartReconcilingRegion(10, 0, 0);
|
| + public void test_new_empty2() {
|
| + DartReconcilingRegion target = new DartReconcilingRegion(10, 0, 0);
|
| assertEquals(10, target.getOffset());
|
| assertEquals(0, target.getOldLength());
|
| assertEquals(0, target.getNewLength());
|
| @@ -107,4 +162,22 @@
|
| assertEquals(0, target.getNewLength());
|
| assertFalse(target.isEmpty());
|
| }
|
| +
|
| + private String adjust(String code, DartReconcilingRegion region) {
|
| + StringBuilder sb = new StringBuilder();
|
| + sb.append(code.substring(0, region.getOffset()));
|
| + for (int count = 0; count < region.getNewLength(); count++) {
|
| + sb.append('0');
|
| + }
|
| + sb.append(code.substring(region.getOffset() + region.getOldLength()));
|
| + return sb.toString();
|
| + }
|
| +
|
| + private void assertResult(DartReconcilingRegion target, DartReconcilingRegion added,
|
| + DartReconcilingRegion result) {
|
| + String code = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
| + String expected = adjust(adjust(code, target), added);
|
| + String actual = adjust(code, result);
|
| + assertEquals(expected, actual);
|
| + }
|
| }
|
|
|