[Htmlparser-cvs] htmlparser/src/org/htmlparser/tests DecodingNodeTest.java,NONE,1.1 AllTests.java,1.
Brought to you by:
derrickoswald
From: <jke...@us...> - 2003-06-17 03:26:23
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests In directory sc8-pr-cvs1:/tmp/cvs-serv18761/src/org/htmlparser/tests Modified Files: AllTests.java Added Files: DecodingNodeTest.java Log Message: add setting for parser to perform the Translate.decode() on all StringNodes. This will later be refactored to a Decorator implementation. --- NEW FILE: DecodingNodeTest.java --- package org.htmlparser.tests; import org.htmlparser.util.NodeIterator; import org.htmlparser.util.ParserException; public class DecodingNodeTest extends ParserTestCase { public DecodingNodeTest(String name) { super(name); } private String parseToObtainDecodedResult(String STRING_TO_DECODE) throws ParserException { StringBuffer decodedContent = new StringBuffer(); createParser(STRING_TO_DECODE); parser.setNodeDecoding(true); // tell parser to decode StringNodes NodeIterator nodes = parser.elements(); while (nodes.hasMoreNodes()) decodedContent.append(nodes.nextNode().toHtml()); return decodedContent.toString(); } public void testAmpersand() throws Exception { String ENCODED_WORKSHOP_TITLE = "<H1>The Testing & Refactoring Workshop</H1>"; String DECODED_WORKSHOP_TITLE = "<H1>The Testing & Refactoring Workshop</H1>"; assertEquals( "ampersand in string", DECODED_WORKSHOP_TITLE, parseToObtainDecodedResult(ENCODED_WORKSHOP_TITLE)); } public void testNumericReference() throws Exception { String ENCODED_DIVISION_SIGN = "÷ is the division sign."; String DECODED_DIVISION_SIGN = "÷ is the division sign."; assertEquals( "numeric reference for division sign", DECODED_DIVISION_SIGN, parseToObtainDecodedResult(ENCODED_DIVISION_SIGN)); } public void testReferencesInString () throws Exception { String ENCODED_REFERENCE_IN_STRING = "Thus, the character entity reference ÷ is a more convenient" + " form than ÷ for obtaining the division sign (÷)"; String DECODED_REFERENCE_IN_STRING = "Thus, the character entity reference ÷ is a more convenient" + " form than ÷ for obtaining the division sign (÷)"; assertEquals ( "character references within a string", DECODED_REFERENCE_IN_STRING, parseToObtainDecodedResult(ENCODED_REFERENCE_IN_STRING)); } public void testBogusCharacterEntityReference() throws Exception { String ENCODED_BOGUS_CHARACTER_ENTITY = "The character entity reference &divode; is bogus"; String DECODED_BOGUS_CHARACTER_ENTITY = "The character entity reference &divode; is bogus"; assertEquals ( "bogus character entity reference", DECODED_BOGUS_CHARACTER_ENTITY, parseToObtainDecodedResult(ENCODED_BOGUS_CHARACTER_ENTITY)); } } Index: AllTests.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/AllTests.java,v retrieving revision 1.39 retrieving revision 1.40 diff -C2 -d -r1.39 -r1.40 *** AllTests.java 1 Jun 2003 20:50:14 -0000 1.39 --- AllTests.java 17 Jun 2003 03:26:20 -0000 1.40 *************** *** 104,107 **** --- 104,108 ---- TestSuite basic = new TestSuite("Basic Tests"); basic.addTestSuite(ParserTest.class); + basic.addTestSuite(DecodingNodeTest.class); suite.addTest(basic); suite.addTest(org.htmlparser.tests.scannersTests.AllTests.suite()); |