Exemplo n.º 1
0
  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());
  }
Exemplo n.º 2
0
  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());
  }
Exemplo n.º 3
0
  //    public void testProblemsReporting() throws ParseException {
  //        HtmlParseResult result = parse("<!DOCTYPE html></section>");
  //        //                              012345678901234567890123456789
  //        //                              0         1         2
  //        Collection<ProblemDescription> problems = result.getProblems();
  //
  //        assertEquals(1, problems.size());
  //        ProblemDescription p = problems.iterator().next();
  //
  //        assertEquals(ProblemDescription.ERROR, p.getType());
  //        assertEquals("nokey", p.getKey()); //XXX fix that
  //        assertEquals("Stray end tag “section”.", p.getText());
  //        assertEquals(15, p.getFrom());
  //        assertEquals(25, p.getTo());
  //
  //    }
  public void testStyle() throws ParseException {
    String code =
        "<!DOCTYPE html>\n<style type=\"text/css\">\n@import \"resources2/ezcompik/newcss2moje.css\";\n</style>\n";
    //             0123456789012345 67890123456 7890123456 789 012345678 90123456789012345678
    // 90123456789012 345678901 23456789
    //             0         1          2          3           4          5         6          7
    //      8           9

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

    OpenTag head = ElementUtils.query(root, "html/head");
    assertNotNull(head);
    assertEquals(2, head.children().size());

    Iterator<Element> itr = head.children().iterator();

    OpenTag styleOpenTag = (OpenTag) itr.next();
    assertNotNull(styleOpenTag);
    assertEquals(16, styleOpenTag.from());
    assertEquals(39, styleOpenTag.to());

    Element styleEndTag = itr.next();
    assertNotNull(styleEndTag);
    assertEquals(87, styleEndTag.from());
    assertEquals(95, styleEndTag.to());

    assertSame(styleEndTag, styleOpenTag.matchingCloseTag());
  }
Exemplo n.º 4
0
  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());
  }
Exemplo n.º 5
0
  // 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());
  }