Search in sources :

Example 1 with Locator

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());
}
Also used : Locator(org.eclipse.mylyn.wikitext.parser.Locator) Test(org.junit.Test)

Example 2 with Locator

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());
}
Also used : Line(org.eclipse.mylyn.wikitext.commonmark.internal.Line) Locator(org.eclipse.mylyn.wikitext.parser.Locator) DocumentBuilder(org.eclipse.mylyn.wikitext.parser.DocumentBuilder) Test(org.junit.Test)

Example 3 with Locator

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);
}
Also used : Locator(org.eclipse.mylyn.wikitext.parser.Locator) StringWriter(java.io.StringWriter) Attributes(org.eclipse.mylyn.wikitext.parser.Attributes) AtomicReference(java.util.concurrent.atomic.AtomicReference) LocatorImpl(org.eclipse.mylyn.wikitext.util.LocatorImpl) HtmlDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder) MarkupParser(org.eclipse.mylyn.wikitext.parser.MarkupParser)

Example 4 with Locator

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());
}
Also used : Locator(org.eclipse.mylyn.wikitext.parser.Locator) Test(org.junit.Test)

Example 5 with Locator

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());
}
Also used : Locator(org.eclipse.mylyn.wikitext.parser.Locator) Test(org.junit.Test)

Aggregations

Locator (org.eclipse.mylyn.wikitext.parser.Locator)6 Test (org.junit.Test)5 DocumentBuilder (org.eclipse.mylyn.wikitext.parser.DocumentBuilder)2 StringWriter (java.io.StringWriter)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Line (org.eclipse.mylyn.wikitext.commonmark.internal.Line)1 Attributes (org.eclipse.mylyn.wikitext.parser.Attributes)1 MarkupParser (org.eclipse.mylyn.wikitext.parser.MarkupParser)1 EventDocumentBuilder (org.eclipse.mylyn.wikitext.parser.builder.EventDocumentBuilder)1 HtmlDocumentBuilder (org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder)1 MultiplexingDocumentBuilder (org.eclipse.mylyn.wikitext.parser.builder.MultiplexingDocumentBuilder)1 NoOpDocumentBuilder (org.eclipse.mylyn.wikitext.parser.builder.NoOpDocumentBuilder)1 ContentState (org.eclipse.mylyn.wikitext.parser.markup.ContentState)1 LocatorImpl (org.eclipse.mylyn.wikitext.util.LocatorImpl)1