Skip to content

Commit 14ed3f3

Browse files
jonahgrahamakurtakov
authored andcommitted
Fix Test_org_eclipse_swt_custom_StyledTextContent
This test had bitrotten significantly since it was written a long time ago. This commit fixes the behaviour by making test implementation of StyledTextContent behave reasonably so that other StyledText operations can complete successfully.
1 parent ad01f19 commit 14ed3f3

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/AllWidgetTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
Test_org_eclipse_swt_custom_LineStyleListener.class, //
3535
Test_org_eclipse_swt_custom_StyleRange.class, //
3636
Test_org_eclipse_swt_custom_StyledText.class, //
37-
// Failing test: Test_org_eclipse_swt_custom_StyledTextContent.class, //
37+
Test_org_eclipse_swt_custom_StyledTextContent.class, //
3838
Test_org_eclipse_swt_custom_StyledTextLineSpacingProvider.class, //
3939
Test_org_eclipse_swt_custom_StyledText_VariableLineHeight.class, //
4040
Test_org_eclipse_swt_custom_StyledText_multiCaretsSelections.class, //

tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_StyledTextContent.java

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,29 +33,29 @@
3333
* @see org.eclipse.swt.custom.StyledTextContent
3434
*/
3535
public class Test_org_eclipse_swt_custom_StyledTextContent {
36-
int XINSET = 0;
36+
private static final String INITIAL_TEXT = "initial text";
3737

3838
static class ContentImplementation implements StyledTextContent {
39-
String textContent = "";
39+
String textContent = INITIAL_TEXT;
4040

4141
@Override
4242
public void addTextChangeListener(TextChangeListener listener){
4343
}
4444
@Override
4545
public int getCharCount() {
46-
return 0;
46+
return textContent.length();
4747
}
4848
@Override
4949
public String getLine(int lineIndex) {
50-
return "getLine";
50+
return textContent;
5151
}
5252
@Override
5353
public int getLineAtOffset(int offset) {
5454
return 0;
5555
}
5656
@Override
5757
public int getLineCount() {
58-
return 0;
58+
return 1;
5959
}
6060
@Override
6161
public String getLineDelimiter() {
@@ -67,14 +67,14 @@ public int getOffsetAtLine(int lineIndex) {
6767
}
6868
@Override
6969
public String getTextRange(int start, int length) {
70-
return textContent;
70+
return textContent.substring(start, start + length);
7171
}
7272
@Override
7373
public void removeTextChangeListener(TextChangeListener listener) {
7474
}
7575
@Override
7676
public void replaceTextRange(int start, int replaceLength, String text) {
77-
textContent = text;
77+
textContent = textContent.substring(0, start) +text + textContent.substring(start + replaceLength);
7878
}
7979
@Override
8080
public void setText(String text) {
@@ -87,16 +87,14 @@ public void setText(String text) {
8787

8888
@Before
8989
public void setUp() {
90-
if (SwtTestUtil.isBidi()) XINSET = 2;
91-
else XINSET = 0;
9290
shell = new Shell();
9391
styledText = new StyledText(shell, SWT.NULL);
9492
styledText.setContent(content);
9593
}
9694

9795
@Test
9896
public void test_getCharCount() {
99-
assertEquals(":a:", 0, styledText.getCharCount());
97+
assertEquals(":a:", INITIAL_TEXT.length(), styledText.getCharCount());
10098
}
10199

102100
@Test
@@ -117,13 +115,13 @@ public void test_getLineDelimiter() {
117115
@Test
118116
public void test_getLineI() {
119117
// will indirectly cause getLine to be called
120-
assertEquals(":b:", new Point(XINSET,0), styledText.getLocationAtOffset(0));
118+
assertEquals(":b:", new Point(0,0), styledText.getLocationAtOffset(0));
121119
}
122120

123121
@Test
124122
public void test_getOffsetAtLineI() {
125123
// will indirectly cause getOffsetAtLine to be called
126-
assertEquals(":f:", new Point(XINSET,0), styledText.getLocationAtOffset(0));
124+
assertEquals(":f:", new Point(0,0), styledText.getLocationAtOffset(0));
127125
}
128126

129127
@Test
@@ -134,13 +132,13 @@ public void test_getTextRangeII() {
134132
@Test
135133
public void test_replaceTextRangeIILjava_lang_String() {
136134
styledText.replaceTextRange(0,0,"test1");
137-
assertEquals(":h:", "test1", styledText.getText());
135+
assertEquals(":h:", "test1" + INITIAL_TEXT, styledText.getText());
138136
}
139137

140138
@Test
141139
public void test_setTextLjava_lang_String() {
142140
styledText.replaceTextRange(0,0,"test2");
143-
assertEquals(":i:", "test2", styledText.getText());
141+
assertEquals(":i:", "test2" + INITIAL_TEXT, styledText.getText());
144142
}
145143

146144
}

0 commit comments

Comments
 (0)