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));
}
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);
}
}
}
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);
}
}
}
Aggregations