Search in sources :

Example 16 with StyledTextContent

use of org.eclipse.swt.custom.StyledTextContent in project webtools.sourceediting by eclipse.

the class StyledTextContentSpec method test_Insert.

public void test_Insert() {
    StyledTextContent content = getContentInstance();
    String newText;
    content.setText("This\nis a test\r");
    content.replaceTextRange(0, 0, "test\n ");
    newText = content.getTextRange(0, content.getCharCount());
    assertWithMessage(":1a:", newText.equals("test\n This\nis a test\r"));
    assertWithMessage(":1b:", content.getLineCount() == 4);
    assertWithMessage(":1c:", content.getLine(0).equals("test"));
    assertWithMessage(":1d:", content.getLine(1).equals(" This"));
    assertWithMessage(":1e:", content.getLine(2).equals("is a test"));
    assertWithMessage(":1f:", content.getLine(3).equals(""));
    content.setText("This\nis a test\r");
    content.replaceTextRange(5, 0, "*** ");
    newText = content.getTextRange(0, content.getCharCount());
    assertWithMessage(":2a:", newText.equals("This\n*** is a test\r"));
    assertWithMessage(":2b:", content.getLineCount() == 3);
    assertWithMessage(":2c:", content.getLine(0).equals("This"));
    assertWithMessage(":2d:", content.getLine(1).equals("*** is a test"));
    assertWithMessage(":2e:", content.getLine(2).equals(""));
    content.setText("Line 1\r\nLine 2");
    content.replaceTextRange(0, 0, "\r");
    newText = content.getTextRange(0, content.getCharCount());
    assertWithMessage(":3a:", newText.equals("\rLine 1\r\nLine 2"));
    assertWithMessage(":3b:", content.getLineCount() == 3);
    assertWithMessage(":3c:", content.getLine(0).equals(""));
    assertWithMessage(":3d:", content.getLine(1).equals("Line 1"));
    assertWithMessage(":3e:", content.getLine(2).equals("Line 2"));
    content.replaceTextRange(9, 0, "\r");
    newText = content.getTextRange(0, content.getCharCount());
    assertWithMessage(":3f:", newText.equals("\rLine 1\r\n\rLine 2"));
    assertWithMessage(":3g:", content.getLineCount() == 4);
    assertWithMessage(":3h:", content.getLine(0).equals(""));
    assertWithMessage(":3i:", content.getLine(1).equals("Line 1"));
    assertWithMessage(":3j:", content.getLine(2).equals(""));
    assertWithMessage(":3k:", content.getLine(3).equals("Line 2"));
    content.setText("This\nis a test\r");
    content.replaceTextRange(0, 0, "\n");
    newText = content.getTextRange(0, content.getCharCount());
    assertWithMessage(":4a:", newText.equals("\nThis\nis a test\r"));
    assertWithMessage(":4b:", content.getLineCount() == 4);
    assertWithMessage(":4c:", content.getLine(0).equals(""));
    assertWithMessage(":4d:", content.getLine(1).equals("This"));
    assertWithMessage(":4e:", content.getLine(2).equals("is a test"));
    assertWithMessage(":4f:", content.getLine(3).equals(""));
    content.setText("This\nis a test\r");
    content.replaceTextRange(7, 0, "\r\nnewLine");
    newText = content.getTextRange(0, content.getCharCount());
    assertWithMessage(":5a:", newText.equals("This\nis\r\nnewLine a test\r"));
    assertWithMessage(":5b:", content.getLineCount() == 4);
    assertWithMessage(":5c:", content.getLine(0).equals("This"));
    assertWithMessage(":5d:", content.getLine(1).equals("is"));
    assertWithMessage(":5e:", content.getLine(2).equals("newLine a test"));
    assertWithMessage(":5f:", content.getLine(3).equals(""));
    content.setText("");
    content.replaceTextRange(0, 0, "This\nis\r\nnewLine a test\r");
    newText = content.getTextRange(0, content.getCharCount());
    assertWithMessage(":6a:", newText.equals("This\nis\r\nnewLine a test\r"));
    assertWithMessage(":6b:", content.getLineCount() == 4);
    assertWithMessage(":6c:", content.getLine(0).equals("This"));
    assertWithMessage(":6d:", content.getLine(1).equals("is"));
    assertWithMessage(":6e:", content.getLine(2).equals("newLine a test"));
    assertWithMessage(":6f:", content.getLine(3).equals(""));
    // insert at end
    content.setText("This");
    content.replaceTextRange(4, 0, "\n ");
    newText = content.getTextRange(0, content.getCharCount());
    assertWithMessage(":7a:", newText.equals("This\n "));
    assertWithMessage(":7b:", content.getLineCount() == 2);
    assertWithMessage(":7c:", content.getLine(0).equals("This"));
    assertWithMessage(":7d:", content.getLine(1).equals(" "));
    content.setText("This\n");
    content.replaceTextRange(5, 0, "\n");
    newText = content.getTextRange(0, content.getCharCount());
    assertWithMessage(":7e:", newText.equals("This\n\n"));
    assertWithMessage(":7f:", content.getLineCount() == 3);
    assertWithMessage(":7g:", content.getLine(0).equals("This"));
    assertWithMessage(":7h:", content.getLine(1).equals(""));
    assertWithMessage(":7i:", content.getLine(2).equals(""));
    // insert at beginning
    content.setText("This");
    content.replaceTextRange(0, 0, "\n");
    newText = content.getTextRange(0, content.getCharCount());
    assertWithMessage(":8a:", newText.equals("\nThis"));
    assertWithMessage(":8b:", content.getLineCount() == 2);
    assertWithMessage(":8c:", content.getLine(0).equals(""));
    assertWithMessage(":8d:", content.getLine(1).equals("This"));
    // insert text
    content.setText("This\nis a test\r");
    content.replaceTextRange(5, 0, "*** ");
    newText = content.getTextRange(0, content.getCharCount());
    assertWithMessage(":9a:", newText.equals("This\n*** is a test\r"));
    assertWithMessage(":9b:", content.getLineCount() == 3);
    assertWithMessage(":9c:", content.getLine(0).equals("This"));
    assertWithMessage(":9d:", content.getLine(1).equals("*** is a test"));
    assertWithMessage(":9e:", content.getLine(2).equals(""));
    content.setText("This\n");
    content.replaceTextRange(5, 0, "line");
    newText = content.getTextRange(0, content.getCharCount());
    assertWithMessage(":10a:", newText.equals("This\nline"));
    assertWithMessage(":10b:", content.getLineCount() == 2);
    assertWithMessage(":10c:", content.getLine(0).equals("This"));
    assertWithMessage(":10d:", content.getLine(1).equals("line"));
    assertWithMessage(":10e:", content.getLineAtOffset(8) == 1);
    assertWithMessage(":10f:", content.getLineAtOffset(9) == 1);
    // insert at beginning
    content.setText("This\n");
    content.replaceTextRange(0, 0, "line\n");
    newText = content.getTextRange(0, content.getCharCount());
    assertWithMessage(":11a:", newText.equals("line\nThis\n"));
    assertWithMessage(":11b:", content.getLineCount() == 3);
    assertWithMessage(":11c:", content.getLine(0).equals("line"));
    assertWithMessage(":11d:", content.getLine(1).equals("This"));
    assertWithMessage(":11e:", content.getLineAtOffset(5) == 1);
    content.setText("Line 1\r\nLine 2\r\nLine 3");
    content.replaceTextRange(0, 0, "\r");
    newText = content.getTextRange(0, content.getCharCount());
    assertWithMessage(":12a:", newText.equals("\rLine 1\r\nLine 2\r\nLine 3"));
    assertWithMessage(":12b:", content.getLineCount() == 4);
    assertWithMessage(":12c:", content.getLine(0).equals(""));
    assertWithMessage(":12d:", content.getLine(1).equals("Line 1"));
    assertWithMessage(":12e:", content.getLine(2).equals("Line 2"));
    assertWithMessage(":12f:", content.getLine(3).equals("Line 3"));
    content.setText("Line 1\nLine 2\nLine 3");
    content.replaceTextRange(7, 0, "Line1a\nLine1b\n");
    newText = content.getTextRange(0, content.getCharCount());
    assertWithMessage(":13a:", newText.equals("Line 1\nLine1a\nLine1b\nLine 2\nLine 3"));
    assertWithMessage(":13b:", content.getLineCount() == 5);
    assertWithMessage(":13c:", content.getLine(0).equals("Line 1"));
    assertWithMessage(":13d:", content.getLine(1).equals("Line1a"));
    assertWithMessage(":13e:", content.getLine(2).equals("Line1b"));
    assertWithMessage(":13f:", content.getLine(3).equals("Line 2"));
    assertWithMessage(":13g:", content.getLine(4).equals("Line 3"));
    content.setText("Line 1\nLine 2\nLine 3");
    content.replaceTextRange(11, 0, "l1a");
    newText = content.getTextRange(0, content.getCharCount());
    assertWithMessage(":14a:", newText.equals("Line 1\nLinel1a 2\nLine 3"));
    assertWithMessage(":14b:", content.getLineCount() == 3);
    assertWithMessage(":14c:", content.getLine(0).equals("Line 1"));
    assertWithMessage(":14d:", content.getLine(1).equals("Linel1a 2"));
    assertWithMessage(":14e:", content.getLine(2).equals("Line 3"));
    content.setText("Line 1\nLine 2 is a very long line that spans many words\nLine 3");
    content.replaceTextRange(19, 0, "very, very, ");
    newText = content.getTextRange(0, content.getCharCount());
    assertWithMessage(":15a:", newText.equals("Line 1\nLine 2 is a very, very, very long line that spans many words\nLine 3"));
    assertWithMessage(":15b:", content.getLineCount() == 3);
    assertWithMessage(":15c:", content.getLine(0).equals("Line 1"));
    assertWithMessage(":15d:", content.getLine(1).equals("Line 2 is a very, very, very long line that spans many words"));
    assertWithMessage(":15e:", content.getLine(2).equals("Line 3"));
}
Also used : StyledTextContent(org.eclipse.swt.custom.StyledTextContent)

