Example #1
0
  @Test
  public void testBrHasSpace() {
    Document doc = Jsoup.parse("<p>Hello<br>there</p>");
    assertEquals("Hello there", doc.text());
    assertEquals("Hello there", doc.select("p").first().ownText());

    doc = Jsoup.parse("<p>Hello <br> there</p>");
    assertEquals("Hello there", doc.text());
  }
Example #2
0
 @Test
 public void testKeepsPreTextInCode() {
   String h = "<pre><code>code\n\ncode</code></pre>";
   Document doc = Jsoup.parse(h);
   assertEquals("code\n\ncode", doc.text());
   assertEquals("<pre><code>code\n\ncode</code></pre>", doc.body().html());
 }
Example #3
0
 @Test
 public void testNormalisesText() {
   String h = "<p>Hello<p>There.</p> \n <p>Here <b>is</b> \n s<b>om</b>e text.";
   Document doc = Jsoup.parse(h);
   String text = doc.text();
   assertEquals("Hello There. Here is some text.", text);
 }
Example #4
0
  @Test
  public void testSetText() {
    String h = "<div id=1>Hello <p>there <b>now</b></p></div>";
    Document doc = Jsoup.parse(h);
    assertEquals("Hello there now", doc.text()); // need to sort out node whitespace
    assertEquals("there now", doc.select("p").get(0).text());

    Element div = doc.getElementById("1").text("Gone");
    assertEquals("Gone", div.text());
    assertEquals(0, doc.select("p").size());
  }
Example #5
0
 @Test
 public void testKeepsPreText() {
   String h = "<p>Hello \n \n there.</p> <div><pre>  What's \n\n  that?</pre>";
   Document doc = Jsoup.parse(h);
   assertEquals("Hello there.   What's \n\n  that?", doc.text());
 }
Example #6
0
 @Test
 public void testGetText() {
   Document doc = Jsoup.parse(reference);
   assertEquals("Hello Another element", doc.text());
   assertEquals("Another element", doc.getElementsByTag("p").get(1).text());
 }