示例#1
0
  @Test
  public void testTitles() {
    Document noTitle = Jsoup.parse("<p>Hello</p>");
    Document withTitle = Jsoup.parse("<title>First</title><title>Ignore</title><p>Hello</p>");

    assertEquals("", noTitle.title());
    noTitle.title("Hello");
    assertEquals("Hello", noTitle.title());
    assertEquals("Hello", noTitle.select("title").first().text());

    assertEquals("First", withTitle.title());
    withTitle.title("Hello");
    assertEquals("Hello", withTitle.title());
    assertEquals("Hello", withTitle.select("title").first().text());

    Document normaliseTitle = Jsoup.parse("<title>   Hello\nthere   \n   now   \n");
    assertEquals("Hello there now", normaliseTitle.title());
  }
示例#2
0
  @Test
  public void testClone() {
    Document doc = Jsoup.parse("<title>Hello</title> <p>One<p>Two");
    Document clone = doc.clone();

    assertEquals(
        "<html><head><title>Hello</title> </head><body><p>One</p><p>Two</p></body></html>",
        TextUtil.stripNewlines(clone.html()));
    clone.title("Hello there");
    clone.select("p").first().text("One more").attr("id", "1");
    assertEquals(
        "<html><head><title>Hello there</title> </head><body><p id=\"1\">One more</p><p>Two</p></body></html>",
        TextUtil.stripNewlines(clone.html()));
    assertEquals(
        "<html><head><title>Hello</title> </head><body><p>One</p><p>Two</p></body></html>",
        TextUtil.stripNewlines(doc.html()));
  }
示例#3
-1
 @Test
 public void setTextPreservesDocumentStructure() {
   Document doc = Jsoup.parse("<p>Hello</p>");
   doc.text("Replaced");
   assertEquals("Replaced", doc.text());
   assertEquals("Replaced", doc.body().text());
   assertEquals(1, doc.select("head").size());
 }