Example 17 with StyledTextContent

use of org.eclipse.swt.custom.StyledTextContent in project webtools.sourceediting by eclipse.

the class StyledTextContentSpec method test_Text_Changed_Event.

public void test_Text_Changed_Event() {
    StyledTextContent content = getContentInstance();
    content.addTextChangeListener(this);
    verify = 1;
    content.setText("testing");
    content.replaceTextRange(0, 0, "\n");
    verify = 2;
    content.setText("\n\n");
    content.replaceTextRange(0, 2, "a");
    verify = 3;
    content.setText("a");
    content.replaceTextRange(0, 1, "\n\n");
    verify = 5;
    content.setText("Line 1\r\nLine 2");
    content.replaceTextRange(0, 0, "\r");
    verify = 6;
    content.setText("This\nis a test\nline 3\nline 4");
    content.replaceTextRange(21, 7, "");
    verify = 7;
    content.setText("This\nis a test\r");
    content.replaceTextRange(5, 9, "");
    verify = 8;
    content.setText("\nL1\r\nL2\r\n");
    content.replaceTextRange(7, 2, "");
    verify = 9;
    content.setText("L1\r\n");
    content.replaceTextRange(2, 2, "test");
    verify = 0;
    content.removeTextChangeListener(this);
}
Also used : StyledTextContent(org.eclipse.swt.custom.StyledTextContent)

