📄 remarknodeparsertest.java
字号:
Tag tag = (Tag)node[0]; assertStringEquals("Expected contents","!\n"+ "-\n"+ "-\n"+ "ssd --",tag.getText()); } /** * Bug reported by John Zook [594301] * If dashes exist in a comment, they dont get added to the comment text */ public void testDashesInComment() throws ParserException{ createParser("<!-- -- -->"); parser.setNodeFactory (new PrototypicalNodeFactory (true)); parseAndAssertNodeCount(1); assertTrue("Node should be a Remark but was "+node[0],node[0] instanceof Remark); Remark Remark = (Remark)node[0]; assertEquals("Remark Node contents"," -- ",Remark.getText()); } // from http://www.w3.org/MarkUp/html-spec/html-spec_3.html//Comments////To include comments in an HTML document, use a comment declaration.//A comment declaration consists of `<!' followed by zero or more comments//followed by `>'. Each comment starts with `--' and includes all text up to//and including the next occurrence of `--'. In a comment declaration, white//space is allowed after each comment, but not before the first comment. The//entire comment declaration is ignored. (10)////For example:////<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">//<HEAD>//<TITLE>HTML Comment Example</TITLE>//<!-- Id: html-sgml.sgm,v 1.5 1995/05/26 21:29:50 connolly Exp -->//<!-- another -- -- comment -->//<!>//</HEAD>//<BODY>//<p> <!- not a comment, just regular old data characters -> /** * Test a comment declaration with a comment. */ public void testSingleComment () throws ParserException { createParser( "<HTML>\n" + "<HEAD>\n" + "<TITLE>HTML Comment Test</TITLE>\n" + "</HEAD>\n" + "<BODY>\n" + "<!-- Id: html-sgml.sgm,v 1.5 1995/05/26 21:29:50 connolly Exp -->\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); Remark Remark = (Remark)node[12]; assertEquals("Remark Node contents"," Id: html-sgml.sgm,v 1.5 1995/05/26 21:29:50 connolly Exp ",Remark.getText()); } /** * Test a comment declaration with two comments. */ public void testDoubleComment () throws ParserException { createParser( "<HTML>\n" + "<HEAD>\n" + "<TITLE>HTML Comment Test</TITLE>\n" + "</HEAD>\n" + "<BODY>\n" + "<!-- another -- -- comment -->\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); Remark Remark = (Remark)node[12]; assertEquals("Remark Node contents"," another -- -- comment ",Remark.getText()); } /** * Test a comment declaration without any comments. */ public void testEmptyComment () throws ParserException { createParser( "<HTML>\n" + "<HEAD>\n" + "<TITLE>HTML Comment Test 'testEmptyComment'</TITLE>\n" + "</HEAD>\n" + "<BODY>\n" + "<!>\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); Remark Remark = (Remark)node[12]; assertEquals("Remark Node contents","",Remark.getText()); }// /**// * Test what the specification calls data characters.// * Actually, no browser I've tried handles this correctly (as text).// * Some handle it as a comment and others handle it as a tag.// * So for now we leave this test case out.// */// public void testNotAComment ()// throws// HTMLParserException// {// createParser(// "<HTML>\n"// + "<HEAD>\n"// + "<TITLE>HTML Comment Test 'testNotAComment'</TITLE>\n"// + "</HEAD>\n"// + "<BODY>\n"// + "<!- not a comment, just regular old data characters ->\n"// + "</BODY>\n"// + "</HTML>\n"// );// parseAndAssertNodeCount(10);// assertTrue("Node should not be a Remark",!(node[7] instanceof Remark));// assertTrue("Node should be a HTMLText but was "+node[7],node[7].getType()==HTMLText.TYPE);// HTMLText stringNode = (HTMLText)node[7];// assertEquals("String Node contents","<!- not a comment, just regular old data characters ->\n",stringNode.getText());// } /** * Test exclamation mark ending. * Test a comment ending with !--. * See bug #788746 parser crashes on comments like <!-- foobar --!> */ public void testExclamationComment () throws 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 ()); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -