Thread: [Htmlparser-cvs] htmlparser/src/org/htmlparser/tests/visitorsTests ScriptCommentTest.java,NONE,1.1 A
Brought to you by:
derrickoswald
From: Derrick O. <der...@us...> - 2004-05-22 03:57:40
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/visitorsTests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25265/tests/visitorsTests Modified Files: AllTests.java Added Files: ScriptCommentTest.java Log Message: Fix bug# 919738 Text has not been extracted correctly using StringBean and (duplicate) bug #936392 ScriptTag visitor fails for comments with ' by handling single and multiline ecmascript comments in the Lexer class when called with quotesmart true. Also added test cases for, but didn't fix bug #923146 tag nesting rule too strict for forms (org.htmlparser.tests.tagTests.InputTagTest.testTable) and bug #922439 OutOfMemory on huge HTML files (4,7MB) (org.htmlparser.tests.MemoryTest) which are thus currently failing. --- NEW FILE: ScriptCommentTest.java --- // HTMLParser Library $Name: $ - A java-based parser for HTML // http://sourceforge.org/projects/htmlparser // Copyright (C) 2004 Jim Arnell // // Revision Control Information // // $Source: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/visitorsTests/ScriptCommentTest.java,v $ // $Author: derrickoswald $ // $Date: 2004/05/22 03:57:31 $ // $Revision: 1.1 $ // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // package org.htmlparser.tests.visitorsTests; import org.htmlparser.tags.CompositeTag; import org.htmlparser.tags.ScriptTag; import org.htmlparser.tags.Tag; import org.htmlparser.tests.ParserTestCase; import org.htmlparser.visitors.NodeVisitor; public class ScriptCommentTest extends ParserTestCase { static { System.setProperty ("org.htmlparser.tests.visitorsTests.ScriptCommentTest", "ScriptCommentTest"); } private String workingScriptTag = "<script language='javascript'>" + "// I cant handle single quotations\n" + "</script>"; private String workingHtml = this.workingScriptTag + "<HTML>" + "</HTML>"; private String failingScriptTag = "<script language='javascript'>" + "// I can't handle single quotations.\n" + "</script>"; private String failingHtml = this.failingScriptTag + "<HTML>" + "</HTML>"; private String failingHtml2 = "<HTML>" + this.failingScriptTag + "</HTML>"; private String anotherFailingScriptTag = "<script language='javascript'>" + "/* I can't handle single quotations. */" + "</script>"; private String failingHtml3 = this.anotherFailingScriptTag + "<HTML>" + "</HTML>"; public ScriptCommentTest(String name) { super(name); } public void testTagWorking() throws Exception { createParser(this.workingHtml); ScriptVisitor visitor = new ScriptVisitor(); this.parser.visitAllNodesWith(visitor); String scriptNodeHtml = visitor.scriptTag.toHtml(); assertEquals("Script parsing worked", this.workingScriptTag, scriptNodeHtml); } public void testScriptTagNotWorkingOuter() throws Exception { createParser(this.failingHtml); ScriptVisitor visitor = new ScriptVisitor(); this.parser.visitAllNodesWith(visitor); String scriptNodeHtml = visitor.scriptTag.toHtml(); assertEquals("Script parsing not working", this.failingScriptTag, scriptNodeHtml); } public void testScriptTagNotWorkingInner() throws Exception { createParser(this.failingHtml2); ScriptVisitor visitor = new ScriptVisitor(); this.parser.visitAllNodesWith(visitor); String scriptNodeHtml = visitor.scriptTag.toHtml(); assertEquals("Script parsing not working", this.failingScriptTag, scriptNodeHtml); } public void testScriptTagNotWorkingMultiLine() throws Exception { createParser(this.anotherFailingScriptTag); ScriptVisitor visitor = new ScriptVisitor(); this.parser.visitAllNodesWith(visitor); String scriptNodeHtml = visitor.scriptTag.toHtml(); assertEquals("Script parsing not working", this.anotherFailingScriptTag, scriptNodeHtml); } /** * Implement test case NodeVisitor. */ public final class ScriptVisitor extends NodeVisitor { /** Keps the only script tag. */ public ScriptTag scriptTag; /** * Creates a new ScriptVisitor object. * * @param hat param. * @param hostString param. * @param direction param. */ public ScriptVisitor() { super(true, true); } /** * @see org.htmlparser.visitors.NodeVisitor */ public void visitTag(final Tag n) { if ((null != n.getParent()) || ((n instanceof CompositeTag) && (null == ((CompositeTag) n).getEndTag()))) { if (n instanceof ScriptTag) { this.scriptTag = (ScriptTag) n; } } else { if (n instanceof ScriptTag) { this.scriptTag = (ScriptTag) n; } } } } } Index: AllTests.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/visitorsTests/AllTests.java,v retrieving revision 1.41 retrieving revision 1.42 diff -C2 -d -r1.41 -r1.42 *** AllTests.java 2 Jan 2004 16:24:57 -0000 1.41 --- AllTests.java 22 May 2004 03:57:31 -0000 1.42 *************** *** 52,55 **** --- 52,56 ---- suite.addTestSuite(TextExtractingVisitorTest.class); suite.addTestSuite(UrlModifyingVisitorTest.class); + suite.addTestSuite(ScriptCommentTest.class); return suite; |