public void testParseFileLongerThan2048chars() throws ParseException {
    StringBuilder b = new StringBuilder();
    for (int i = 0; i < 2048 * 3; i++) {
      b.append('*');
    }

    String code =
        "<!doctype html>\n"
            + "<html>\n"
            + "<title></title>\n"
            + "<body>\n"
            + b.toString()
            + "</body>\n"
            + "</html>\n";

    //        ParseTreeBuilder.setLoggerLevel(Level.ALL);
    HtmlParseResult result = parse(code);
    Node root = result.root();

    assertNotNull(root);
    //        ElementUtils.dumpTree(root);

    OpenTag body = ElementUtils.query(result.root(), "html/body");
    assertNotNull(body);

    CloseTag bodyEnd = body.matchingCloseTag();
    assertNotNull(bodyEnd);

    assertEquals(6190, bodyEnd.from());
    assertEquals(6197, bodyEnd.to());
  }
  public void testLogicalRangesOfUnclosedOpenTags() throws ParseException {
    HtmlParseResult result =
        parse(
            "<!DOCTYPE html>"
                + "<html>"
                + "<head>"
                + "<title>hello</title>"
                + "</head>"
                + "<body>"
                + "<table>"
                + "</html>");
    Node root = result.root();

    //        NodeUtils.dumpTree(root);

    assertNotNull(root);
    OpenTag htmlOpen = ElementUtils.query(root, "html");
    assertNotNull(htmlOpen);
    CloseTag htmlEnd = htmlOpen.matchingCloseTag();
    assertNotNull(htmlEnd);

    assertNotNull(ElementUtils.query(root, "html/head"));
    assertNotNull(ElementUtils.query(root, "html/head/title"));
    OpenTag body = ElementUtils.query(root, "html/body");
    assertNotNull(body);
    OpenTag table = ElementUtils.query(root, "html/body/table");
    assertNotNull(table);

    // both body and table should be logically closed at the beginning of the html end tag
    assertEquals(htmlEnd.from(), body.semanticEnd());
    assertEquals(htmlEnd.from(), table.semanticEnd());
  }
  public void testSimpleDocument() throws ParseException {
    String code =
        "<!doctype html><html><head><title>x</title></head><body><div onclick=\"alert();\"/></body></html>";
    //             012345678901234567890123456789012345678901234567890123456789012345678 901234567
    // 8901234567890123456789
    //             0         1         2         3         4         5         6          7
    // 8         9

    //        NodeTreeBuilder.DEBUG_STATES = true;
    HtmlParseResult result = parse(code);
    Node root = result.root();
    assertNotNull(root);
    //        NodeUtils.dumpTree(result.root());

    OpenTag html = ElementUtils.query(root, "html");
    assertEquals("html", html.name());
    assertEquals(15, html.from());
    assertEquals(21, html.to());
    assertEquals(15, html.from());
    assertEquals(95, html.semanticEnd());

    OpenTag body = ElementUtils.query(root, "html/body");
    assertEquals("body", body.name());
    assertEquals(50, body.from());
    assertEquals(56, body.to());
    assertEquals(50, body.from());
    assertEquals(88, body.semanticEnd());

    CloseTag bodyEndTag = body.matchingCloseTag();
    assertNotNull(bodyEndTag);
    assertSame(body, bodyEndTag.matchingOpenTag());
    assertSame(bodyEndTag, body.matchingCloseTag());

    OpenTag title = ElementUtils.query(root, "html/head/title");
    assertEquals("title", title.name());
    assertEquals(27, title.from());
    assertEquals(34, title.to());
    assertEquals(27, title.from());
    assertEquals(43, title.semanticEnd());

    CloseTag titleEndTag = title.matchingCloseTag();
    assertNotNull(titleEndTag);
    assertSame(title, titleEndTag.matchingOpenTag());
    assertSame(titleEndTag, title.matchingCloseTag());
  }
  // Bug 213332 - IllegalStateException: A bug #212445 just happended for source text "
  // scrollbar-arrow-color:"black"; } </STYLE> <TITLE>Cyprus :: Larnaca</TITLE></HEAD> <BOD". Please
  // report a new bug or r
  // http://netbeans.org/bugzilla/show_bug.cgi?id=213332
  public void testIssue213332() throws ParseException {
    ParseTreeBuilder.setLoggerLevel(Level.ALL);

    String code = "<html><head><style type=text/css></style></head></html>";
    //             012345678901234567890123456789012345678901234567890123456789
    //             0         1         2         3         4         5
    Node root = parse(code).root();

    //        ElementUtils.dumpTree(root);

    OpenTag styleOpen = ElementUtils.query(root, "html/head/style");
    assertNotNull(styleOpen);

    CloseTag styleClose = styleOpen.matchingCloseTag();
    assertNotNull(styleClose);

    assertEquals(33, styleClose.from());
    assertEquals(41, styleClose.to());

    assertEquals(12, styleOpen.from());
    assertEquals(33, styleOpen.to());
  }