[Htmlparser-cvs] htmlparser/src/org/htmlparser/tests/lexerTests AttributeTests.java,1.11,1.12
Brought to you by:
derrickoswald
From: <der...@us...> - 2004-02-07 14:09:57
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/lexerTests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15266/tests/lexerTests Modified Files: AttributeTests.java Log Message: Fix bug #891058 Bug in lexer. Patch submitted by Gernot Fricke. This change causes attribute parsing to be more 'greedy' resulting in 'empty' attributes consuming the next attribute. This brings the lexer parsing more in line with other (browser) interpretations and simplifies it immensely. Index: AttributeTests.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/lexerTests/AttributeTests.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** AttributeTests.java 14 Jan 2004 02:53:47 -0000 1.11 --- AttributeTests.java 7 Feb 2004 12:53:09 -0000 1.12 *************** *** 58,65 **** public void getParameterTableFor(String tagContents) { String html; NodeIterator iterator; Node node; - Tag tag; Vector attributes; --- 58,69 ---- public void getParameterTableFor(String tagContents) { + getParameterTableFor (tagContents, false); + } + + public void getParameterTableFor(String tagContents, boolean dump) + { String html; NodeIterator iterator; Node node; Vector attributes; *************** *** 75,81 **** tag = (Tag)node; attributes = tag.getAttributesEx (); ! // for (int i = 0; i < attributes.size (); i++) ! // System.out.print ("|" + attributes.elementAt (i)); ! // System.out.println ("|"); table = tag.getAttributes (); } --- 79,100 ---- tag = (Tag)node; attributes = tag.getAttributesEx (); ! if (dump) ! { ! for (int i = 0; i < attributes.size (); i++) ! { ! System.out.print ("Attribute #" + i); ! Attribute attribute = (Attribute)attributes.elementAt (i); ! if (null != attribute.getName ()) ! System.out.print (" Name: '" + attribute.getName () + "'"); ! if (null != attribute.getAssignment ()) ! System.out.print (" Assignment: '" + attribute.getAssignment () + "'"); ! if (0 != attribute.getQuote ()) ! System.out.print (" Quote: " + attribute.getQuote ()); ! if (null != attribute.getValue ()) ! System.out.print (" Value: '" + attribute.getValue () + "'"); ! System.out.println (); ! } ! System.out.println (); ! } table = tag.getAttributes (); } *************** *** 98,101 **** --- 117,121 ---- { Vector attributes; + Tag tag; String html; *************** *** 126,129 **** --- 146,150 ---- Attribute space; Vector attributes; + Tag tag; String html; *************** *** 180,183 **** --- 201,205 ---- { Vector attributes; + Tag tag; String html; *************** *** 208,211 **** --- 230,234 ---- Attribute space; Vector attributes; + Tag tag; String html; *************** *** 455,458 **** --- 478,482 ---- /** * Test Rule 1. + * See discussion in Bug#891058 Bug in lexer. regarding alternate interpretations. */ public void testRule1 () *************** *** 460,467 **** getParameterTableFor ("tag att = other=fred"); assertTrue ("Attribute missing", table.containsKey ("ATT")); ! assertEquals ("Attribute has wrong value", "", (String)table.get ("ATT")); assertTrue ("No attribute should be called equal sign", !table.containsKey ("=")); - assertTrue ("Attribute missing", table.containsKey ("OTHER")); - assertEquals ("Attribute has wrong value", "fred", (String)table.get ("OTHER")); } --- 484,489 ---- 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 ("=")); } *************** *** 494,497 **** --- 516,520 ---- /** * Test Rule 4. + * See discussion in Bug#891058 Bug in lexer. regarding alternate interpretations. */ public void testRule4 () *************** *** 499,504 **** getParameterTableFor ("tag att=\"va\"lue\" other=fred"); assertTrue ("Attribute missing", table.containsKey ("ATT")); ! assertEquals ("Attribute has wrong value", "va\"lue", (String)table.get ("ATT")); assertTrue ("No attribute should be called va\"lue", !table.containsKey ("VA\"LUE")); assertTrue ("Attribute missing", table.containsKey ("OTHER")); assertEquals ("Attribute has wrong value", "fred", (String)table.get ("OTHER")); --- 522,529 ---- 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")); *************** *** 507,510 **** --- 532,536 ---- /** * Test Rule 5. + * See discussion in Bug#891058 Bug in lexer. regarding alternate interpretations. */ public void testRule5 () *************** *** 512,517 **** getParameterTableFor ("tag att='va'lue' other=fred"); assertTrue ("Attribute missing", table.containsKey ("ATT")); ! assertEquals ("Attribute has wrong value", "va'lue", (String)table.get ("ATT")); assertTrue ("No attribute should be called va'lue", !table.containsKey ("VA'LUE")); assertTrue ("Attribute missing", table.containsKey ("OTHER")); assertEquals ("Attribute has wrong value", "fred", (String)table.get ("OTHER")); --- 538,545 ---- 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")); |