[Htmlparser-cvs] htmlparser/src/org/htmlparser/tests/tagTests FrameSetTagTest.java,1.22,1.23 FrameTa
Brought to you by:
derrickoswald
From: <der...@us...> - 2003-08-02 16:23:01
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/tagTests In directory sc8-pr-cvs1:/tmp/cvs-serv9188/org/htmlparser/tests/tagTests Modified Files: FrameSetTagTest.java FrameTagTest.java InputTagTest.java TagTest.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: FrameSetTagTest.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/tagTests/FrameSetTagTest.java,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** FrameSetTagTest.java 27 Jul 2003 19:19:23 -0000 1.22 --- FrameSetTagTest.java 2 Aug 2003 16:22:58 -0000 1.23 *************** *** 56,60 **** assertStringEquals("HTML Contents", "<FRAMESET BORDER=\"0\" ROWS=\"115,*\" FRAMESPACING=\"0\" FRAMEBORDER=\"NO\">\r\n"+ ! "<FRAME SCROLLING=\"NO\" FRAMEBORDER=\"NO\" SRC=\"demo_bc_top.html\" NAME=\"topFrame\" NORESIZE=\"\">\r\n"+ "<FRAME SCROLLING=\"AUTO\" SRC=\"http://www.kizna.com/web_e/\" NAME=\"mainFrame\">\r\n"+ "</FRAMESET>", --- 56,60 ---- assertStringEquals("HTML Contents", "<FRAMESET BORDER=\"0\" ROWS=\"115,*\" FRAMESPACING=\"0\" FRAMEBORDER=\"NO\">\r\n"+ ! "<FRAME SCROLLING=\"NO\" FRAMEBORDER=\"NO\" SRC=\"demo_bc_top.html\" NAME=\"topFrame\" NORESIZE>\r\n"+ "<FRAME SCROLLING=\"AUTO\" SRC=\"http://www.kizna.com/web_e/\" NAME=\"mainFrame\">\r\n"+ "</FRAMESET>", Index: FrameTagTest.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/tagTests/FrameTagTest.java,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** FrameTagTest.java 27 Jul 2003 19:19:23 -0000 1.22 --- FrameTagTest.java 2 Aug 2003 16:22:58 -0000 1.23 *************** *** 55,59 **** FrameTag frameTag2 = (FrameTag)node[2]; ! assertStringEquals("Frame 1 toHTML()","<FRAME SCROLLING=\"NO\" FRAMEBORDER=\"NO\" SRC=\"demo_bc_top.html\" NAME=\"topFrame\" NORESIZE=\"\">",frameTag1.toHtml()); assertStringEquals("Frame 2 toHTML()","<FRAME SCROLLING=\"AUTO\" SRC=\"http://www.kizna.com/web_e/\" NAME=\"mainFrame\">",frameTag2.toHtml()); } --- 55,59 ---- FrameTag frameTag2 = (FrameTag)node[2]; ! assertStringEquals("Frame 1 toHTML()","<FRAME SCROLLING=\"NO\" FRAMEBORDER=\"NO\" SRC=\"demo_bc_top.html\" NAME=\"topFrame\" NORESIZE>",frameTag1.toHtml()); assertStringEquals("Frame 2 toHTML()","<FRAME SCROLLING=\"AUTO\" SRC=\"http://www.kizna.com/web_e/\" NAME=\"mainFrame\">",frameTag2.toHtml()); } Index: InputTagTest.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/tagTests/InputTagTest.java,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** InputTagTest.java 27 Jul 2003 19:19:23 -0000 1.23 --- InputTagTest.java 2 Aug 2003 16:22:58 -0000 1.24 *************** *** 87,91 **** InputTag = (InputTag) node[0]; assertStringEquals("HTML String", ! "<INPUT CHECKED=\"\" NAME=\"cbCheck\" TYPE=\"checkbox\">", InputTag.toHtml()); } --- 87,91 ---- InputTag = (InputTag) node[0]; assertStringEquals("HTML String", ! "<INPUT CHECKED NAME=\"cbCheck\" TYPE=\"checkbox\">", InputTag.toHtml()); } Index: TagTest.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/tagTests/TagTest.java,v retrieving revision 1.34 retrieving revision 1.35 diff -C2 -d -r1.34 -r1.35 *** TagTest.java 27 Jul 2003 19:19:23 -0000 1.34 --- TagTest.java 2 Aug 2003 16:22:58 -0000 1.35 *************** *** 165,169 **** assertEquals ("Link tag (A)","A",a); assertEquals ("href value","http://www.iki.fi/kaila",href); ! assertEquals ("myparameter value","",myValue); assertEquals ("yourparameter value","Kaarle Kaaila",nice); } --- 165,169 ---- assertEquals ("Link tag (A)","A",a); assertEquals ("href value","http://www.iki.fi/kaila",href); ! assertEquals ("myparameter value",null,myValue); assertEquals ("yourparameter value","Kaarle Kaaila",nice); } *************** *** 236,240 **** assertEquals ("The tagname should be G",a,"G"); assertEquals ("Check the http address",href,"http://www.iki.fi/kaila"); ! assertEquals ("myValue is empty",myValue,""); assertEquals ("The second parameter value",nice,"Kaila"); } --- 236,240 ---- assertEquals ("The tagname should be G",a,"G"); assertEquals ("Check the http address",href,"http://www.iki.fi/kaila"); ! assertEquals ("myValue is not null",myValue,null); assertEquals ("The second parameter value",nice,"Kaila"); } *************** *** 376,380 **** assertTrue("1st Node should be a Tag",node[0] instanceof Tag); Tag tag = (Tag)node[0]; ! assertStringEquals("toHTML()","<MYTAG EFGH=\"\" ABCD=\"\" MNOP=\"\" IJKL=\"\">",tag.toHtml()); assertTrue("2nd Node should be a Tag",node[1] instanceof Tag); assertTrue("5th Node should be a Tag",node[4] instanceof Tag); --- 376,380 ---- assertTrue("1st Node should be a Tag",node[0] instanceof Tag); Tag tag = (Tag)node[0]; ! assertStringEquals("toHTML()","<MYTAG EFGH ABCD MNOP IJKL>",tag.toHtml()); assertTrue("2nd Node should be a Tag",node[1] instanceof Tag); assertTrue("5th Node should be a Tag",node[4] instanceof Tag); *************** *** 405,409 **** result += node.toHtml(); } ! String expected = "<A YOURPARAMETER=\"Kaarle\" MYPARAMETER=\"\" HREF=\"http://www.iki.fi/kaila\">Kaarle's homepage</A><P>Paragraph</P>"; assertStringEquals("Check collected contents to original", expected, result); } catch (ClassCastException ce) { --- 405,409 ---- result += node.toHtml(); } ! String expected = "<A YOURPARAMETER=\"Kaarle\" MYPARAMETER HREF=\"http://www.iki.fi/kaila\">Kaarle's homepage</A><P>Paragraph</P>"; assertStringEquals("Check collected contents to original", expected, result); } catch (ClassCastException ce) { *************** *** 627,641 **** public void testSetText() throws ParserException { ! String testHTML = "<LABEL ID=\"JohnDoe\" >John Doe</LABEL>"; createParser(testHTML); parser.addScanner(new org.htmlparser.scanners.LabelScanner("-l")); parseAndAssertNodeCount(1); org.htmlparser.tags.LabelTag htmlTag = (org.htmlparser.tags.LabelTag)node[0]; ! String expectedHTML = "<LABEL ID=\"JohnDoe\" >John Doe</LABEL>"; assertStringEquals("Expected HTML",expectedHTML,htmlTag.toHtml()); assertStringEquals("Expected HTML","John Doe",htmlTag.getLabel()); ((org.htmlparser.StringNode)((org.htmlparser.tags.CompositeTag)htmlTag).getChild(0)).setText("Jane Doe"); ! expectedHTML = "<LABEL ID=\"JohnDoe\" >Jane Doe</LABEL>"; assertStringEquals("Expected HTML",expectedHTML,htmlTag.toHtml()); assertStringEquals("Expected HTML","Jane Doe",htmlTag.getLabel()); --- 627,641 ---- public void testSetText() throws ParserException { ! String testHTML = "<LABEL ID=\"JohnDoe\">John Doe</LABEL>"; createParser(testHTML); parser.addScanner(new org.htmlparser.scanners.LabelScanner("-l")); parseAndAssertNodeCount(1); org.htmlparser.tags.LabelTag htmlTag = (org.htmlparser.tags.LabelTag)node[0]; ! String expectedHTML = "<LABEL ID=\"JohnDoe\">John Doe</LABEL>"; assertStringEquals("Expected HTML",expectedHTML,htmlTag.toHtml()); assertStringEquals("Expected HTML","John Doe",htmlTag.getLabel()); ((org.htmlparser.StringNode)((org.htmlparser.tags.CompositeTag)htmlTag).getChild(0)).setText("Jane Doe"); ! expectedHTML = "<LABEL ID=\"JohnDoe\">Jane Doe</LABEL>"; assertStringEquals("Expected HTML",expectedHTML,htmlTag.toHtml()); assertStringEquals("Expected HTML","Jane Doe",htmlTag.getLabel()); *************** *** 695,699 **** String s = tag.toHtml (); ! assertEquals("HTML should be","<TABLE BORDER=\"1\" >", s); } } --- 695,699 ---- String s = tag.toHtml (); ! assertEquals("HTML should be","<TABLE BORDER=\"1\">", s); } } |