Search in sources :

Example 1 with LocationTrackingReader

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);
}
Also used : LocationTrackingReader(org.eclipse.mylyn.wikitext.util.LocationTrackingReader) StringReader(java.io.StringReader)

Example 2 with LocationTrackingReader

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);
}
Also used : LocationTrackingReader(org.eclipse.mylyn.wikitext.util.LocationTrackingReader) StringReader(java.io.StringReader) BufferedReader(java.io.BufferedReader)

Example 3 with LocationTrackingReader

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()));
    }
}
Also used : LocationTrackingReader(org.eclipse.mylyn.wikitext.util.LocationTrackingReader) StringReader(java.io.StringReader)

Example 4 with LocationTrackingReader

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);
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) LocationTrackingReader(org.eclipse.mylyn.wikitext.util.LocationTrackingReader) StringReader(java.io.StringReader) IOException(java.io.IOException)

Example 5 with LocationTrackingReader

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()));
    }
}
Also used : LocationTrackingReader(org.eclipse.mylyn.wikitext.util.LocationTrackingReader) StringReader(java.io.StringReader)

Aggregations

StringReader (java.io.StringReader)6 LocationTrackingReader (org.eclipse.mylyn.wikitext.util.LocationTrackingReader)6 IOException (java.io.IOException)2 BufferedReader (java.io.BufferedReader)1 Stack (java.util.Stack)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 DocumentBuilder (org.eclipse.mylyn.wikitext.parser.DocumentBuilder)1