[Htmlparser-cvs] htmlparser/src/org/htmlparser/tests/temporaryFailures AttributeParserTest.java,1.5,
Brought to you by:
derrickoswald
From: <der...@us...> - 2003-08-02 16:23:01
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/temporaryFailures In directory sc8-pr-cvs1:/tmp/cvs-serv9188/org/htmlparser/tests/temporaryFailures Modified Files: AttributeParserTest.java TagParserTest.java Log Message: Fixed bug #757337 Standalone attributes should remain standalone Changing to a HashMap was not adopted for two reasons. The first is that it would break Java 1.1.x compatibility (which I believe we still maintain, although I haven't checked lately), and using a HashMap would return the attributes in a different order, leading to a *lot* of broken tests that rely on toHTML() returning a specific string with attributes in a certain order (if I'm going to fix a bunch of tests I would like the attributes to come out in the order they were originally, so this will need an AttributeStorage class when the attribute parser is rewritten). The solution adopted is to subclass HashTable and store two special values, which are new constants in the Tag class. For naive programs, and for backward compatibility, this SpecialHashtable class translates these constants into null and "" respectively, so the old behavior is the same. However, savvy programs, and the toHTML() method in the Tag class can call getRaw() on this hashtable to get at these special constants and behave appropriately. For this specific bug, toHTML returns the stand-alone attribute as is, but the missing value case is also handled. Index: AttributeParserTest.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/temporaryFailures/AttributeParserTest.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** AttributeParserTest.java 27 Jul 2003 19:19:23 -0000 1.5 --- AttributeParserTest.java 2 Aug 2003 16:22:58 -0000 1.6 *************** *** 79,83 **** public void testParseMissingEqual() { getParameterTableFor("a b\"c\""); ! assertEquals("ValueB","",table.get("B")); } --- 79,83 ---- public void testParseMissingEqual() { getParameterTableFor("a b\"c\""); ! assertEquals("ValueB",null,table.get("B")); } *************** *** 101,105 **** assertEquals("Name","Authorize",table.get("NAME")); assertEquals("Value","Y",table.get("VALUE")); ! assertEquals("Checked","",table.get("CHECKED")); } --- 101,105 ---- assertEquals("Name","Authorize",table.get("NAME")); assertEquals("Value","Y",table.get("VALUE")); ! assertEquals("Checked",null,table.get("CHECKED")); } *************** *** 209,212 **** --- 209,234 ---- assertStringEquals ("parameter parsed incorrectly", "defaultStatus=''", value); } + } + + /** + * Test that stand-alone attributes are kept that way, rather than being + * given empty values. + * -Joe Robins, 6/19/03 + */ + public void testStandaloneAttribute () + { + getParameterTableFor ("INPUT DISABLED"); + assertTrue ("Standalone attribue has no entry in table keyset",table.containsKey("DISABLED")); + assertNull ("Standalone attribute has non-null value",(String)table.get("DISABLED")); + } + + /** + * Test missing value. + */ + public void testMissingAttribute () + { + getParameterTableFor ("INPUT DISABLED="); + assertTrue ("Attribue has no entry in table keyset",table.containsKey("DISABLED")); + assertEquals ("Attribute has non-blank value","",(String)table.get("DISABLED")); } } Index: TagParserTest.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/temporaryFailures/TagParserTest.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** TagParserTest.java 27 Jul 2003 19:19:23 -0000 1.5 --- TagParserTest.java 2 Aug 2003 16:22:58 -0000 1.6 *************** *** 410,413 **** return result; } ! } } --- 410,440 ---- return result; } ! } ! ! /** ! * Test the toHTML method for a standalone attribute. ! */ ! public void testStandAloneToHTML () throws ParserException ! { ! createParser("<input disabled>"); ! parseAndAssertNodeCount (1); ! assertType ("should be Tag", Tag.class, node[0]); ! Tag tag = (Tag)node[0]; ! String html = tag.toHtml (); ! assertStringEquals ("html","<INPUT DISABLED>", html); ! } ! ! /** ! * Test the toHTML method for a missing value attribute. ! */ ! public void testMissingValueToHTML () throws ParserException ! { ! createParser("<input disabled=>"); ! parseAndAssertNodeCount (1); ! assertType ("should be Tag", Tag.class, node[0]); ! Tag tag = (Tag)node[0]; ! String html = tag.toHtml (); ! assertStringEquals ("html","<INPUT DISABLED=>", html); ! } ! } |