3333 * @see org.eclipse.swt.custom.StyledTextContent
3434 */
3535public 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
8989public 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
9896public 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
118116public 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
124122public 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
135133public 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
141139public 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