Example 18 with StyledTextContent

use of org.eclipse.swt.custom.StyledTextContent in project eclipse.platform.swt by eclipse.

the class StyledTextContentSpec method test_Line_Conversion.

public void test_Line_Conversion() {
    StyledTextContent content = getContentInstance();
    content.setText("This\nis a test\rrepeat\nend\r");
    assertTrue(":1a:", content.getLineCount() == 5);
    assertTrue(":1b:", content.getLine(0).equals("This"));
    assertTrue(":1c:", content.getOffsetAtLine(0) == 0);
    assertTrue(":1d:", content.getLine(1).equals("is a test"));
    assertTrue(":1e:", content.getLineAtOffset(4) == 0);
    assertTrue(":1f:", content.getOffsetAtLine(1) == 5);
    assertTrue(":1g:", content.getLine(2).equals("repeat"));
    assertTrue(":1h:", content.getOffsetAtLine(2) == 15);
    assertTrue(":1i:", content.getLine(3).equals("end"));
    assertTrue(":1j:", content.getOffsetAtLine(3) == 22);
    assertTrue(":1k:", content.getLine(4).isEmpty());
    assertTrue(":1l:", content.getOffsetAtLine(4) == 26);
    content.setText("This\r\nis a test");
    assertTrue(":2a:", content.getLineCount() == 2);
    assertTrue(":2b:", content.getLine(1).equals("is a test"));
    assertTrue(":2c:", content.getLineAtOffset(4) == 0);
    assertTrue(":2d:", content.getLineAtOffset(5) == 0);
    content.setText("This\r\nis a test\r");
    assertTrue(":3a:", content.getLineCount() == 3);
    assertTrue(":3b:", content.getLine(1).equals("is a test"));
    assertTrue(":3c:", content.getLineAtOffset(15) == 1);
    content.setText("\r\n");
    assertTrue(":4a:", content.getLineCount() == 2);
    assertTrue(":4b:", content.getLine(0).isEmpty());
    assertTrue(":4c:", content.getLine(1).isEmpty());
    assertTrue(":4d:", content.getLineAtOffset(0) == 0);
    assertTrue(":4e:", content.getLineAtOffset(1) == 0);
    assertTrue(":4f:", content.getLineAtOffset(2) == 1);
    content.setText("\r\n\n\r\r\n");
    assertTrue(":5a:", content.getLineCount() == 5);
    assertTrue(":5b:", content.getLine(0).isEmpty());
    assertTrue(":5c:", content.getOffsetAtLine(0) == 0);
    assertTrue(":5d:", content.getLine(1).isEmpty());
    assertTrue(":5e:", content.getOffsetAtLine(1) == 2);
    assertTrue(":5f:", content.getLine(2).isEmpty());
    assertTrue(":5g:", content.getOffsetAtLine(2) == 3);
    assertTrue(":5h:", content.getLine(3).isEmpty());
    assertTrue(":5i:", content.getOffsetAtLine(3) == 4);
    assertTrue(":5j:", content.getLine(4).isEmpty());
    assertTrue(":5k:", content.getOffsetAtLine(4) == 6);
    content.setText("test\r\rtest2\r\r");
    assertTrue(":6a:", content.getLineCount() == 5);
    assertTrue(":6b:", content.getLine(0).equals("test"));
    assertTrue(":6c:", content.getOffsetAtLine(0) == 0);
    assertTrue(":6d:", content.getLine(1).isEmpty());
    assertTrue(":6e:", content.getOffsetAtLine(1) == 5);
    assertTrue(":6f:", content.getLine(2).equals("test2"));
    assertTrue(":6g:", content.getOffsetAtLine(2) == 6);
    assertTrue(":6h:", content.getLine(3).isEmpty());
    assertTrue(":6i:", content.getOffsetAtLine(3) == 12);
    assertTrue(":6j:", content.getLine(4).isEmpty());
    assertTrue(":6k:", content.getOffsetAtLine(4) == 13);
}
Also used : StyledTextContent(org.eclipse.swt.custom.StyledTextContent)

