1 package org.jsoup.nodes; 2 3 import org.junit.jupiter.api.Test; 4 5 import java.io.IOException; 6 7 import static org.junit.jupiter.api.Assertions.assertEquals; 8 9 public class DataNodeTest { 10 11 @Test xmlOutputScriptWithCData()12 public void xmlOutputScriptWithCData() throws IOException { 13 DataNode node = new DataNode("//<![CDATA[\nscript && <> data]]>"); 14 node.parentNode = new Element("script"); 15 StringBuilder accum = new StringBuilder(); 16 node.outerHtmlHead(accum, 0, new Document.OutputSettings().syntax(Document.OutputSettings.Syntax.xml)); 17 assertEquals("//<![CDATA[\nscript && <> data]]>", accum.toString()); 18 } 19 20 @Test xmlOutputScriptWithoutCData()21 public void xmlOutputScriptWithoutCData() throws IOException { 22 DataNode node = new DataNode("script && <> data"); 23 node.parentNode = new Element("script"); 24 StringBuilder accum = new StringBuilder(); 25 node.outerHtmlHead(accum, 0, new Document.OutputSettings().syntax(Document.OutputSettings.Syntax.xml)); 26 assertEquals("//<![CDATA[\nscript && <> data\n//]]>", accum.toString()); 27 } 28 29 @Test xmlOutputStyleWithCData()30 public void xmlOutputStyleWithCData() throws IOException { 31 DataNode node = new DataNode("/*<![CDATA[*/\nstyle && <> data]]>"); 32 node.parentNode = new Element("style"); 33 StringBuilder accum = new StringBuilder(); 34 node.outerHtmlHead(accum, 0, new Document.OutputSettings().syntax(Document.OutputSettings.Syntax.xml)); 35 assertEquals("/*<![CDATA[*/\nstyle && <> data]]>", accum.toString()); 36 } 37 38 @Test xmlOutputStyleWithoutCData()39 public void xmlOutputStyleWithoutCData() throws IOException { 40 DataNode node = new DataNode("style && <> data"); 41 node.parentNode = new Element("style"); 42 StringBuilder accum = new StringBuilder(); 43 node.outerHtmlHead(accum, 0, new Document.OutputSettings().syntax(Document.OutputSettings.Syntax.xml)); 44 assertEquals("/*<![CDATA[*/\nstyle && <> data\n/*]]>*/", accum.toString()); 45 } 46 47 @Test xmlOutputOtherWithCData()48 public void xmlOutputOtherWithCData() throws IOException { 49 DataNode node = new DataNode("<![CDATA[other && <> data]]>"); 50 node.parentNode = new Element("other"); 51 StringBuilder accum = new StringBuilder(); 52 node.outerHtmlHead(accum, 0, new Document.OutputSettings().syntax(Document.OutputSettings.Syntax.xml)); 53 assertEquals("<![CDATA[other && <> data]]>", accum.toString()); 54 } 55 56 @Test xmlOutputOtherWithoutCData()57 public void xmlOutputOtherWithoutCData() throws IOException { 58 DataNode node = new DataNode("other && <> data"); 59 node.parentNode = new Element("other"); 60 StringBuilder accum = new StringBuilder(); 61 node.outerHtmlHead(accum, 0, new Document.OutputSettings().syntax(Document.OutputSettings.Syntax.xml)); 62 assertEquals("<![CDATA[other && <> data]]>", accum.toString()); 63 } 64 65 @Test xmlOutputOrphanWithoutCData()66 public void xmlOutputOrphanWithoutCData() throws IOException { 67 DataNode node = new DataNode("other && <> data"); 68 StringBuilder accum = new StringBuilder(); 69 node.outerHtmlHead(accum, 0, new Document.OutputSettings().syntax(Document.OutputSettings.Syntax.xml)); 70 assertEquals("<![CDATA[other && <> data]]>", accum.toString()); 71 } 72 73 } 74