[Htmlparser-cvs] htmlparser/src/org/htmlparser/tests ParserTest.java,1.56,1.57
Brought to you by:
derrickoswald
From: <der...@us...> - 2004-02-29 13:10:26
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25994/tests Modified Files: ParserTest.java Log Message: Fix bug #900128 RemarkNode.setText() does not set Text Add override setText() to StringNode and RemarkNode. Add unit tests to excercise the new code. Remove remaining XX_FILTER constants. Index: ParserTest.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/ParserTest.java,v retrieving revision 1.56 retrieving revision 1.57 diff -C2 -d -r1.56 -r1.57 *** ParserTest.java 25 Jan 2004 21:33:12 -0000 1.56 --- ParserTest.java 29 Feb 2004 12:52:21 -0000 1.57 *************** *** 42,45 **** --- 42,46 ---- import org.htmlparser.Parser; import org.htmlparser.PrototypicalNodeFactory; + import org.htmlparser.RemarkNode; import org.htmlparser.StringNode; import org.htmlparser.filters.NodeClassFilter; *************** *** 884,886 **** --- 885,958 ---- } } + + /** + * See bug #900128 RemarkNode.setText() does not set Text + */ + public void testSetStringText () throws Exception + { + String text; + String html; + String newtext; + String newhtml; + Node txt; + + text = "This is just text."; + html = "<body>" + text + "</body>"; + newtext = "This is different text."; + newhtml = "<body>" + newtext + "</body>"; + createParser (html); + parseAndAssertNodeCount (1); + assertStringEquals ("html wrong", html, node[0].toHtml ()); + assertTrue ("wrong number of children", 1 == node[0].getChildren ().size ()); + assertTrue ("string node expected", node[0].getChildren ().elementAt (0) instanceof StringNode); + txt = node[0].getChildren ().elementAt (0); + assertStringEquals ("string html wrong", text, txt.toHtml ()); + assertStringEquals ("string contents wrong", text, txt.getText ()); + assertTrue ("toString wrong", txt.toString ().endsWith (text)); + txt.setText (newtext); + assertStringEquals ("html wrong", newhtml, node[0].toHtml ()); + assertStringEquals ("new string html wrong", newtext, txt.toHtml ()); + assertStringEquals ("new string contents wrong", newtext, txt.getText ()); + assertTrue ("toString wrong", txt.toString ().endsWith (newtext)); + } + + /** + * See bug #900128 RemarkNode.setText() does not set Text + */ + public void testSetRemarkText () throws Exception + { + String text; + String remark; + String html; + String newtext; + String newremark; + String newhtml; + Node rem; + + text = " This is a remark. "; + remark = "<!--" + text + "-->"; + html = "<body>" + remark + "</body>"; + newtext = " This is a different remark. "; + newremark = "<!--" + newtext + "-->"; + newhtml = "<body>" + newremark + "</body>"; + createParser (html); + parseAndAssertNodeCount (1); + assertStringEquals ("html wrong", html, node[0].toHtml ()); + assertTrue ("wrong number of children", 1 == node[0].getChildren ().size ()); + assertTrue ("remark node expected", node[0].getChildren ().elementAt (0) instanceof RemarkNode); + rem = node[0].getChildren ().elementAt (0); + assertStringEquals ("remark html wrong", remark, rem.toHtml ()); + assertStringEquals ("remark contents wrong", text, rem.getText ()); + assertTrue ("toString wrong", rem.toString ().endsWith (text)); + rem.setText (newtext); + assertStringEquals ("html wrong", newhtml, node[0].toHtml ()); + assertStringEquals ("new remark html wrong", newremark, rem.toHtml ()); + assertStringEquals ("new remark contents wrong", newtext, rem.getText ()); + assertTrue ("toString wrong", rem.toString ().endsWith (newtext)); + rem.setText (newremark); + assertStringEquals ("html wrong", newhtml, node[0].toHtml ()); + assertStringEquals ("new remark html wrong", newremark, rem.toHtml ()); + assertStringEquals ("new remark contents wrong", newtext, rem.getText ()); + assertTrue ("toString wrong", rem.toString ().endsWith (newtext)); + } } |