Example 19 with StyledTextContent

use of org.eclipse.swt.custom.StyledTextContent in project eclipse.platform.swt by eclipse.

the class StyledTextContentSpec method test_Delimiter_Special_Cases.

public void test_Delimiter_Special_Cases() {
    StyledTextContent content = getContentInstance();
    String newText;
    content.setText("\nL1\r\nL2\r\n");
    content.replaceTextRange(7, 2, "");
    newText = content.getTextRange(0, content.getCharCount());
    assertTrue(":1:", newText.equals("\nL1\r\nL2"));
    content.setText("L1\r\n");
    content.replaceTextRange(2, 2, "test\n\n");
    newText = content.getTextRange(0, content.getCharCount());
    assertTrue(":2:", newText.equals("L1test\n\n"));
    // content.setText("L1\r\n");
    // content.replaceTextRange(3, 1, "test\r\n");
    // newText = content.getTextRange(0, content.getCharCount());
    // assertTrue(":3:", newText.equals("L1\rtest\r\n"));
    // content.setText("L1\r\nL2\r\nL3\r\nL4\r\n");
    // content.replaceTextRange(1, 2, "test\n\n");
    // newText = content.getTextRange(0, content.getCharCount());
    // assertTrue(":4:", newText.equals("Ltest\n\n\nL2\r\nL3\r\nL4\r\n"));
    content.setText("L1\n");
    content.replaceTextRange(2, 0, "test\r\r\r");
    newText = content.getTextRange(0, content.getCharCount());
    assertTrue(":3:", newText.equals("L1test\r\r\r\n"));
}
Also used : StyledTextContent(org.eclipse.swt.custom.StyledTextContent)

