use of org.eclipse.mylyn.wikitext.util.LocationTrackingReader in project mylyn.docs by eclipse.
the class LocationTrackingReaderTest method testCharOffset.
public void testCharOffset() throws IOException {
String content = "aaflkjsdf \nas;dfj asl;fj\r\naslfkjasd";
int count = 0;
LocationTrackingReader reader = new LocationTrackingReader(new StringReader(content), 16);
int c;
while ((c = reader.read()) != -1) {
++count;
assertEquals(content.charAt(count - 1), (char) c);
assertEquals(count - 1, reader.getOffset());
}
assertEquals(content.length(), count);
}
use of org.eclipse.mylyn.wikitext.util.LocationTrackingReader in project mylyn.docs by eclipse.
the class LocationTrackingReaderTest method doTest.
private void doTest(String content, int[] lineOffsets, int bufSize) throws IOException {
LocationTrackingReader reader = new LocationTrackingReader(new StringReader(content), bufSize);
BufferedReader refReader = new BufferedReader(new StringReader(content));
int lineNumber = 0;
String testLine = null;
String refLine = null;
do {
int expectedOffset = lineOffsets[lineNumber++];
testLine = reader.readLine();
refLine = refReader.readLine();
assertEquals(refLine, testLine);
assertEquals(expectedOffset, reader.getLineOffset());
assertEquals(lineNumber - 1, reader.getLineNumber());
} while (testLine != null && refLine != null);
assertTrue(refLine == null);
assertTrue(testLine == null);
}
use of org.eclipse.mylyn.wikitext.util.LocationTrackingReader in project mylyn.docs by eclipse.
the class LookAheadReader method setContentState.
public void setContentState(ContentState state) {
if (mustInitReader(state)) {
this.state = state;
this.reader = new LocationTrackingReader(new StringReader(state.getMarkupContent()));
}
}
use of org.eclipse.mylyn.wikitext.util.LocationTrackingReader in project mylyn.docs by eclipse.
the class CommonMarkSpecTest method loadSpec.
private static void loadSpec(ImmutableList.Builder<Object[]> parameters) {
Pattern headingPattern = Pattern.compile("#+\\s*(.+)");
try {
String spec = loadCommonMarkSpec();
LocationTrackingReader reader = new LocationTrackingReader(new StringReader(spec));
String heading = "unspecified";
String line;
while ((line = reader.readLine()) != null) {
line = line.replace('→', '\t');
if (line.trim().equals(".")) {
int testLineNumber = reader.getLineNumber();
Expectation expectation = readExpectation(reader);
parameters.add(new Object[] { heading + ":line " + testLineNumber, heading, testLineNumber, expectation });
}
Matcher headingMatcher = headingPattern.matcher(line);
if (headingMatcher.matches()) {
heading = headingMatcher.group(1);
}
}
} catch (IOException e) {
throw Throwables.propagate(e);
}
}
use of org.eclipse.mylyn.wikitext.util.LocationTrackingReader in project mylyn.docs by eclipse.
the class LookAheadReader method setContentState.
public void setContentState(ContentState state) {
if (mustInitReader(state)) {
this.state = state;
this.reader = new LocationTrackingReader(new StringReader(state.getMarkupContent()));
}
}
Aggregations