Thread: [Htmlparser-cvs] htmlparser/src/org/htmlparser/tests/lexerTests AttributeTests.java,1.16,1.17 TagTes
Brought to you by:
derrickoswald
From: Derrick O. <der...@us...> - 2004-07-02 00:49:40
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/lexerTests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32670/src/org/htmlparser/tests/lexerTests Modified Files: AttributeTests.java TagTests.java Log Message: Part four of a multiphase refactoring. Most internals now use the Tag interface. This interface has been broadened to add set/get scanner and set/get endtag. Removed the org.htmlparser.tags.Tag class and moved the remaining (minor) functionality to the TagNode class. So now tags inherit directly from TagNode or CompositeTag. ** NOTE: If you have subclassed org.htmlparser.tags.Tag, use org.htmlparser.nodes.TagNode now.** Removed deprecated methods getTagBegin/getTagEnd and deleted unused classes: PeekingIterator and it's Implementation. Index: AttributeTests.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/lexerTests/AttributeTests.java,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** AttributeTests.java 26 Jun 2004 11:56:08 -0000 1.16 --- AttributeTests.java 2 Jul 2004 00:49:30 -0000 1.17 *************** *** 33,40 **** import org.htmlparser.Attribute; import org.htmlparser.PrototypicalNodeFactory; import org.htmlparser.lexer.PageAttribute; import org.htmlparser.tags.ImageTag; import org.htmlparser.tags.LinkTag; - import org.htmlparser.tags.Tag; import org.htmlparser.tests.ParserTestCase; import org.htmlparser.util.NodeIterator; --- 33,41 ---- import org.htmlparser.Attribute; import org.htmlparser.PrototypicalNodeFactory; + import org.htmlparser.Tag; import org.htmlparser.lexer.PageAttribute; + import org.htmlparser.nodes.TagNode; import org.htmlparser.tags.ImageTag; import org.htmlparser.tags.LinkTag; import org.htmlparser.tests.ParserTestCase; import org.htmlparser.util.NodeIterator; *************** *** 51,55 **** private static final boolean JSP_TESTS_ENABLED = false; private Tag tag; ! private Hashtable table; public AttributeTests (String name) { --- 52,56 ---- private static final boolean JSP_TESTS_ENABLED = false; private Tag tag; ! private Vector attributes; public AttributeTests (String name) { *************** *** 67,71 **** NodeIterator iterator; Node node; - Vector attributes; html = "<" + tagContents + ">"; --- 68,71 ---- *************** *** 98,105 **** System.out.println (); } - table = tag.getAttributes (); } else ! table = null; String string = node.toHtml (); assertEquals ("toHtml differs", html, string); --- 98,104 ---- System.out.println (); } } else ! attributes = null; String string = node.toHtml (); assertEquals ("toHtml differs", html, string); *************** *** 134,138 **** // String String, String, char attributes.add (new Attribute ("name", "=", "topFrame", '"')); ! tag = new Tag (null, 0, 0, attributes); html = "<wombat label=\"The civil war.\" frameborder= no name=\"topFrame\">"; assertStringEquals ("tag contents", html, tag.toHtml ()); --- 133,137 ---- // String String, String, char attributes.add (new Attribute ("name", "=", "topFrame", '"')); ! tag = new TagNode (null, 0, 0, attributes); html = "<wombat label=\"The civil war.\" frameborder= no name=\"topFrame\">"; assertStringEquals ("tag contents", html, tag.toHtml ()); *************** *** 191,195 **** assertTrue ("should not be empty", !attribute.isEmpty ()); attributes.add (attribute); ! tag = new Tag (null, 0, 0, attributes); html = "<wombat label=\"The civil war.\" frameborder= no name=\"topFrame\">"; assertStringEquals ("tag contents", html, tag.toHtml ()); --- 190,194 ---- assertTrue ("should not be empty", !attribute.isEmpty ()); attributes.add (attribute); ! tag = new TagNode (null, 0, 0, attributes); html = "<wombat label=\"The civil war.\" frameborder= no name=\"topFrame\">"; assertStringEquals ("tag contents", html, tag.toHtml ()); *************** *** 218,222 **** // String String, String, char attributes.add (new PageAttribute ("name", "=", "topFrame", '"')); ! tag = new Tag (null, 0, 0, attributes); html = "<wombat label=\"The civil war.\" frameborder= no name=\"topFrame\">"; assertStringEquals ("tag contents", html, tag.toHtml ()); --- 217,221 ---- // String String, String, char attributes.add (new PageAttribute ("name", "=", "topFrame", '"')); ! tag = new TagNode (null, 0, 0, attributes); html = "<wombat label=\"The civil war.\" frameborder= no name=\"topFrame\">"; assertStringEquals ("tag contents", html, tag.toHtml ()); *************** *** 279,283 **** assertTrue ("should not be empty", !attribute.isEmpty ()); attributes.add (attribute); ! tag = new Tag (null, 0, 0, attributes); html = "<wombat label=\"The civil war.\" frameborder= no name=\"topFrame\">"; assertStringEquals ("tag contents", html, tag.toHtml ()); --- 278,282 ---- assertTrue ("should not be empty", !attribute.isEmpty ()); attributes.add (attribute); ! tag = new TagNode (null, 0, 0, attributes); html = "<wombat label=\"The civil war.\" frameborder= no name=\"topFrame\">"; assertStringEquals ("tag contents", html, tag.toHtml ()); *************** *** 289,293 **** public void testParseParameters() { getParameterTableFor("a b = \"c\""); ! assertEquals("Value","c",table.get("B")); } --- 288,292 ---- public void testParseParameters() { getParameterTableFor("a b = \"c\""); ! assertEquals("Value","c",((Attribute)(attributes.elementAt (2))).getValue ()); } *************** *** 297,301 **** public void testParseTokenValues() { getParameterTableFor("a b = \"'\""); ! assertEquals("Value","'",table.get("B")); } --- 296,300 ---- public void testParseTokenValues() { getParameterTableFor("a b = \"'\""); ! assertEquals("Value","'",((Attribute)(attributes.elementAt (2))).getValue ()); } *************** *** 305,309 **** public void testParseEmptyValues() { getParameterTableFor("a b = \"\""); ! assertEquals("Value","",table.get("B")); } --- 304,308 ---- public void testParseEmptyValues() { getParameterTableFor("a b = \"\""); ! assertEquals("Value","",((Attribute)(attributes.elementAt (2))).getValue ()); } *************** *** 315,320 **** public void testParseMissingEqual() { getParameterTableFor("a b\"c\""); ! assertEquals("ValueB",null,table.get("B")); ! assertTrue("NameC",table.containsKey("B\"C\"")); } --- 314,318 ---- public void testParseMissingEqual() { getParameterTableFor("a b\"c\""); ! assertEquals("NameC", "b\"c\"", ((Attribute)(attributes.elementAt (2))).getName ()); } *************** *** 324,329 **** public void testTwoParams(){ getParameterTableFor("PARAM NAME=\"Param1\" VALUE=\"Somik\""); ! assertEquals("Param1","Param1",table.get("NAME")); ! assertEquals("Somik","Somik",table.get("VALUE")); } --- 322,327 ---- public void testTwoParams(){ getParameterTableFor("PARAM NAME=\"Param1\" VALUE=\"Somik\""); ! assertEquals("Param1","Param1",((Attribute)(attributes.elementAt (2))).getValue ()); ! assertEquals("Somik","Somik",((Attribute)(attributes.elementAt (4))).getValue ()); } *************** *** 333,338 **** public void testPlainParams(){ getParameterTableFor("PARAM NAME=Param1 VALUE=Somik"); ! assertEquals("Param1","Param1",table.get("NAME")); ! assertEquals("Somik","Somik",table.get("VALUE")); } --- 331,336 ---- public void testPlainParams(){ getParameterTableFor("PARAM NAME=Param1 VALUE=Somik"); ! assertEquals("Param1","Param1",((Attribute)(attributes.elementAt (2))).getValue ()); ! assertEquals("Somik","Somik",((Attribute)(attributes.elementAt (4))).getValue ()); } *************** *** 342,350 **** public void testValueMissing() { getParameterTableFor("INPUT type=\"checkbox\" name=\"Authorize\" value=\"Y\" checked"); ! assertEquals("Name of Tag","INPUT",table.get(SpecialHashtable.TAGNAME)); ! assertEquals("Type","checkbox",table.get("TYPE")); ! assertEquals("Name","Authorize",table.get("NAME")); ! assertEquals("Value","Y",table.get("VALUE")); ! assertEquals("Checked",null,table.get("CHECKED")); } --- 340,348 ---- public void testValueMissing() { getParameterTableFor("INPUT type=\"checkbox\" name=\"Authorize\" value=\"Y\" checked"); ! assertEquals("Name of Tag","INPUT",((Attribute)(attributes.elementAt (0))).getName ()); ! assertEquals("Type","checkbox",((Attribute)(attributes.elementAt (2))).getValue ()); ! assertEquals("Name","Authorize",((Attribute)(attributes.elementAt (4))).getValue ()); ! assertEquals("Value","Y",((Attribute)(attributes.elementAt (6))).getValue ()); ! assertEquals("Checked",null,((Attribute)(attributes.elementAt (8))).getValue ()); } *************** *** 357,367 **** getParameterTableFor("TEXTAREA name=\"Remarks\" "); // There should only be two keys.. ! assertEquals("There should only be two keys",2,table.size()); // The first key is name ! String key1 = "NAME"; ! String value1 = (String)table.get(key1); ! assertEquals("Expected value 1", "Remarks",value1); ! String key2 = SpecialHashtable.TAGNAME; ! assertEquals("Expected Value 2","TEXTAREA",table.get(key2)); } --- 355,362 ---- getParameterTableFor("TEXTAREA name=\"Remarks\" "); // There should only be two keys.. ! assertEquals("There should only be two attributes",4,attributes.size()); // The first key is name ! assertEquals("Expected name","TEXTAREA",((Attribute)(attributes.elementAt (0))).getName ()); ! assertEquals("Expected value 1", "Remarks",((Attribute)(attributes.elementAt (2))).getValue ()); } *************** *** 371,376 **** public void testNullTag(){ getParameterTableFor("INPUT type="); ! assertEquals("Name of Tag","INPUT",table.get(SpecialHashtable.TAGNAME)); ! assertEquals("Type","",table.get("TYPE")); } --- 366,371 ---- public void testNullTag(){ getParameterTableFor("INPUT type="); ! assertEquals("Name of Tag","INPUT",((Attribute)(attributes.elementAt (0))).getName ()); ! assertNull("Type",((Attribute)(attributes.elementAt (2))).getValue ()); } *************** *** 385,389 **** "href", "/news/866201.asp?0sl=-32", ! (String)table.get("HREF") ); } --- 380,384 ---- "href", "/news/866201.asp?0sl=-32", ! ((Attribute)(attributes.elementAt (4))).getValue () ); } *************** *** 399,408 **** "href", "mailto:sa...@ne...?subject=Site Comments", ! (String)table.get("HREF") ); assertStringEquals( "tag name", ! "A", ! (String)table.get(SpecialHashtable.TAGNAME) ); } --- 394,403 ---- "href", "mailto:sa...@ne...?subject=Site Comments", ! ((Attribute)(attributes.elementAt (2))).getValue () ); assertStringEquals( "tag name", ! "a", ! ((Attribute)(attributes.elementAt (0))).getName () ); } *************** *** 420,424 **** public void testEmptyTag () { getParameterTableFor(""); ! assertNull ("<> is not a tag",table); } --- 415,419 ---- public void testEmptyTag () { getParameterTableFor(""); ! assertNull ("<> is not a tag",attributes); } *************** *** 437,441 **** "href", "<%=Application(\"sURL\")%>/literature/index.htm", ! (String)table.get("HREF") ); } --- 432,436 ---- "href", "<%=Application(\"sURL\")%>/literature/index.htm", ! ((Attribute)(attributes.elementAt (2))).getValue () ); } *************** *** 448,455 **** public void testScriptedTag () { getParameterTableFor("body onLoad=defaultStatus=''"); ! String name = (String)table.get(SpecialHashtable.TAGNAME); assertNotNull ("No Tag.TAGNAME", name); ! assertStringEquals("tag name parsed incorrectly", "BODY", name); ! String value = (String)table.get ("ONLOAD"); assertStringEquals ("parameter parsed incorrectly", "defaultStatus=''", value); } --- 443,450 ---- public void testScriptedTag () { getParameterTableFor("body onLoad=defaultStatus=''"); ! String name = ((Attribute)(attributes.elementAt (0))).getName (); assertNotNull ("No Tag.TAGNAME", name); ! assertStringEquals("tag name parsed incorrectly", "body", name); ! String value = ((Attribute)(attributes.elementAt (2))).getValue (); assertStringEquals ("parameter parsed incorrectly", "defaultStatus=''", value); } *************** *** 463,468 **** { getParameterTableFor ("INPUT DISABLED"); ! assertTrue ("Standalone attribute has no entry in table keyset",table.containsKey("DISABLED")); ! assertNull ("Standalone attribute has non-null value",(String)table.get("DISABLED")); } --- 458,463 ---- { getParameterTableFor ("INPUT DISABLED"); ! assertStringEquals("Standalone attribute not parsed","DISABLED",((Attribute)(attributes.elementAt (2))).getName ()); ! assertNull ("Standalone attribute has non-null value",((Attribute)(attributes.elementAt (2))).getValue ()); } *************** *** 473,478 **** { getParameterTableFor ("INPUT DISABLED="); ! assertTrue ("Attribute has no entry in table keyset",table.containsKey("DISABLED")); ! assertEquals ("Attribute has non-blank value","",(String)table.get("DISABLED")); } --- 468,473 ---- { getParameterTableFor ("INPUT DISABLED="); ! assertStringEquals("Empty attribute has no attribute","DISABLED",((Attribute)(attributes.elementAt (2))).getName ()); ! assertEquals ("Attribute has non-blank value",null,((Attribute)(attributes.elementAt (2))).getValue ()); } *************** *** 484,490 **** { getParameterTableFor ("tag att = other=fred"); ! assertTrue ("Attribute missing", table.containsKey ("ATT")); ! assertEquals ("Attribute has wrong value", "other=fred", (String)table.get ("ATT")); ! assertTrue ("No attribute should be called equal sign", !table.containsKey ("=")); } --- 479,486 ---- { getParameterTableFor ("tag att = other=fred"); ! assertStringEquals("Attribute not parsed","att",((Attribute)(attributes.elementAt (2))).getName ()); ! assertEquals ("Attribute has wrong value", "other=fred", ((Attribute)(attributes.elementAt (2))).getValue ()); ! for (int i = 0; i < attributes.size (); i++) ! assertTrue ("No attribute should be called =", !((Attribute)(attributes.elementAt (2))).getName ().equals ("=")); } *************** *** 495,503 **** { getParameterTableFor ("tag att =value other=fred"); ! assertTrue ("Attribute missing", table.containsKey ("ATT")); ! assertEquals ("Attribute has wrong value", "value", (String)table.get ("ATT")); ! assertTrue ("No attribute should be called =value", !table.containsKey ("=VALUE")); ! assertTrue ("Attribute missing", table.containsKey ("OTHER")); ! assertEquals ("Attribute has wrong value", "fred", (String)table.get ("OTHER")); } --- 491,500 ---- { getParameterTableFor ("tag att =value other=fred"); ! assertStringEquals("Attribute not parsed","att",((Attribute)(attributes.elementAt (2))).getName ()); ! assertEquals ("Attribute has wrong value", "value", ((Attribute)(attributes.elementAt (2))).getValue ()); ! for (int i = 0; i < attributes.size (); i++) ! assertTrue ("No attribute should be called =value", !((Attribute)(attributes.elementAt (2))).getName ().equals ("=value")); ! assertStringEquals("Empty attribute not parsed","other",((Attribute)(attributes.elementAt (4))).getName ()); ! assertEquals ("Attribute has wrong value", "fred", ((Attribute)(attributes.elementAt (4))).getValue ()); } *************** *** 508,516 **** { getParameterTableFor ("tag att= \"value\" other=fred"); ! assertTrue ("Attribute missing", table.containsKey ("ATT")); ! assertEquals ("Attribute has wrong value", "value", (String)table.get ("ATT")); ! assertTrue ("No attribute should be called \"value\"", !table.containsKey ("\"VALUE\"")); ! assertTrue ("Attribute missing", table.containsKey ("OTHER")); ! assertEquals ("Attribute has wrong value", "fred", (String)table.get ("OTHER")); } --- 505,514 ---- { getParameterTableFor ("tag att= \"value\" other=fred"); ! assertStringEquals("Attribute not parsed","att",((Attribute)(attributes.elementAt (2))).getName ()); ! assertEquals ("Attribute has wrong value", "value", ((Attribute)(attributes.elementAt (2))).getValue ()); ! for (int i = 0; i < attributes.size (); i++) ! assertTrue ("No attribute should be called \"value\"", !((Attribute)(attributes.elementAt (2))).getName ().equals ("\"value\"")); ! assertStringEquals("Empty attribute not parsed","other",((Attribute)(attributes.elementAt (4))).getName ()); ! assertEquals ("Attribute has wrong value", "fred", ((Attribute)(attributes.elementAt (4))).getValue ()); } *************** *** 522,532 **** { getParameterTableFor ("tag att=\"va\"lue\" other=fred"); ! assertTrue ("Attribute missing", table.containsKey ("ATT")); ! assertEquals ("Attribute has wrong value", "va", (String)table.get ("ATT")); ! assertTrue ("No attribute should be called va\"lue", !table.containsKey ("VA\"LUE")); ! assertTrue ("Attribute missing", table.containsKey ("LUE\"")); ! assertNull ("Attribute has wrong value", table.get ("LUE\"")); ! assertTrue ("Attribute missing", table.containsKey ("OTHER")); ! assertEquals ("Attribute has wrong value", "fred", (String)table.get ("OTHER")); } --- 520,532 ---- { getParameterTableFor ("tag att=\"va\"lue\" other=fred"); ! assertStringEquals("Attribute not parsed","att",((Attribute)(attributes.elementAt (2))).getName ()); ! assertEquals ("Attribute has wrong value", "va", ((Attribute)(attributes.elementAt (2))).getValue ()); ! for (int i = 0; i < attributes.size (); i++) ! assertTrue ("No attribute should be called va\"lue", !((Attribute)(attributes.elementAt (2))).getName ().equals ("va\"lue")); ! assertStringEquals("Attribute missing","att",((Attribute)(attributes.elementAt (2))).getName ()); ! assertStringEquals("Attribute not parsed","lue\"",((Attribute)(attributes.elementAt (3))).getName ()); ! assertNull ("Attribute has wrong value", ((Attribute)(attributes.elementAt (3))).getValue ()); ! assertStringEquals("Empty attribute not parsed","other",((Attribute)(attributes.elementAt (5))).getName ()); ! assertEquals ("Attribute has wrong value", "fred", ((Attribute)(attributes.elementAt (5))).getValue ()); } *************** *** 538,548 **** { getParameterTableFor ("tag att='va'lue' other=fred"); ! assertTrue ("Attribute missing", table.containsKey ("ATT")); ! assertEquals ("Attribute has wrong value", "va", (String)table.get ("ATT")); ! assertTrue ("No attribute should be called va'lue", !table.containsKey ("VA'LUE")); ! assertTrue ("Attribute missing", table.containsKey ("LUE'")); ! assertNull ("Attribute has wrong value", table.get ("LUE'")); ! assertTrue ("Attribute missing", table.containsKey ("OTHER")); ! assertEquals ("Attribute has wrong value", "fred", (String)table.get ("OTHER")); } --- 538,549 ---- { getParameterTableFor ("tag att='va'lue' other=fred"); ! assertStringEquals("Attribute not parsed","att",((Attribute)(attributes.elementAt (2))).getName ()); ! assertEquals ("Attribute has wrong value", "va", ((Attribute)(attributes.elementAt (2))).getValue ()); ! for (int i = 0; i < attributes.size (); i++) ! assertTrue ("No attribute should be called va'lue", !((Attribute)(attributes.elementAt (2))).getName ().equals ("va'lue")); ! assertStringEquals("Attribute not parsed","lue'",((Attribute)(attributes.elementAt (3))).getName ()); ! assertNull ("Attribute has wrong value", ((Attribute)(attributes.elementAt (3))).getValue ()); ! assertStringEquals("Empty attribute not parsed","other",((Attribute)(attributes.elementAt (5))).getName ()); ! assertEquals ("Attribute has wrong value", "fred", ((Attribute)(attributes.elementAt (5))).getValue ()); } Index: TagTests.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/lexerTests/TagTests.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** TagTests.java 16 Jun 2004 02:17:26 -0000 1.10 --- TagTests.java 2 Jul 2004 00:49:30 -0000 1.11 *************** *** 32,38 **** import org.htmlparser.Parser; import org.htmlparser.PrototypicalNodeFactory; import org.htmlparser.tags.LinkTag; import org.htmlparser.tags.MetaTag; - import org.htmlparser.tags.Tag; import org.htmlparser.tests.ParserTestCase; import org.htmlparser.util.ParserException; --- 32,38 ---- import org.htmlparser.Parser; import org.htmlparser.PrototypicalNodeFactory; + import org.htmlparser.Tag; import org.htmlparser.tags.LinkTag; import org.htmlparser.tags.MetaTag; import org.htmlparser.tests.ParserTestCase; import org.htmlparser.util.ParserException; |