Search in sources :

Example 11 with StyledTextContent

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

the class Test_org_eclipse_swt_custom_StyledText method test_getContent.

@Test
public void test_getContent() {
    StyledTextContent content = text.getContent();
    assertNotNull(content);
    content = new StyledTextContent() {

        @Override
        public void addTextChangeListener(TextChangeListener listener) {
        }

        @Override
        public int getCharCount() {
            return 0;
        }

        @Override
        public String getLine(int lineIndex) {
            return "";
        }

        @Override
        public int getLineAtOffset(int offset) {
            return 0;
        }

        @Override
        public int getLineCount() {
            return 0;
        }

        @Override
        public String getLineDelimiter() {
            return "";
        }

        @Override
        public int getOffsetAtLine(int lineIndex) {
            return 0;
        }

        @Override
        public String getTextRange(int start, int length) {
            return "";
        }

        @Override
        public void removeTextChangeListener(TextChangeListener listener) {
        }

        @Override
        public void replaceTextRange(int start, int replaceLength, String text) {
        }

        @Override
        public void setText(String text) {
        }
    };
    text.setContent(content);
    assertEquals(content, text.getContent());
}
Also used : StyledTextContent(org.eclipse.swt.custom.StyledTextContent) TextChangeListener(org.eclipse.swt.custom.TextChangeListener) Point(org.eclipse.swt.graphics.Point) Test(org.junit.Test)

Example 12 with StyledTextContent

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

the class Test_org_eclipse_swt_custom_StyledText method test_setContentLorg_eclipse_swt_custom_StyledTextContent.

@Test
public void test_setContentLorg_eclipse_swt_custom_StyledTextContent() {
    boolean exceptionThrown;
    StyledTextContent content = new StyledTextContent() {

        @Override
        public void addTextChangeListener(TextChangeListener listener) {
        }

        @Override
        public int getCharCount() {
            return 0;
        }

        @Override
        public String getLine(int lineIndex) {
            return "";
        }

        @Override
        public int getLineAtOffset(int offset) {
            return 0;
        }

        @Override
        public int getLineCount() {
            return 0;
        }

        @Override
        public String getLineDelimiter() {
            return "";
        }

        @Override
        public int getOffsetAtLine(int lineIndex) {
            return 0;
        }

        @Override
        public String getTextRange(int start, int length) {
            return "";
        }

        @Override
        public void removeTextChangeListener(TextChangeListener listener) {
        }

        @Override
        public void replaceTextRange(int start, int replaceLength, String text) {
        }

        @Override
        public void setText(String text) {
        }
    };
    text.setContent(content);
    assertEquals(content, text.getContent());
    exceptionThrown = false;
    try {
        text.setContent(null);
    } catch (IllegalArgumentException e) {
        exceptionThrown = true;
    }
    assertTrue(exceptionThrown);
}
Also used : StyledTextContent(org.eclipse.swt.custom.StyledTextContent) TextChangeListener(org.eclipse.swt.custom.TextChangeListener) Test(org.junit.Test)

Example 13 with StyledTextContent

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

the class StyledTextContentSpec method test_Line_To_Offset.

