[Htmlparser-cvs] htmlparser/src/org/htmlparser/tests/scannersTests HeadScannerTest.java,NONE,1.1 All
Brought to you by:
derrickoswald
From: <der...@us...> - 2003-05-16 11:38:41
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/scannersTests In directory sc8-pr-cvs1:/tmp/cvs-serv2400/org/htmlparser/tests/scannersTests Modified Files: AllTests.java BodyScannerTest.java Added Files: HeadScannerTest.java Log Message: From Dhaval: Created the HEAD tag-scanner pair and corrected the BodyScanner. There were some mistakes after the redisgn that took place. --- NEW FILE: HeadScannerTest.java --- // HTMLParser Library v1_3_20030511 - A java-based parser for HTML // Copyright (C) Dec 31, 2000 Somik Raha // // 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 // // For any questions or suggestions, you can write to me at : // Email :so...@in... // // Postal Address : // Somik Raha // Extreme Programmer & Coach // Industrial Logic Corporation // 2583 Cedar Street, Berkeley, // CA 94708, USA // Website : http://www.industriallogic.com // // This class was contributed by Dhaval Udani // dha...@or... package org.htmlparser.tests.scannersTests; import java.util.*; import junit.framework.TestSuite; import org.htmlparser.*; import org.htmlparser.scanners.*; import org.htmlparser.tags.*; import org.htmlparser.tests.ParserTestCase; import org.htmlparser.util.ParserException; public class HeadScannerTest extends ParserTestCase { public HeadScannerTest(String name) { super(name); } public void testSimpleHead() throws ParserException { createParser("<HTML><HEAD></HEAD></HTML>"); HeadScanner headScanner = new HeadScanner(); parser.registerDomScanners(); parseAndAssertNodeCount(1); assertTrue(node[0] instanceof Html); Html htmlTag = (Html)node[0]; assertTrue(htmlTag.getChild(0) instanceof HeadTag); } public void testSimpleHeadWithoutEndTag() throws ParserException { createParser("<HTML><HEAD></HTML>"); HeadScanner headScanner = new HeadScanner(); parser.registerDomScanners(); parseAndAssertNodeCount(1); assertTrue(node[0] instanceof Html); Html htmlTag = (Html)node[0]; assertTrue(htmlTag.getChild(0) instanceof HeadTag); HeadTag headTag = (HeadTag)htmlTag.getChild(0); assertEquals("toHtml()","<HEAD></HEAD>",headTag.toHtml()); assertEquals("toHtml()","<HTML><HEAD></HEAD></HTML>",htmlTag.toHtml()); } public void testSimpleHeadWithBody() throws ParserException { createParser("<HTML><HEAD><BODY></HTML>"); HeadScanner headScanner = new HeadScanner(); parser.registerDomScanners(); parseAndAssertNodeCount(1); assertTrue(node[0] instanceof Html); Html htmlTag = (Html)node[0]; assertTrue(htmlTag.getChild(0) instanceof HeadTag); //assertTrue(htmlTag.getChild(1) instanceof BodyTag); HeadTag headTag = (HeadTag)htmlTag.getChild(0); assertEquals("toHtml()","<HEAD></HEAD>",headTag.toHtml()); assertEquals("toHtml()","<HTML><HEAD></HEAD><BODY></BODY></HTML>",htmlTag.toHtml()); } public static TestSuite suite() { return new TestSuite(HeadScannerTest.class); } public static void main(String[] args) { new junit.awtui.TestRunner().start(new String[] {HeadScannerTest.class.getName()}); } } Index: AllTests.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/scannersTests/AllTests.java,v retrieving revision 1.33 retrieving revision 1.34 diff -C2 -d -r1.33 -r1.34 *** AllTests.java 12 May 2003 01:37:48 -0000 1.33 --- AllTests.java 16 May 2003 11:38:38 -0000 1.34 *************** *** 83,86 **** --- 83,87 ---- suite.addTestSuite(BodyScannerTest.class); suite.addTestSuite(CompositeTagScannerTest.class); + suite.addTestSuite(HeadScannerTest.class); return suite; } Index: BodyScannerTest.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/scannersTests/BodyScannerTest.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** BodyScannerTest.java 13 Apr 2003 06:28:05 -0000 1.5 --- BodyScannerTest.java 16 May 2003 11:38:38 -0000 1.6 *************** *** 82,85 **** --- 82,98 ---- assertEquals("Body Scanner",bodyScanner,bodyTag.getThisScanner()); } + + public void testBodyEnding() throws ParserException { + createParser("<html><body>before jsp<%=BodyValue%>after jsp</html>"); + parser.registerScanners(); + BodyScanner bodyScanner = new BodyScanner("-b"); + parser.addScanner(bodyScanner); + parseAndAssertNodeCount(3); + assertTrue(node[1] instanceof BodyTag); + // check the body node + BodyTag bodyTag = (BodyTag) node[1]; + assertEquals("Body","<BODY>before jsp<%=BodyValue%>after jsp</BODY>",bodyTag.toHtml()); + assertEquals("Body Scanner",bodyScanner,bodyTag.getThisScanner()); + } public static TestSuite suite() |