@Test
public void testFetchText() {
DefaultJavadocScanner scanner = scanner("testFetchText.txt");
{
int offset = scanner.lookahead(0).getStartPosition();
IrDocText text = JavadocBlockParserUtil.fetchText(scanner, false, false);
assertEquals("onlyIdentifier", text.getContent());
assertNotNull(text.getLocation());
assertEquals(offset, text.getLocation().getStartPosition());
assertEquals(text.getContent().length(), text.getLocation().getLength());
assertEquals(JavadocTokenKind.LINE_BREAK, scanner.lookahead(0).getKind());
scanner.consume(JavadocScannerUtil.countUntilNextLineStart(scanner, 0));
}
{
int offset = scanner.lookahead(0).getStartPosition();
IrDocText text = JavadocBlockParserUtil.fetchText(scanner, false, false);
assertEquals("Identifier with space", text.getContent());
assertNotNull(text.getLocation());
assertEquals(offset, text.getLocation().getStartPosition());
assertEquals(text.getContent().length(), text.getLocation().getLength());
assertEquals(JavadocTokenKind.LINE_BREAK, scanner.lookahead(0).getKind());
scanner.consume(JavadocScannerUtil.countUntilNextLineStart(scanner, 0));
}
{
IrDocText text = JavadocBlockParserUtil.fetchText(scanner, false, false);
assertNull(text);
scanner.consume(JavadocScannerUtil.countUntilNextLineStart(scanner, 0));
}
{
int offset = scanner.lookahead(0).getStartPosition();
IrDocText text = JavadocBlockParserUtil.fetchText(scanner, false, false);
assertEquals("head ", text.getContent());
assertNotNull(text.getLocation());
assertEquals(offset, text.getLocation().getStartPosition());
assertEquals(text.getContent().length(), text.getLocation().getLength());
assertEquals(JavadocTokenKind.LEFT_BRACE, scanner.lookahead(0).getKind());
scanner.consume(JavadocScannerUtil.countUntil(EnumSet.of(JavadocTokenKind.RIGHT_BRACE), scanner, 0) + 1);
offset = scanner.lookahead(0).getStartPosition();
text = JavadocBlockParserUtil.fetchText(scanner, false, false);
assertEquals(" tail", text.getContent());
assertNotNull(text.getLocation());
assertEquals(offset, text.getLocation().getStartPosition());
assertEquals(text.getContent().length(), text.getLocation().getLength());
assertEquals(JavadocTokenKind.LINE_BREAK, scanner.lookahead(0).getKind());
scanner.consume(JavadocScannerUtil.countUntilNextLineStart(scanner, 0));
}
{
int offset = scanner.lookahead(0).getStartPosition();
IrDocText text = JavadocBlockParserUtil.fetchText(scanner, false, false);
assertEquals(" <- 3spaces -> ", text.getContent());
assertNotNull(text.getLocation());
assertEquals(offset, text.getLocation().getStartPosition());
assertEquals(text.getContent().length(), text.getLocation().getLength());
assertEquals(JavadocTokenKind.LINE_BREAK, scanner.lookahead(0).getKind());
scanner.consume(JavadocScannerUtil.countUntilNextLineStart(scanner, 0));
}
{
int offset = scanner.lookahead(0).getStartPosition();
IrDocText text = JavadocBlockParserUtil.fetchText(scanner, true, false);
assertEquals("<- 3spaces -> ", text.getContent());
assertNotNull(text.getLocation());
assertEquals(offset + 3, text.getLocation().getStartPosition());
assertEquals(text.getContent().length(), text.getLocation().getLength());
assertEquals(JavadocTokenKind.LINE_BREAK, scanner.lookahead(0).getKind());
scanner.consume(JavadocScannerUtil.countUntilNextLineStart(scanner, 0));
}
{
int offset = scanner.lookahead(0).getStartPosition();
IrDocText text = JavadocBlockParserUtil.fetchText(scanner, false, true);
assertEquals(" <- 3spaces ->", text.getContent());
assertNotNull(text.getLocation());
assertEquals(offset, text.getLocation().getStartPosition());
assertEquals(text.getContent().length(), text.getLocation().getLength());
assertEquals(JavadocTokenKind.LINE_BREAK, scanner.lookahead(0).getKind());
scanner.consume(JavadocScannerUtil.countUntilNextLineStart(scanner, 0));
}
{
int offset = scanner.lookahead(0).getStartPosition();
IrDocText text = JavadocBlockParserUtil.fetchText(scanner, true, true);
assertEquals("<- 3spaces ->", text.getContent());
assertNotNull(text.getLocation());
assertEquals(offset + 3, text.getLocation().getStartPosition());
assertEquals(text.getContent().length(), text.getLocation().getLength());
assertEquals(JavadocTokenKind.LINE_BREAK, scanner.lookahead(0).getKind());
scanner.consume(JavadocScannerUtil.countUntilNextLineStart(scanner, 0));
}
{
IrDocText text = JavadocBlockParserUtil.fetchText(scanner, false, false);
assertNull(text);
}
}