コード例 #1
0
  /** Test method for {@link JavadocBlockParserUtil#fetchBlockInfo(JavadocScanner)}. */
  @Test
  public void testFetchBlockInfoBroken() {
    DefaultJavadocScanner scanner = scanner("broken-inline.txt");
    JavadocBlockInfo block = JavadocBlockParserUtil.fetchBlockInfo(scanner);
    assertEquals(JavadocTokenKind.EOF, scanner.lookahead(0).getKind());
    assertEquals("code", block.getTagName());
    assertEquals(0, block.getLocation().getStartPosition());
    assertEquals(scanner.lookahead(0).getStartPosition(), block.getLocation().getLength());

    JavadocScanner bScanner = block.getBlockScanner();
    IrDocText inline = JavadocBlockParserUtil.fetchText(bScanner, false, false);
    assertEquals(" Hello, world! EOF->", inline.getContent());
    assertEquals(JavadocTokenKind.EOF, bScanner.lookahead(0).getKind());
  }
コード例 #2
0
  /** Test method for {@link JavadocBlockParserUtil#fetchText(JavadocScanner, boolean, boolean)}. */
  @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);
    }
  }