public void test_Line_To_Offset() {
    StyledTextContent content = getContentInstance();
    content.setText("This\nis a test\rrepeat\nend\r");
    assertWithMessage(":1a:", content.getOffsetAtLine(0) == 0);
    assertWithMessage(":1b:", content.getOffsetAtLine(1) == 5);
    assertWithMessage(":1c:", content.getOffsetAtLine(2) == 15);
    assertWithMessage(":1d:", content.getOffsetAtLine(3) == 22);
    assertWithMessage(":1e:", content.getOffsetAtLine(4) == 26);
    content.setText("This\r\nis a test");
    assertWithMessage(":2a:", content.getOffsetAtLine(0) == 0);
    assertWithMessage(":2b:", content.getOffsetAtLine(1) == 6);
    content.setText("\r\n");
    assertWithMessage(":3a:", content.getOffsetAtLine(0) == 0);
    assertWithMessage(":3b:", content.getOffsetAtLine(1) == 2);
    content.setText("\r\n\n\r\r\n");
    assertWithMessage(":4a:", content.getOffsetAtLine(0) == 0);
    assertWithMessage(":4b:", content.getOffsetAtLine(1) == 2);
    assertWithMessage(":4c:", content.getOffsetAtLine(2) == 3);
    assertWithMessage(":4d:", content.getOffsetAtLine(3) == 4);
    assertWithMessage(":4e:", content.getOffsetAtLine(4) == 6);
    content.setText("\r\ntest\r\n");
    assertWithMessage(":5a:", content.getOffsetAtLine(0) == 0);
    assertWithMessage(":5b:", content.getOffsetAtLine(1) == 2);
    assertWithMessage(":5c:", content.getOffsetAtLine(2) == 8);
}
Also used : StyledTextContent(org.eclipse.swt.custom.StyledTextContent)

Example 14 with StyledTextContent

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

the class StyledTextContentSpec method test_Empty.

public void test_Empty() {
    StyledTextContent content = getContentInstance();
    assertWithMessage(":1a:", content.getLineCount() == 1);
    assertWithMessage(":1b:", content.getLine(0).equals(""));
    content.setText("test");
    content.replaceTextRange(0, 4, "");
    assertWithMessage(":2a:", content.getLineCount() == 1);
    assertWithMessage(":2b:", content.getLine(0).equals(""));
}
Also used : StyledTextContent(org.eclipse.swt.custom.StyledTextContent)

Example 15 with StyledTextContent