Example 20 with StyledTextContent

use of org.eclipse.swt.custom.StyledTextContent in project eclipse.platform.swt by eclipse.

the class StyledTextContentSpec method test_Delete.

public void test_Delete() {
    StyledTextContent content = getContentInstance();
    String newText;
    content.setText("This\nis a test\r");
    content.replaceTextRange(6, 2, "");
    newText = content.getTextRange(0, content.getCharCount());
    assertTrue(":1a:", newText.equals("This\nia test\r"));
    assertTrue(":1b:", content.getLine(0).equals("This"));
    assertTrue(":1c:", content.getLine(1).equals("ia test"));
    content.setText("This\nis a test\r");
    content.replaceTextRange(5, 9, "");
    newText = content.getTextRange(0, content.getCharCount());
    assertTrue(":2a:", newText.equals("This\n\r"));
    assertTrue(":2b:", content.getLineCount() == 3);
    assertTrue(":2c:", content.getLine(0).equals("This"));
    assertTrue(":2d:", content.getLine(1).isEmpty());
    assertTrue(":2e:", content.getLine(2).isEmpty());
    content.setText("This\nis a test\nline 3\nline 4");
    content.replaceTextRange(21, 7, "");
    newText = content.getTextRange(0, content.getCharCount());
    assertTrue(":3a:", newText.equals("This\nis a test\nline 3"));
    assertTrue(":3b:", content.getLineCount() == 3);
    assertTrue(":3c:", content.getLine(0).equals("This"));
    assertTrue(":3d:", content.getLine(1).equals("is a test"));
    assertTrue(":3e:", content.getLine(2).equals("line 3"));
    content.setText("This\nis a test\nline 3\nline 4");
    content.replaceTextRange(0, 5, "");
    newText = content.getTextRange(0, content.getCharCount());
    assertTrue(":4a:", newText.equals("is a test\nline 3\nline 4"));
    assertTrue(":4b:", content.getLineCount() == 3);
    assertTrue(":4c:", content.getLine(0).equals("is a test"));
    assertTrue(":4d:", content.getLine(1).equals("line 3"));
    assertTrue(":4e:", content.getLine(2).equals("line 4"));
    content.replaceTextRange(16, 7, "");
    newText = content.getTextRange(0, content.getCharCount());
    assertTrue(":4f:", newText.equals("is a test\nline 3"));
    assertTrue(":4g:", content.getLine(0).equals("is a test"));
    assertTrue(":4h:", content.getLine(1).equals("line 3"));
    content.replaceTextRange(9, 7, "");
    newText = content.getTextRange(0, content.getCharCount());
    assertTrue(":4i:", newText.equals("is a test"));
    assertTrue(":4j:", content.getLine(0).equals("is a test"));
    content.replaceTextRange(1, 8, "");
    newText = content.getTextRange(0, content.getCharCount());
    assertTrue(":4k:", newText.equals("i"));
    assertTrue(":4l:", content.getLine(0).equals("i"));
    content.replaceTextRange(0, 1, "");
    newText = content.getTextRange(0, content.getCharCount());
    assertTrue(":4m:", newText.isEmpty());
    assertTrue(":4n:", content.getLine(0).isEmpty());
    content.setText("This\nis a test\r");
    content.replaceTextRange(5, 9, "");
    newText = content.getTextRange(0, content.getCharCount());
    assertTrue(":5a:", newText.equals("This\n\r"));
    assertTrue(":5b:", content.getLineCount() == 3);
    assertTrue(":5c:", content.getLine(0).equals("This"));
    assertTrue(":5d:", content.getLine(1).isEmpty());
    assertTrue(":5e:", content.getLine(2).isEmpty());
    content.setText("L1\r\nL2\r\nL3\r\nL4\r\n");
    content.replaceTextRange(4, 8, "");
    newText = content.getTextRange(0, content.getCharCount());
    assertTrue(":6a:", newText.equals("L1\r\nL4\r\n"));
    assertTrue(":6b:", content.getLineCount() == 3);
    assertTrue(":6c:", content.getLine(0).equals("L1"));
    assertTrue(":6d:", content.getLine(1).equals("L4"));
    assertTrue(":6e:", content.getLine(2).isEmpty());
    content.setText("\nL1\r\nL2");
    content.replaceTextRange(0, 1, "");
    newText = content.getTextRange(0, content.getCharCount());
    assertTrue(":7a:", newText.equals("L1\r\nL2"));
    assertTrue(":7b:", content.getLineCount() == 2);
    assertTrue(":7c:", content.getLine(0).equals("L1"));
    assertTrue(":7d:", content.getLine(1).equals("L2"));
    content.setText("\nL1\r\nL2\r\n");
    content.replaceTextRange(7, 2, "");
    newText = content.getTextRange(0, content.getCharCount());
    assertTrue(":8a:", newText.equals("\nL1\r\nL2"));
    assertTrue(":8b:", content.getLineCount() == 3);
    assertTrue(":8c:", content.getLine(0).isEmpty());
    assertTrue(":8d:", content.getLine(1).equals("L1"));
    assertTrue(":8e:", content.getLine(2).equals("L2"));
    content.setText("\nLine 1\nLine 2\n");
    content.replaceTextRange(0, 7, "");
    newText = content.getTextRange(0, content.getCharCount());
    assertTrue(":9a:", newText.equals("\nLine 2\n"));
    assertTrue(":9b:", content.getLineCount() == 3);
    assertTrue(":9c:", content.getLine(0).isEmpty());
    assertTrue(":9d:", content.getLine(1).equals("Line 2"));
    assertTrue(":9e:", content.getLine(2).isEmpty());
    content.setText("Line 1\nLine 2\n");
    content.replaceTextRange(6, 8, "");
    newText = content.getTextRange(0, content.getCharCount());
    assertTrue(":10a:", newText.equals("Line 1"));
    assertTrue(":10b:", content.getLineCount() == 1);
    assertTrue(":10c:", content.getLine(0).equals("Line 1"));
    content.setText("Line one is short\r\nLine 2 is a longer line\r\nLine 3\n");
    content.replaceTextRange(12, 17, "");
    newText = content.getTextRange(0, content.getCharCount());
    assertTrue(":11a:", newText.equals("Line one is a longer line\r\nLine 3\n"));
    assertTrue(":11b:", content.getLineCount() == 3);
    assertTrue(":11c:", content.getLine(0).equals("Line one is a longer line"));
    assertTrue(":11d:", content.getLine(1).equals("Line 3"));
    assertTrue(":11e:", content.getLine(2).isEmpty());
}
Also used : StyledTextContent(org.eclipse.swt.custom.StyledTextContent)

Aggregations

StyledTextContent (org.eclipse.swt.custom.StyledTextContent)26 TextChangeListener (org.eclipse.swt.custom.TextChangeListener)6 Test (org.junit.Test)6 TextChangedEvent (org.eclipse.swt.custom.TextChangedEvent)3 TextChangingEvent (org.eclipse.swt.custom.TextChangingEvent)3 Point (org.eclipse.swt.graphics.Point)3 StyleRange (org.eclipse.swt.custom.StyleRange)1 Color (org.eclipse.swt.graphics.Color)1