[Htmlparser-cvs] htmlparser/src/org/htmlparser/tests EscapeCharacterRemovingNodeTest.java,NONE,1.1 D
Brought to you by:
derrickoswald
From: <jke...@us...> - 2003-06-25 03:46:40
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests In directory sc8-pr-cvs1:/tmp/cvs-serv26404/src/org/htmlparser/tests Modified Files: DecodingNodeTest.java ParserTestCase.java Added Files: EscapeCharacterRemovingNodeTest.java Log Message: added EscapeRemovingNode decorator, remove lots of private methods and field that were never used in numerous classes --- NEW FILE: EscapeCharacterRemovingNodeTest.java --- // HTMLParser Library v1_4_20030622 - 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 test class produced by Joshua Kerievsky package org.htmlparser.tests; import org.htmlparser.util.NodeIterator; import org.htmlparser.util.ParserException; public class EscapeCharacterRemovingNodeTest extends ParserTestCase { public EscapeCharacterRemovingNodeTest(String name) { super(name); } private String parseToObtainDecodedResult(String STRING_TO_DECODE) throws ParserException { StringBuffer decodedContent = new StringBuffer(); createParser(STRING_TO_DECODE); parser.setEscapeCharacterRemoval(true); NodeIterator nodes = parser.elements(); while (nodes.hasMoreNodes()) decodedContent.append(nodes.nextNode().toPlainTextString()); return decodedContent.toString(); } public void testTab() throws Exception { String ENCODED_WORKSHOP_TITLE = "The Testing & Refactoring Workshop\tCreated by Industrial Logic, Inc."; String DECODED_WORKSHOP_TITLE = "The Testing & Refactoring WorkshopCreated by Industrial Logic, Inc."; assertEquals( "tab in string", DECODED_WORKSHOP_TITLE, parseToObtainDecodedResult(ENCODED_WORKSHOP_TITLE)); } public void testCarriageReturn() throws Exception { String ENCODED_WORKSHOP_TITLE = "The Testing & Refactoring Workshop\nCreated by Industrial Logic, Inc.\n"; String DECODED_WORKSHOP_TITLE = "The Testing & Refactoring WorkshopCreated by Industrial Logic, Inc."; assertEquals( "tab in string", DECODED_WORKSHOP_TITLE, parseToObtainDecodedResult(ENCODED_WORKSHOP_TITLE)); } public void testWithDecodingNodeDecorator() throws Exception { String ENCODED_WORKSHOP_TITLE = "The Testing & Refactoring Workshop\nCreated by Industrial Logic, Inc.\n"; String DECODED_WORKSHOP_TITLE = "The Testing & Refactoring WorkshopCreated by Industrial Logic, Inc."; StringBuffer decodedContent = new StringBuffer(); createParser(ENCODED_WORKSHOP_TITLE); parser.setEscapeCharacterRemoval(true); parser.setNodeDecoding(true); NodeIterator nodes = parser.elements(); while (nodes.hasMoreNodes()) decodedContent.append(nodes.nextNode().toPlainTextString()); assertEquals( "tab in string", DECODED_WORKSHOP_TITLE, decodedContent.toString()); } } Index: DecodingNodeTest.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/DecodingNodeTest.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** DecodingNodeTest.java 22 Jun 2003 21:37:46 -0000 1.3 --- DecodingNodeTest.java 25 Jun 2003 03:46:37 -0000 1.4 *************** *** 26,29 **** --- 26,31 ---- // CA 94708, USA // Website : http://www.industriallogic.com + // + // This test class produced by Joshua Kerievsky package org.htmlparser.tests; Index: ParserTestCase.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/ParserTestCase.java,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** ParserTestCase.java 22 Jun 2003 21:37:46 -0000 1.16 --- ParserTestCase.java 25 Jun 2003 03:46:37 -0000 1.17 *************** *** 40,44 **** import org.htmlparser.Parser; import org.htmlparser.StringNode; - import org.htmlparser.tags.EndTag; import org.htmlparser.tags.FormTag; import org.htmlparser.tags.InputTag; --- 40,43 ---- *************** *** 305,365 **** } - - private void assertStringNodeEquals( - String displayMessage, - Node expectedNode, - Node actualNode) { - if (expectedNode instanceof StringNode) { - StringNode expectedString = - (StringNode)expectedNode; - StringNode actualString = - (StringNode)actualNode; - assertStringEquals( - displayMessage, - expectedString.getText(), - actualString.getText() - ); - } - } - - private void assertTagEquals( - String displayMessage, - Node expectedNode, - Node actualNode, - NodeIterator actualEnumeration) - throws ParserException { - - if (expectedNode instanceof Tag) { - Tag expectedTag = (Tag)expectedNode; - Tag actualTag = (Tag)actualNode; - if (isTagAnXmlEndTag(expectedTag)) { - if (!isTagAnXmlEndTag(actualTag)) { - assertAttributesMatch(displayMessage, expectedTag, actualTag); - Node tempNode = - actualEnumeration.nextNode(); - assertTrue( - "should be an end tag but was "+ - tempNode.getClass().getName(), - tempNode instanceof EndTag - ); - actualTag = (EndTag)tempNode; - String expectedTagName = ParserUtils.removeChars( - expectedTag.getTagName(),'/' - ); - assertEquals( - "expected end tag", - expectedTagName, - actualTag.getTagName() - ); - - } - } else - assertAttributesMatch(displayMessage, expectedTag, actualTag); - } - } - - private boolean isTagAnXmlEndTag(Tag expectedTag) { - return expectedTag.getText().lastIndexOf('/')==expectedTag.getText().length()-1; - } --- 304,307 ---- |