use of org.eclipse.mylyn.wikitext.parser.Locator in project mylyn.docs by eclipse.
the class LineTest method toLocator.
@Test
public void toLocator() {
Line line = new Line(2, 15, "0123456789");
Locator locator = line.toLocator();
assertNotNull(locator);
assertEquals(3, locator.getLineNumber());
assertEquals(15, locator.getLineDocumentOffset());
}
use of org.eclipse.mylyn.wikitext.parser.Locator in project mylyn.docs by eclipse.
the class InlineTest method create.
@Test
public void create() {
Line line = new Line(3, 5, "text");
Inline inline = new Inline(line, 8, 3) {
@Override
public void emit(DocumentBuilder builder) {
}
};
assertSame(line, inline.getLine());
assertEquals(8, inline.getOffset());
assertEquals(3, inline.getLength());
Locator locator = inline.getLocator();
assertEquals(3, locator.getLineCharacterOffset());
assertEquals(6, locator.getLineSegmentEndOffset());
assertEquals(8, locator.getDocumentOffset());
assertEquals(line.getOffset(), locator.getLineDocumentOffset());
assertEquals(line.getText().length(), locator.getLineLength());
assertEquals(line.getLineNumber() + 1, locator.getLineNumber());
}
use of org.eclipse.mylyn.wikitext.parser.Locator in project mylyn.docs by eclipse.
the class CommonMarkLanguageDocumentOffsetsTest method assertSpanOffsets.
private void assertSpanOffsets(int offset, int length, String expectedHtml, String markup) {
final AtomicReference<Locator> spanLocator = new AtomicReference<Locator>();
CommonMarkLanguage language = new CommonMarkLanguage();
MarkupParser parser = new MarkupParser(language);
StringWriter out = new StringWriter();
HtmlDocumentBuilder builder = new HtmlDocumentBuilder(out) {
@Override
public void beginSpan(SpanType type, Attributes attributes) {
assertNull(spanLocator.get());
spanLocator.set(new LocatorImpl(getLocator()));
super.beginSpan(type, attributes);
}
};
builder.setEmitAsDocument(false);
parser.setBuilder(builder);
parser.parse(markup);
assertEquals(expectedHtml, out.toString());
Locator locator = spanLocator.get();
assertNotNull(locator);
assertEquals(offset, locator.getDocumentOffset());
int actualLength = locator.getLineSegmentEndOffset() - locator.getLineCharacterOffset();
assertEquals(length, actualLength);
}
use of org.eclipse.mylyn.wikitext.parser.Locator in project mylyn.docs by eclipse.
the class SimpleLocatorTest method createFromLine.
@Test
public void createFromLine() {
Line line = new Line(2, 104, "one two");
Locator simpleLocator = new SimpleLocator(line);
assertEquals(104, simpleLocator.getDocumentOffset());
assertEquals(0, simpleLocator.getLineCharacterOffset());
assertEquals(104, simpleLocator.getLineDocumentOffset());
assertEquals(7, simpleLocator.getLineLength());
assertEquals(3, simpleLocator.getLineNumber());
assertEquals(7, simpleLocator.getLineSegmentEndOffset());
}
use of org.eclipse.mylyn.wikitext.parser.Locator in project mylyn.docs by eclipse.
the class SimpleLocatorTest method createFromLineWithSegmentOffset.
@Test
public void createFromLineWithSegmentOffset() {
Line line = new Line(2, 104, "one two");
Locator simpleLocator = new SimpleLocator(line, 2, 6);
assertEquals(106, simpleLocator.getDocumentOffset());
assertEquals(2, simpleLocator.getLineCharacterOffset());
assertEquals(104, simpleLocator.getLineDocumentOffset());
assertEquals(7, simpleLocator.getLineLength());
assertEquals(3, simpleLocator.getLineNumber());
assertEquals(6, simpleLocator.getLineSegmentEndOffset());
}
Aggregations