Ejemplo n.º 1
0
  // Bug 210976 - StringIndexOutOfBoundsException: String index out of range: 399
  public void testIssue210976() throws ParseException {
    String code = "<a href=\"@&msc=@@@&klub=@@@\"></a>";
    //             01234567 8901234567890123456 7890123
    //             0          1         2          3

    HtmlParseResult result = parse(code);
    Node root = result.root();
    assertNotNull(root);

    //        ElementUtils.dumpTree(root);

    OpenTag a = ElementUtils.query(root, "html/body/a");
    assertNotNull(a);
    assertEquals(0, a.from());
    assertEquals(29, a.to());

    Attribute attr = a.getAttribute("href");
    assertNotNull(attr);

    assertNotNull(attr.value());
    assertNotNull(attr.unquotedValue());

    assertEquals("\"@&msc=@@@&klub=@@@\"", attr.value());
    assertEquals("@&msc=@@@&klub=@@@", attr.unquotedValue());
  }
Ejemplo n.º 2
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());
  }
Ejemplo n.º 3
0
  public void testSelfCloseTagEndOffset() throws ParseException {
    //        ParseTreeBuilder.setLoggerLevel(Level.ALL);

    String code = "<div/>text";
    //             0123456
    HtmlParseResult result = parse(code);
    Node root = result.root();

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

    assertEquals(0, div.from());
    assertEquals(6, div.to());
  }
Ejemplo n.º 4
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());
  }
Ejemplo n.º 5
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());
  }