use of org.eclipse.swt.custom.StyledTextContent in project webtools.sourceediting 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());
    assertWithMessage(":1a:", newText.equals("This\nia test\r"));
    assertWithMessage(":1b:", content.getLine(0).equals("This"));
    assertWithMessage(":1c:", content.getLine(1).equals("ia test"));
    content.setText("This\nis a test\r");
    content.replaceTextRange(5, 9, "");
    newText = content.getTextRange(0, content.getCharCount());
    assertWithMessage(":2a:", newText.equals("This\n\r"));
    assertWithMessage(":2b:", content.getLineCount() == 3);
    assertWithMessage(":2c:", content.getLine(0).equals("This"));
    assertWithMessage(":2d:", content.getLine(1).equals(""));
    assertWithMessage(":2e:", content.getLine(2).equals(""));
    content.setText("This\nis a test\nline 3\nline 4");
    content.replaceTextRange(21, 7, "");
    newText = content.getTextRange(0, content.getCharCount());
    assertWithMessage(":3a:", newText.equals("This\nis a test\nline 3"));
    assertWithMessage(":3b:", content.getLineCount() == 3);
    assertWithMessage(":3c:", content.getLine(0).equals("This"));
    assertWithMessage(":3d:", content.getLine(1).equals("is a test"));
    assertWithMessage(":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());
    assertWithMessage(":4a:", newText.equals("is a test\nline 3\nline 4"));
    assertWithMessage(":4b:", content.getLineCount() == 3);
    assertWithMessage(":4c:", content.getLine(0).equals("is a test"));
    assertWithMessage(":4d:", content.getLine(1).equals("line 3"));
    assertWithMessage(":4e:", content.getLine(2).equals("line 4"));
    content.replaceTextRange(16, 7, "");
    newText = content.getTextRange(0, content.getCharCount());
    assertWithMessage(":4f:", newText.equals("is a test\nline 3"));
    assertWithMessage(":4g:", content.getLine(0).equals("is a test"));
    assertWithMessage(":4h:", content.getLine(1).equals("line 3"));
    content.replaceTextRange(9, 7, "");
    newText = content.getTextRange(0, content.getCharCount());
    assertWithMessage(":4i:", newText.equals("is a test"));
    assertWithMessage(":4j:", content.getLine(0).equals("is a test"));
    content.replaceTextRange(1, 8, "");
    newText = content.getTextRange(0, content.getCharCount());
    assertWithMessage(":4k:", newText.equals("i"));
    assertWithMessage(":4l:", content.getLine(0).equals("i"));
    content.replaceTextRange(0, 1, "");
    newText = content.getTextRange(0, content.getCharCount());
    assertWithMessage(":4m:", newText.equals(""));
    assertWithMessage(":4n:", content.getLine(0).equals(""));
    content.setText("This\nis a test\r");
    content.replaceTextRange(5, 9, "");
    newText = content.getTextRange(0, content.getCharCount());
    assertWithMessage(":5a:", newText.equals("This\n\r"));
    assertWithMessage(":5b:", content.getLineCount() == 3);
    assertWithMessage(":5c:", content.getLine(0).equals("This"));
    assertWithMessage(":5d:", content.getLine(1).equals(""));
    assertWithMessage(":5e:", content.getLine(2).equals(""));
    content.setText("L1\r\nL2\r\nL3\r\nL4\r\n");
    content.replaceTextRange(4, 8, "");
    newText = content.getTextRange(0, content.getCharCount());
    assertWithMessage(":6a:", newText.equals("L1\r\nL4\r\n"));
    assertWithMessage(":6b:", content.getLineCount() == 3);
    assertWithMessage(":6c:", content.getLine(0).equals("L1"));
    assertWithMessage(":6d:", content.getLine(1).equals("L4"));
    assertWithMessage(":6e:", content.getLine(2).equals(""));
    content.setText("\nL1\r\nL2");
    content.replaceTextRange(0, 1, "");
    newText = content.getTextRange(0, content.getCharCount());
    assertWithMessage(":7a:", newText.equals("L1\r\nL2"));
    assertWithMessage(":7b:", content.getLineCount() == 2);
    assertWithMessage(":7c:", content.getLine(0).equals("L1"));
    assertWithMessage(":7d:", content.getLine(1).equals("L2"));
    content.setText("\nL1\r\nL2\r\n");
    content.replaceTextRange(7, 2, "");
    newText = content.getTextRange(0, content.getCharCount());
    assertWithMessage(":8a:", newText.equals("\nL1\r\nL2"));
    assertWithMessage(":8b:", content.getLineCount() == 3);
    assertWithMessage(":8c:", content.getLine(0).equals(""));
    assertWithMessage(":8d:", content.getLine(1).equals("L1"));
    assertWithMessage(":8e:", content.getLine(2).equals("L2"));
    content.setText("\nLine 1\nLine 2\n");
    content.replaceTextRange(0, 7, "");
    newText = content.getTextRange(0, content.getCharCount());
    assertWithMessage(":9a:", newText.equals("\nLine 2\n"));
    assertWithMessage(":9b:", content.getLineCount() == 3);
    assertWithMessage(":9c:", content.getLine(0).equals(""));
    assertWithMessage(":9d:", content.getLine(1).equals("Line 2"));
    assertWithMessage(":9e:", content.getLine(2).equals(""));
    content.setText("Line 1\nLine 2\n");
    content.replaceTextRange(6, 8, "");
    newText = content.getTextRange(0, content.getCharCount());
    assertWithMessage(":10a:", newText.equals("Line 1"));
    assertWithMessage(":10b:", content.getLineCount() == 1);
    assertWithMessage(":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());
    assertWithMessage(":11a:", newText.equals("Line one is a longer line\r\nLine 3\n"));
    assertWithMessage(":11b:", content.getLineCount() == 3);
    assertWithMessage(":11c:", content.getLine(0).equals("Line one is a longer line"));
    assertWithMessage(":11d:", content.getLine(1).equals("Line 3"));
    assertWithMessage(":11e:", content.getLine(2).equals(""));
}
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