Search in sources :

Example 1 with HTML2TextReader

use of org.eclipse.jface.internal.text.html.HTML2TextReader in project eclipse.platform.text by eclipse.

the class HTML2TextReaderTest method testBug367378.

@Test
public void testBug367378() throws IOException {
    verify("<head>", "", 0);
    verify("<head>some styles</html>", "", 0);
    char[] cb = new char[20];
    StringReader reader = new StringReader("<head>");
    try (HTML2TextReader r = new HTML2TextReader(reader, null)) {
        r.read(cb);
    }
    assertTrue(Arrays.equals(new char[20], cb));
}
Also used : HTML2TextReader(org.eclipse.jface.internal.text.html.HTML2TextReader) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 2 with HTML2TextReader

use of org.eclipse.jface.internal.text.html.HTML2TextReader in project eclipse.platform.text by eclipse.

the class HTML2TextReaderTest method verify.

/**
 * @param input input
 * @param expectedOutput expected output
 * @param styleRangeCount count
 * @throws IOException test failure
 * @deprecated pass actual style ranges
 */
@Deprecated
private void verify(String input, String expectedOutput, int styleRangeCount) throws IOException {
    Reader reader = new StringReader(input);
    TextPresentation textPresentation = new TextPresentation();
    String result;
    try (HTML2TextReader htmlReader = new HTML2TextReader(reader, textPresentation)) {
        result = htmlReader.getString();
    }
    if (DEBUG)
        System.out.println("<" + result + "/>");
    assertEquals(expectedOutput, result);
    Iterator<StyleRange> styleRangeIterator = textPresentation.getAllStyleRangeIterator();
    List<StyleRange> ranges = new ArrayList<>();
    while (styleRangeIterator.hasNext()) {
        ranges.add(styleRangeIterator.next());
    }
    assertEquals("Incorrect number of style ranges", styleRangeCount, ranges.size());
    Collections.sort(ranges, (r1, r2) -> r1.start - r2.start);
    for (int i = 0; i < ranges.size() - 1; i++) {
        StyleRange range1 = ranges.get(i);
        StyleRange range2 = ranges.get(i + 1);
        if (range1.start + range1.length > range2.start) {
            assertTrue("StyleRanges overlap", false);
        }
    }
}
Also used : HTML2TextReader(org.eclipse.jface.internal.text.html.HTML2TextReader) StyleRange(org.eclipse.swt.custom.StyleRange) StringReader(java.io.StringReader) ArrayList(java.util.ArrayList) Reader(java.io.Reader) StringReader(java.io.StringReader) HTML2TextReader(org.eclipse.jface.internal.text.html.HTML2TextReader) TextPresentation(org.eclipse.jface.text.TextPresentation)

Example 3 with HTML2TextReader

use of org.eclipse.jface.internal.text.html.HTML2TextReader in project eclipse.platform.text by eclipse.

the class HTML2TextReaderTest method verify.

private void verify(String input, String expectedOutput, StyleRange[] styleRanges) throws IOException {
    Reader reader = new StringReader(input);
    TextPresentation textPresentation = new TextPresentation();
    String result;
    try (HTML2TextReader htmlReader = new HTML2TextReader(reader, textPresentation)) {
        result = htmlReader.getString();
    }
    if (DEBUG)
        System.out.println("<" + result + "/>");
    assertEquals(expectedOutput, result);
    Iterator<StyleRange> styleRangeIterator = textPresentation.getAllStyleRangeIterator();
    List<StyleRange> ranges = new ArrayList<>();
    while (styleRangeIterator.hasNext()) {
        ranges.add(styleRangeIterator.next());
    }
    Collections.sort(ranges, (r1, r2) -> r1.start - r2.start);
    assertEquals(Arrays.asList(styleRanges), ranges);
    for (int i = 0; i < ranges.size() - 1; i++) {
        StyleRange range1 = ranges.get(i);
        StyleRange range2 = ranges.get(i + 1);
        if (range1.start + range1.length > range2.start) {
            assertTrue("StyleRanges overlap", false);
        }
    }
}
Also used : HTML2TextReader(org.eclipse.jface.internal.text.html.HTML2TextReader) StyleRange(org.eclipse.swt.custom.StyleRange) StringReader(java.io.StringReader) ArrayList(java.util.ArrayList) Reader(java.io.Reader) StringReader(java.io.StringReader) HTML2TextReader(org.eclipse.jface.internal.text.html.HTML2TextReader) TextPresentation(org.eclipse.jface.text.TextPresentation)

Aggregations

StringReader (java.io.StringReader)3 HTML2TextReader (org.eclipse.jface.internal.text.html.HTML2TextReader)3 Reader (java.io.Reader)2 ArrayList (java.util.ArrayList)2 TextPresentation (org.eclipse.jface.text.TextPresentation)2 StyleRange (org.eclipse.swt.custom.StyleRange)2 Test (org.junit.Test)1