Exemplo n.º 1
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.º 2
0
  public void testParseUnfinishedCode() throws ParseException {
    String code =
        "<!DOCTYPE HTML>"
            + "<html>"
            + "<head>"
            + "<title>"
            + "</title>"
            + "</head>"
            + "<body>"
            + "</table>"
            + "</html>";

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

    assertNotNull(root);

    //        NodeUtils.dumpTree(root);

    Node html = ElementUtils.query(root, "html");
    assertNotNull(html);

    Collection<Element> children = html.children();
    assertEquals(4, children.size()); // <head>, </head>,<body>,</table>
    Iterator<Element> childernItr = children.iterator();

    assertTrue(childernItr.hasNext());
    Element child = childernItr.next();
    assertEquals(ElementType.OPEN_TAG, child.type());
    assertEquals("head", ((OpenTag) child).name().toString());
    assertTrue(childernItr.hasNext());
    child = childernItr.next();
    assertEquals(ElementType.CLOSE_TAG, child.type());
    assertEquals("head", ((CloseTag) child).name().toString());
    assertTrue(childernItr.hasNext());
    child = childernItr.next();
    assertEquals(ElementType.OPEN_TAG, child.type());
    assertEquals("body", ((OpenTag) child).name().toString());
    assertTrue(childernItr.hasNext());
    child = childernItr.next();
    assertEquals(ElementType.CLOSE_TAG, child.type());
    assertEquals("table", ((CloseTag) child).name().toString());

    //        NodeUtils.dumpTree(root);

  }