1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
/*******************************************************************************
* Copyright (c) 2006, 2008 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.text.tests;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class AdaptiveGapTextTest extends AbstractGapTextTest {
@Before
public void setUp() {
fText= new GapText(2, 10, 0.5f);
fText.set("xxxxx");
}
@After
public void tearDown () {
fText= null;
}
@Test
public void testSet() {
assertGap(5, 7);
}
@Test
public void testGetText1() {
String[] expected= {
"xyxxxx",
"xyxyxxx",
"xyxyxyxx",
"xyxyxyxyx",
"xyxyxyxyxy"
};
for (int i= 1; i < 5; i++) {
fText.replace(2 * i - 1, 0, "y");
assertContents(expected[i - 1]);
}
}
@Test
public void testGetText2() {
String[] expected= {
"yxxxxx",
"yxyxxxx",
"yxyxyxxx",
"yxyxyxyxx",
"yxyxyxyxyx"
};
for (int i= 1; i < 5; i++) {
fText.replace(2 * (i - 1), 0, "y");
assertContents(expected[i - 1]);
}
}
@Test
public void testInsert() {
fText.replace(2, 0, "y");
assertGap(3, 4);
for (int i= 1; i <= 1; i++) {
fText.replace(2 + i, 0, "y");
assertGap(3 + i, 4);
}
fText.replace(7, 0, "y");
assertGap(8, 10);
}
@Test
public void testRemoveGapOverlapping() {
fText.replace(2, 2, null);
assertGap(2, 6);
fText.replace(1, 2, null);
assertGap(1, 3);
}
@Test
public void testRemoveGapOverlapping2() {
fText.replace(0, 0, "aaaaazzzzzyyyyy");
assertGap(15, 21);
assertContents("aaaaazzzzzyyyyyxxxxx");
fText.replace(5, 12, null);
assertGap(5, 7);
assertContents("aaaaaxxx");
}
@Test
public void testRemoveRemoteFromGap() {
fText.replace(0, 0, "aaaaazzzzzyyyyy");
assertGap(15, 21);
assertContents("aaaaazzzzzyyyyyxxxxx");
// before gap
fText.replace(5, 2, null);
assertGap(5, 13);
assertContents("aaaaazzzyyyyyxxxxx");
// after gap
fText.replace(7, 10, null);
assertGap(7, 9);
assertContents("aaaaazzx");
}
@Test
public void testRemoveAtLeftGapEdge() {
fText.replace(4, 0, "xxx");
assertGap(7, 9);
fText.replace(6, 0, "x");
assertGap(7, 8);
fText.replace(6, 1, null);
assertGap(6, 8);
}
@Test
public void testRemoveAtRightGapEdge() {
fText.replace(4, 0, "xxx");
assertGap(7, 9);
fText.replace(6, 0, "x");
assertGap(7, 8);
fText.replace(7, 1, null);
assertGap(7, 9);
}
@Test
public void testReplace() {
fText.replace(2, 2, "yy");
assertGap(4, 6);
fText.replace(2, 1, "yyyyyyyyyyyy");
assertGap(14, 19);
fText.replace(14, 0, "yyy");
assertGap(17, 19);
}
@Test
public void testRemoveReallocateBeforeGap() throws Exception {
fText.replace(0, 0, "yyyyyzzzzz");
assertGap(10, 15);
assertContents("yyyyyzzzzzxxxxx");
fText.replace(2, 6, null);
assertGap(2, 5);
assertContents("yyzzxxxxx");
}
}
|