[Htmlparser-cvs] htmlparser/src/org/htmlparser/tests/parserHelperTests RemarkNodeParserTest.java,1.4
Brought to you by:
derrickoswald
From: Derrick O. <der...@us...> - 2006-05-27 14:02:41
|
Update of //cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/parserHelperTests In directory sc8-pr-cvs5.sourceforge.net:/tmp/cvs-serv27338/tests/parserHelperTests Modified Files: RemarkNodeParserTest.java Log Message: fix bug #1345049 HTMLParser should not terminate a comment with ---> add static STRICT_REMARKS to Lexer class, which when true follows the specification for remarks Index: RemarkNodeParserTest.java =================================================================== RCS file: //cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/parserHelperTests/RemarkNodeParserTest.java,v retrieving revision 1.48 retrieving revision 1.49 diff -C2 -d -r1.48 -r1.49 *** RemarkNodeParserTest.java 2 Sep 2004 02:28:16 -0000 1.48 --- RemarkNodeParserTest.java 27 May 2006 14:02:28 -0000 1.49 *************** *** 31,34 **** --- 31,35 ---- import org.htmlparser.Tag; import org.htmlparser.Text; + import org.htmlparser.lexer.Lexer; import org.htmlparser.tests.ParserTestCase; import org.htmlparser.util.ParserException; *************** *** 85,89 **** } ! public void testToPlainTextString() throws ParserException { createParser( "<!-- saved from url=(0022)http://internet.e-mail -->\n"+ --- 86,90 ---- } ! public void testGetText () throws ParserException { createParser( "<!-- saved from url=(0022)http://internet.e-mail -->\n"+ *************** *** 101,105 **** assertTrue("First node should be a Remark",node[0] instanceof Remark); Remark Remark = (Remark)node[0]; ! assertEquals("Plain Text of the Remark #1"," saved from url=(0022)http://internet.e-mail ",Remark.toPlainTextString()); // The tenth node should be a Remark assertTrue("Tenth node should be a Remark",node[9] instanceof Remark); --- 102,106 ---- assertTrue("First node should be a Remark",node[0] instanceof Remark); Remark Remark = (Remark)node[0]; ! assertEquals("Plain Text of the Remark #1"," saved from url=(0022)http://internet.e-mail ",Remark.getText ()); // The tenth node should be a Remark assertTrue("Tenth node should be a Remark",node[9] instanceof Remark); *************** *** 364,382 **** ParserException { ! createParser ( ! "<html>\n" ! + "<head>\n" ! + "<title>foobar</title>\n" ! + "</head>\n" ! + "<body>\n" ! + "<!-- foobar --!>\n" ! + "</body>\n" ! + "</html>\n" ! ); parser.setNodeFactory (new PrototypicalNodeFactory (true)); ! parseAndAssertNodeCount (18); ! assertTrue("Node should be a Remark but was " + node[12], node[12] instanceof Remark); ! assertStringEquals ("remark text", "<!-- foobar --!>", node[12].toHtml ()); } } --- 365,429 ---- ParserException { ! boolean old_remark_handling = Lexer.STRICT_REMARKS; ! try ! { ! // handling this requires non-strict handling ! Lexer.STRICT_REMARKS = false; ! createParser ( ! "<html>\n" ! + "<head>\n" ! + "<title>foobar</title>\n" ! + "</head>\n" ! + "<body>\n" ! + "<!-- foobar --!>\n" ! + "</body>\n" ! + "</html>\n" ! ); ! parser.setNodeFactory (new PrototypicalNodeFactory (true)); ! parseAndAssertNodeCount (18); ! assertTrue("Node should be a Remark but was " + node[12], node[12] instanceof Remark); ! assertStringEquals ("remark text", "<!-- foobar --!>", node[12].toHtml ()); ! } ! finally ! { ! Lexer.STRICT_REMARKS = old_remark_handling; ! } ! } ! ! /** ! * Test a comment ending with -. ! * See also the Acid2 test at http://www.webstandards.org/act/acid2/test.html. ! */ ! public void testDashEnding () ! throws ! ParserException ! { ! String preamble = "<div class=\"parser\">"; ! String remark = "<!-- ->ERROR<!- -->"; ! String rest = "</div></div> <!-- two dashes is what delimits a comment, so the text \"->ERROR<!-\" earlier on this line is actually part of a comment -->"; ! createParser (preamble + remark + rest); parser.setNodeFactory (new PrototypicalNodeFactory (true)); ! parseAndAssertNodeCount (6); ! assertTrue("Node should be a Remark but was " + node[1], node[1] instanceof Remark); ! assertStringEquals ("remark text", remark, node[1].toHtml ()); } + /** + * Test a comment ending with ---. + * See bug #1345049 HTMLParser should not terminate a comment with ---> + * See also the Acid2 test at http://www.webstandards.org/act/acid2/test.html. + */ + public void test3DashesEnding () + throws + ParserException + { + String preamble = "<div class=\"parser\">"; + String remark = "<!-- --->ERROR<!- -->"; + String rest = "</div></div> <!-- two dashes is what delimits a comment, so the text \"->ERROR<!-\" earlier on this line is actually part of a comment -->"; + createParser (preamble + remark + rest); + parser.setNodeFactory (new PrototypicalNodeFactory (true)); + parseAndAssertNodeCount (6); + assertTrue("Node should be a Remark but was " + node[1], node[1] instanceof Remark); + assertStringEquals ("remark text", remark, node[1].toHtml ()); + } } |