[Htmlparser-cvs] htmlparser/src/org/htmlparser/tests/temporaryFailures AttributeParserTest.java,1.12
Brought to you by:
derrickoswald
From: <der...@us...> - 2003-09-10 03:54:08
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/temporaryFailures In directory sc8-pr-cvs1:/tmp/cvs-serv24483/src/org/htmlparser/tests/temporaryFailures Modified Files: AttributeParserTest.java TagParserTest.java Log Message: Add style checking target to ant build script: ant checkstyle It uses a jar from http://checkstyle.sourceforge.net which is dropped in the lib directory. The rules are in the file htmlparser_checks.xml in the src directory. Added lexerapplications package with Tabby as the first app. It performs whitespace manipulation on source files to follow the style rules. This reduced the number of style violations to roughly 14,000. There are a few issues with the style checker that need to be resolved before it should be taken too seriously. For example: It thinks all method arguments should be final, even if they are modified by the code (which the compiler frowns on). It complains about long lines, even when there is no possibility of wrapping the line, i.e. a URL in a comment that's more than 80 characters long. It considers all naked integers as 'magic numbers', even when they are obvious, i.e. the 4 corners of a box. It complains about whitespace following braces, even in array initializers, i.e. X[][] = { {a, b} { } } But it points out some really interesting things, even if you don't agree with the style guidelines, so it's worth a look. Index: AttributeParserTest.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/temporaryFailures/AttributeParserTest.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** AttributeParserTest.java 8 Sep 2003 02:26:31 -0000 1.12 --- AttributeParserTest.java 10 Sep 2003 03:38:25 -0000 1.13 *************** *** 11,15 **** // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. ! // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software --- 11,15 ---- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. ! // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software *************** *** 18,27 **** // For any questions or suggestions, you can write to me at : // Email :so...@in... ! // ! // Postal Address : // Somik Raha // Extreme Programmer & Coach // Industrial Logic Corporation ! // 2583 Cedar Street, Berkeley, // CA 94708, USA // Website : http://www.industriallogic.com --- 18,27 ---- // For any questions or suggestions, you can write to me at : // Email :so...@in... ! // ! // Postal Address : // Somik Raha // Extreme Programmer & Coach // Industrial Logic Corporation ! // 2583 Cedar Street, Berkeley, // CA 94708, USA // Website : http://www.industriallogic.com *************** *** 47,51 **** private Tag tag; private Hashtable table; ! public AttributeParserTest(String name) { super(name); --- 47,51 ---- private Tag tag; private Hashtable table; ! public AttributeParserTest(String name) { super(name); *************** *** 55,65 **** parser = new AttributeParser(); } ! public void getParameterTableFor(String tagContents) { tag = new Tag(new TagData(0,0,tagContents,"")); table = parser.parseAttributes(tag.getText ()); ! } ! public void testParseParameters() { getParameterTableFor("a b = \"c\""); --- 55,65 ---- parser = new AttributeParser(); } ! public void getParameterTableFor(String tagContents) { tag = new Tag(new TagData(0,0,tagContents,"")); table = parser.parseAttributes(tag.getText ()); ! } ! public void testParseParameters() { getParameterTableFor("a b = \"c\""); *************** *** 71,78 **** assertEquals("Value","'",table.get("B")); } ! public void testParseEmptyValues() { getParameterTableFor("a b = \"\""); ! assertEquals("Value","",table.get("B")); } --- 71,78 ---- assertEquals("Value","'",table.get("B")); } ! public void testParseEmptyValues() { getParameterTableFor("a b = \"\""); ! assertEquals("Value","",table.get("B")); } *************** *** 80,90 **** getParameterTableFor("a b\"c\""); assertEquals("ValueB",null,table.get("B")); ! } ! public void testTwoParams(){ getParameterTableFor("PARAM NAME=\"Param1\" VALUE=\"Somik\">\n"); assertEquals("Param1","Param1",table.get("NAME")); ! assertEquals("Somik","Somik",table.get("VALUE")); } --- 80,90 ---- getParameterTableFor("a b\"c\""); assertEquals("ValueB",null,table.get("B")); ! } ! public void testTwoParams(){ getParameterTableFor("PARAM NAME=\"Param1\" VALUE=\"Somik\">\n"); assertEquals("Param1","Param1",table.get("NAME")); ! assertEquals("Somik","Somik",table.get("VALUE")); } *************** *** 92,102 **** getParameterTableFor("PARAM NAME=Param1 VALUE=Somik"); assertEquals("Param1","Param1",table.get("NAME")); ! assertEquals("Somik","Somik",table.get("VALUE")); } ! public void testValueMissing() { getParameterTableFor("INPUT type=\"checkbox\" name=\"Authorize\" value=\"Y\" checked"); assertEquals("Name of Tag","INPUT",table.get(Tag.TAGNAME)); ! assertEquals("Type","checkbox",table.get("TYPE")); assertEquals("Name","Authorize",table.get("NAME")); assertEquals("Value","Y",table.get("VALUE")); --- 92,102 ---- getParameterTableFor("PARAM NAME=Param1 VALUE=Somik"); assertEquals("Param1","Param1",table.get("NAME")); ! assertEquals("Somik","Somik",table.get("VALUE")); } ! public void testValueMissing() { getParameterTableFor("INPUT type=\"checkbox\" name=\"Authorize\" value=\"Y\" checked"); assertEquals("Name of Tag","INPUT",table.get(Tag.TAGNAME)); ! assertEquals("Type","checkbox",table.get("TYPE")); assertEquals("Name","Authorize",table.get("NAME")); assertEquals("Value","Y",table.get("VALUE")); *************** *** 105,109 **** /** ! * This is a simulation of a bug reported by Dhaval Udani - wherein * a space before the end of the tag causes a problem - there is a key * in the table with just a space in it and an empty value --- 105,109 ---- /** ! * This is a simulation of a bug reported by Dhaval Udani - wherein * a space before the end of the tag causes a problem - there is a key * in the table with just a space in it and an empty value *************** *** 124,130 **** getParameterTableFor("INPUT type="); assertEquals("Name of Tag","INPUT",table.get(Tag.TAGNAME)); ! assertEquals("Type","",table.get("TYPE")); } ! public void testAttributeWithSpuriousEqualTo() { getParameterTableFor( --- 124,130 ---- getParameterTableFor("INPUT type="); assertEquals("Name of Tag","INPUT",table.get(Tag.TAGNAME)); ! assertEquals("Type","",table.get("TYPE")); } ! public void testAttributeWithSpuriousEqualTo() { getParameterTableFor( *************** *** 137,141 **** ); } ! public void testQuestionMarksInAttributes() { getParameterTableFor( --- 137,141 ---- ); } ! public void testQuestionMarksInAttributes() { getParameterTableFor( *************** *** 187,191 **** } } ! /** * Test Script in attributes. --- 187,191 ---- } } ! /** * Test Script in attributes. *************** *** 204,208 **** } } ! /** * Test that stand-alone attributes are kept that way, rather than being --- 204,208 ---- } } ! /** * Test that stand-alone attributes are kept that way, rather than being Index: TagParserTest.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/temporaryFailures/TagParserTest.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** TagParserTest.java 8 Sep 2003 02:26:31 -0000 1.10 --- TagParserTest.java 10 Sep 2003 03:38:25 -0000 1.11 *************** *** 11,15 **** // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. ! // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software --- 11,15 ---- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. ! // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software *************** *** 18,27 **** // For any questions or suggestions, you can write to me at : // Email :so...@in... ! // ! // Postal Address : // Somik Raha // Extreme Programmer & Coach // Industrial Logic, Inc. ! // 2583 Cedar Street, Berkeley, // CA 94708, USA // Website : http://www.industriallogic.com --- 18,27 ---- // For any questions or suggestions, you can write to me at : // Email :so...@in... ! // ! // Postal Address : // Somik Raha // Extreme Programmer & Coach // Industrial Logic, Inc. ! // 2583 Cedar Street, Berkeley, // CA 94708, USA // Website : http://www.industriallogic.com *************** *** 82,94 **** private Map results; private int testProgress; ! public TagParserTest(String name) { super(name); } ! public void testTagWithQuotes() throws Exception { ! String testHtml = "<img src=\"http://g-images.amazon.com/images/G/01/merchants/logos/marshall-fields-logo-20.gif\" width=87 height=20 border=0 alt=\"Marshall Field's\">"; ! createParser(testHtml); parseAndAssertNodeCount(1); --- 82,94 ---- private Map results; private int testProgress; ! public TagParserTest(String name) { super(name); } ! public void testTagWithQuotes() throws Exception { ! String testHtml = "<img src=\"http://g-images.amazon.com/images/G/01/merchants/logos/marshall-fields-logo-20.gif\" width=87 height=20 border=0 alt=\"Marshall Field's\">"; ! createParser(testHtml); parseAndAssertNodeCount(1); *************** *** 102,106 **** ); } ! public void testEmptyTag() throws Exception { createParser("<custom/>"); --- 102,106 ---- ); } ! public void testEmptyTag() throws Exception { createParser("<custom/>"); *************** *** 116,120 **** ); } ! public void testTagWithCloseTagSymbolInAttribute() throws ParserException { createParser("<tag att=\"a>b\">"); --- 116,120 ---- ); } ! public void testTagWithCloseTagSymbolInAttribute() throws ParserException { createParser("<tag att=\"a>b\">"); *************** *** 124,128 **** assertStringEquals("attribute","a>b",tag.getAttribute("att")); } ! public void testTagWithOpenTagSymbolInAttribute() throws ParserException { createParser("<tag att=\"a<b\">"); --- 124,128 ---- assertStringEquals("attribute","a>b",tag.getAttribute("att")); } ! public void testTagWithOpenTagSymbolInAttribute() throws ParserException { createParser("<tag att=\"a<b\">"); *************** *** 251,255 **** } } ! /** * Test multiline split tag like attribute. --- 251,255 ---- } } ! /** * Test multiline split tag like attribute. *************** *** 295,311 **** String testHtml2 = "<a href=\"http://normallink.com/sometext.html\">" + TEST_HTML; ! ParsingThread parsingThread [] = new ParsingThread[100]; results = new HashMap(); testProgress = 0; for (int i=0;i<parsingThread.length;i++) { ! if (i<parsingThread.length/2) ! parsingThread[i] = new ParsingThread(i,testHtml1,parsingThread.length); else ! parsingThread[i] = new ParsingThread(i,testHtml2,parsingThread.length); ! Thread thread = new Thread(parsingThread[i]); thread.start(); } --- 295,311 ---- String testHtml2 = "<a href=\"http://normallink.com/sometext.html\">" + TEST_HTML; ! ParsingThread parsingThread [] = new ParsingThread[100]; results = new HashMap(); testProgress = 0; for (int i=0;i<parsingThread.length;i++) { ! if (i<parsingThread.length/2) ! parsingThread[i] = new ParsingThread(i,testHtml1,parsingThread.length); else ! parsingThread[i] = new ParsingThread(i,testHtml2,parsingThread.length); ! Thread thread = new Thread(parsingThread[i]); thread.start(); } *************** *** 319,323 **** catch (InterruptedException e) { } ! } while (testProgress!=completionValue); for (int i=0;i<parsingThread.length;i++) { --- 319,323 ---- catch (InterruptedException e) { } ! } while (testProgress!=completionValue); for (int i=0;i<parsingThread.length;i++) { *************** *** 348,352 **** parsingThread[i].getLink2().getLink() ); ! } } } --- 348,352 ---- parsingThread[i].getLink2().getLink() ); ! } } } *************** *** 358,362 **** return numThreads * (numThreads - 1) / 2; } ! class ParsingThread implements Runnable { Parser parser; --- 358,362 ---- return numThreads * (numThreads - 1) / 2; } ! class ParsingThread implements Runnable { Parser parser; *************** *** 365,377 **** boolean result; int max; ! ParsingThread(int id, String testHtml, int max) { this.id = id; this.max = max; ! this.parser = Parser.createParser(testHtml); parser.registerScanners(); } ! public void run() { try { --- 365,377 ---- boolean result; int max; ! ParsingThread(int id, String testHtml, int max) { this.id = id; this.max = max; ! this.parser = Parser.createParser(testHtml); parser.registerScanners(); } ! public void run() { try { *************** *** 398,415 **** } } ! public LinkTag getLink1() { return link1; } ! public LinkTag getLink2() { return link2; } ! public boolean passed() { return result; } } ! /** * Test the toHTML method for a standalone attribute. --- 398,415 ---- } } ! public LinkTag getLink1() { return link1; } ! public LinkTag getLink2() { return link2; } ! public boolean passed() { return result; } } ! /** * Test the toHTML method for a standalone attribute. *************** *** 424,428 **** assertStringEquals ("html","<INPUT DISABLED>", html); } ! /** * Test the toHTML method for a missing value attribute. --- 424,428 ---- assertStringEquals ("html","<INPUT DISABLED>", html); } ! /** * Test the toHTML method for a missing value attribute. *************** *** 437,440 **** assertStringEquals ("html","<INPUT DISABLED=>", html); } ! } --- 437,440 ---- assertStringEquals ("html","<INPUT DISABLED=>", html); } ! } |