[Htmlparser-cvs] htmlparser/src/org/htmlparser/tests/parserHelperTests AllTests.java,1.26,1.27 Compo
Brought to you by:
derrickoswald
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/parserHelperTests In directory sc8-pr-cvs1:/tmp/cvs-serv24483/src/org/htmlparser/tests/parserHelperTests Modified Files: AllTests.java CompositeTagScannerHelperTest.java RemarkNodeParserTest.java StringParserTest.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: AllTests.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/parserHelperTests/AllTests.java,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** AllTests.java 8 Sep 2003 02:26:30 -0000 1.26 --- AllTests.java 10 Sep 2003 03:38:24 -0000 1.27 *************** *** 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 *************** *** 30,34 **** import junit.framework.*; ! public class AllTests extends junit.framework.TestCase { --- 30,34 ---- import junit.framework.*; ! public class AllTests extends junit.framework.TestCase { Index: CompositeTagScannerHelperTest.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/parserHelperTests/CompositeTagScannerHelperTest.java,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** CompositeTagScannerHelperTest.java 8 Sep 2003 02:26:31 -0000 1.19 --- CompositeTagScannerHelperTest.java 10 Sep 2003 03:38:24 -0000 1.20 *************** *** 1,27 **** // HTMLParser Library v1_4_20030907 - A java-based parser for HTML // Copyright (C) Dec 31, 2000 Somik Raha ! // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. ! // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // 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 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ! // // 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 --- 1,27 ---- // HTMLParser Library v1_4_20030907 - A java-based parser for HTML // Copyright (C) Dec 31, 2000 Somik Raha ! // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. ! // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // 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 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ! // // 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,55 **** protected void setUp() { ! helper = new CompositeTagScannerHelper(null,null,null,null,null,false); } ! ! public void testIsXmlEndTagForRealXml() { Tag tag = new Tag( new TagData( --- 47,55 ---- protected void setUp() { ! helper = new CompositeTagScannerHelper(null,null,null,null,null,false); } ! ! public void testIsXmlEndTagForRealXml() { Tag tag = new Tag( new TagData( *************** *** 60,70 **** } ! public void testIsXmlEndTagForFalseMatches() { Tag tag = new Tag( new TagData( 0,0,"a href=http://someurl.com/","" ) ! ); ! assertFalse("should not be an xml end tag",helper.isXmlEndTag(tag)); } } --- 60,70 ---- } ! public void testIsXmlEndTagForFalseMatches() { Tag tag = new Tag( new TagData( 0,0,"a href=http://someurl.com/","" ) ! ); ! assertFalse("should not be an xml end tag",helper.isXmlEndTag(tag)); } } Index: RemarkNodeParserTest.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/parserHelperTests/RemarkNodeParserTest.java,v retrieving revision 1.34 retrieving revision 1.35 diff -C2 -d -r1.34 -r1.35 *** RemarkNodeParserTest.java 8 Sep 2003 02:26:31 -0000 1.34 --- RemarkNodeParserTest.java 10 Sep 2003 03:38:24 -0000 1.35 *************** *** 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 *************** *** 37,46 **** import org.htmlparser.util.ParserException; ! public class RemarkNodeParserTest extends ParserTestCase { public RemarkNodeParserTest(String name) { super(name); } ! /** * The bug being reproduced is this : <BR> --- 37,46 ---- import org.htmlparser.util.ParserException; ! public class RemarkNodeParserTest extends ParserTestCase { public RemarkNodeParserTest(String name) { super(name); } ! /** * The bug being reproduced is this : <BR> *************** *** 54,60 **** * <TEST> * </TEST> ! * * The above line is incorrectly parsed - the remark is not correctly identified. ! * This bug was reported by Serge Kruppa (2002-Feb-08). */ public void testRemarkNodeBug() throws ParserException --- 54,60 ---- * <TEST> * </TEST> ! * * The above line is incorrectly parsed - the remark is not correctly identified. ! * This bug was reported by Serge Kruppa (2002-Feb-08). */ public void testRemarkNodeBug() throws ParserException *************** *** 75,80 **** assertTrue("First node should be a HTMLRemarkNode",node[0] instanceof RemarkNode); RemarkNode remarkNode = (RemarkNode)node[0]; ! assertEquals("Text of the remarkNode #1"," saved from url=(0022)http://internet.e-mail ",remarkNode.getText()); ! // The sixth node should be a HTMLRemarkNode assertTrue("Sixth node should be a HTMLRemarkNode",node[5] instanceof RemarkNode); remarkNode = (RemarkNode)node[5]; --- 75,80 ---- assertTrue("First node should be a HTMLRemarkNode",node[0] instanceof RemarkNode); RemarkNode remarkNode = (RemarkNode)node[0]; ! assertEquals("Text of the remarkNode #1"," saved from url=(0022)http://internet.e-mail ",remarkNode.getText()); ! // The sixth node should be a HTMLRemarkNode assertTrue("Sixth node should be a HTMLRemarkNode",node[5] instanceof RemarkNode); remarkNode = (RemarkNode)node[5]; *************** *** 98,107 **** assertTrue("First node should be a HTMLRemarkNode",node[0] instanceof RemarkNode); RemarkNode remarkNode = (RemarkNode)node[0]; ! assertEquals("Plain Text of the remarkNode #1"," saved from url=(0022)http://internet.e-mail ",remarkNode.toPlainTextString()); ! // The sixth node should be a HTMLRemarkNode assertTrue("Sixth node should be a HTMLRemarkNode",node[5] instanceof RemarkNode); remarkNode = (RemarkNode)node[5]; ! assertEquals("Plain Text of the remarkNode #6","\r\n Whats gonna happen now ?\r\n",remarkNode.getText()); ! } --- 98,107 ---- assertTrue("First node should be a HTMLRemarkNode",node[0] instanceof RemarkNode); RemarkNode remarkNode = (RemarkNode)node[0]; ! assertEquals("Plain Text of the remarkNode #1"," saved from url=(0022)http://internet.e-mail ",remarkNode.toPlainTextString()); ! // The sixth node should be a HTMLRemarkNode assertTrue("Sixth node should be a HTMLRemarkNode",node[5] instanceof RemarkNode); remarkNode = (RemarkNode)node[5]; ! assertEquals("Plain Text of the remarkNode #6","\r\n Whats gonna happen now ?\r\n",remarkNode.getText()); ! } *************** *** 122,132 **** assertTrue("First node should be a HTMLRemarkNode",node[0] instanceof RemarkNode); RemarkNode remarkNode = (RemarkNode)node[0]; ! assertStringEquals("Raw String of the remarkNode #1","<!-- saved from url=(0022)http://internet.e-mail -->",remarkNode.toHtml()); ! // The sixth node should be a HTMLRemarkNode assertTrue("Sixth node should be a HTMLRemarkNode",node[5] instanceof RemarkNode); remarkNode = (RemarkNode)node[5]; ! assertStringEquals("Raw String of the remarkNode #6","<!--\r\n Whats gonna happen now ?\r\n-->",remarkNode.toHtml()); } ! public void testNonRemarkNode() throws ParserException { createParser(" <![endif]>"); --- 122,132 ---- assertTrue("First node should be a HTMLRemarkNode",node[0] instanceof RemarkNode); RemarkNode remarkNode = (RemarkNode)node[0]; ! assertStringEquals("Raw String of the remarkNode #1","<!-- saved from url=(0022)http://internet.e-mail -->",remarkNode.toHtml()); ! // The sixth node should be a HTMLRemarkNode assertTrue("Sixth node should be a HTMLRemarkNode",node[5] instanceof RemarkNode); remarkNode = (RemarkNode)node[5]; ! assertStringEquals("Raw String of the remarkNode #6","<!--\r\n Whats gonna happen now ?\r\n-->",remarkNode.toHtml()); } ! public void testNonRemarkNode() throws ParserException { createParser(" <![endif]>"); *************** *** 139,145 **** assertEquals("Text contents"," ",stringNode.getText()); assertEquals("Tag Contents","![endif]",tag.getText()); ! } ! /** * This is the simulation of bug report 586756, submitted --- 139,145 ---- assertEquals("Text contents"," ",stringNode.getText()); assertEquals("Tag Contents","![endif]",tag.getText()); ! } ! /** * This is the simulation of bug report 586756, submitted *************** *** 147,151 **** * If all the comment contains is a blank line, it breaks * the state ! */ public void testRemarkNodeWithBlankLine() throws ParserException { createParser("<!--\n"+ --- 147,151 ---- * If all the comment contains is a blank line, it breaks * the state ! */ public void testRemarkNodeWithBlankLine() throws ParserException { createParser("<!--\n"+ *************** *** 157,168 **** RemarkNode remarkNode = (RemarkNode)node[0]; assertEquals("Expected contents","\r\n",remarkNode.getText()); ! } ! /** * This is the simulation of a bug report submitted * by Claude Duguay. * If it is a comment with nothing in it, parser crashes ! */ public void testRemarkNodeWithNothing() throws ParserException { createParser("<!-->"); --- 157,168 ---- RemarkNode remarkNode = (RemarkNode)node[0]; assertEquals("Expected contents","\r\n",remarkNode.getText()); ! } ! /** * This is the simulation of a bug report submitted * by Claude Duguay. * If it is a comment with nothing in it, parser crashes ! */ public void testRemarkNodeWithNothing() throws ParserException { createParser("<!-->"); *************** *** 171,177 **** RemarkNode remarkNode = (RemarkNode)node[0]; assertEquals("Expected contents","",remarkNode.getText()); ! ! } ! /** * Reproduction of bug reported by John Zook [594301] --- 171,177 ---- RemarkNode remarkNode = (RemarkNode)node[0]; assertEquals("Expected contents","",remarkNode.getText()); ! ! } ! /** * Reproduction of bug reported by John Zook [594301] *************** *** 179,183 **** * <!-- <A> --> * it doesent get parsed correctly ! */ public void testTagWithinRemarkNode() throws ParserException { createParser("<!-- \n"+ --- 179,183 ---- * <!-- <A> --> * it doesent get parsed correctly ! */ public void testTagWithinRemarkNode() throws ParserException { createParser("<!-- \n"+ *************** *** 189,195 **** RemarkNode remarkNode = (RemarkNode)node[0]; assertStringEquals("Expected contents"," \n<A>\nbcd ",remarkNode.getText()); ! } ! /** * Bug reported by John Zook [594301], invalid remark nodes are accepted as remark nodes. --- 189,195 ---- RemarkNode remarkNode = (RemarkNode)node[0]; assertStringEquals("Expected contents"," \n<A>\nbcd ",remarkNode.getText()); ! } ! /** * Bug reported by John Zook [594301], invalid remark nodes are accepted as remark nodes. *************** *** 215,219 **** Parser.setLineSeparator("\r\n"); } ! /** * Bug reported by John Zook [594301] --- 215,219 ---- Parser.setLineSeparator("\r\n"); } ! /** * Bug reported by John Zook [594301] *************** *** 273,277 **** assertEquals("Remark Node contents"," Id: html-sgml.sgm,v 1.5 1995/05/26 21:29:50 connolly Exp ",remarkNode.getText()); } ! /** * Test a comment declaration with two comments. --- 273,277 ---- assertEquals("Remark Node contents"," Id: html-sgml.sgm,v 1.5 1995/05/26 21:29:50 connolly Exp ",remarkNode.getText()); } ! /** * Test a comment declaration with two comments. *************** *** 366,369 **** parseAndAssertNodeCount (10); } ! } --- 366,369 ---- parseAndAssertNodeCount (10); } ! } Index: StringParserTest.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/parserHelperTests/StringParserTest.java,v retrieving revision 1.36 retrieving revision 1.37 diff -C2 -d -r1.36 -r1.37 *** StringParserTest.java 8 Sep 2003 02:26:31 -0000 1.36 --- StringParserTest.java 10 Sep 2003 03:38:24 -0000 1.37 *************** *** 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 *************** *** 43,47 **** super(name); } ! /** * The bug being reproduced is this : <BR> --- 43,47 ---- super(name); } ! /** * The bug being reproduced is this : <BR> *************** *** 60,64 **** assertEquals("Text of the StringNode","Google",stringNode.getText()); } ! /** * Bug reported by Kaarle Kaila of Nokia<br> --- 60,64 ---- assertEquals("Text of the StringNode","Google",stringNode.getText()); } ! /** * Bug reported by Kaarle Kaila of Nokia<br> *************** *** 71,75 **** public void testStringNodeBug2() throws ParserException { // Register the link scanner ! createParser("view these documents, you must have <A href='http://www.adobe.com'>Adobe \n"+ "Acrobat Reader</A> installed on your computer."); --- 71,75 ---- public void testStringNodeBug2() throws ParserException { // Register the link scanner ! createParser("view these documents, you must have <A href='http://www.adobe.com'>Adobe \n"+ "Acrobat Reader</A> installed on your computer."); *************** *** 77,81 **** parser.addScanner(new LinkScanner("-l")); parseAndAssertNodeCount(3); ! // The first node should be a HTMLStringNode- with the text - view these documents, you must have assertTrue("First node should be a HTMLStringNode",node[0] instanceof StringNode); StringNode stringNode = (StringNode)node[0]; --- 77,81 ---- parser.addScanner(new LinkScanner("-l")); parseAndAssertNodeCount(3); ! // The first node should be a HTMLStringNode- with the text - view these documents, you must have assertTrue("First node should be a HTMLStringNode",node[0] instanceof StringNode); StringNode stringNode = (StringNode)node[0]; *************** *** 85,94 **** assertEquals("Link is","http://www.adobe.com",linkNode.getLink()); assertEquals("Link text is","Adobe \r\nAcrobat Reader",linkNode.getLinkText()); ! assertTrue("Third node should be a string node",node[2] instanceof StringNode); StringNode stringNode2 = (StringNode)node[2]; assertEquals("Contents of third node"," installed on your computer.",stringNode2.getText()); } ! /** * Bug reported by Roger Sollberger<br> --- 85,94 ---- assertEquals("Link is","http://www.adobe.com",linkNode.getLink()); assertEquals("Link text is","Adobe \r\nAcrobat Reader",linkNode.getLinkText()); ! assertTrue("Third node should be a string node",node[2] instanceof StringNode); StringNode stringNode2 = (StringNode)node[2]; assertEquals("Contents of third node"," installed on your computer.",stringNode2.getText()); } ! /** * Bug reported by Roger Sollberger<br> *************** *** 106,110 **** assertEquals("http://asgard.ch",linkTag.getLink()); } ! public void testToPlainTextString() throws ParserException { createParser("<HTML><HEAD><TITLE>This is the Title</TITLE></HEAD><BODY>Hello World, this is the HTML Parser</BODY></HTML>"); --- 106,110 ---- assertEquals("http://asgard.ch",linkTag.getLink()); } ! public void testToPlainTextString() throws ParserException { createParser("<HTML><HEAD><TITLE>This is the Title</TITLE></HEAD><BODY>Hello World, this is the HTML Parser</BODY></HTML>"); *************** *** 117,121 **** assertEquals("Second string node","Hello World, this is the HTML Parser",stringNode.toPlainTextString()); } ! public void testToHTML() throws ParserException { createParser("<HTML><HEAD><TITLE>This is the Title</TITLE></HEAD><BODY>Hello World, this is the HTML Parser</BODY></HTML>"); --- 117,121 ---- assertEquals("Second string node","Hello World, this is the HTML Parser",stringNode.toPlainTextString()); } ! public void testToHTML() throws ParserException { createParser("<HTML><HEAD><TITLE>This is the Title</TITLE></HEAD><BODY>Hello World, this is the HTML Parser</BODY></HTML>"); *************** *** 157,161 **** RemarkNode remarkNode = (RemarkNode)node[1]; assertEquals("Remark Node contents"," Comment ",remarkNode.getText()); ! } --- 157,161 ---- RemarkNode remarkNode = (RemarkNode)node[1]; assertEquals("Remark Node contents"," Comment ",remarkNode.getText()); ! } *************** *** 171,175 **** assertEquals("First String node contents","a",stringNode.getText()); } ! public void testStringWithEmptyLine() throws ParserException { createParser("a\n\nb"); --- 171,175 ---- assertEquals("First String node contents","a",stringNode.getText()); } ! public void testStringWithEmptyLine() throws ParserException { createParser("a\n\nb"); *************** *** 178,183 **** StringNode stringNode = (StringNode)node[0]; assertStringEquals("First String node contents","a\r\n\r\nb",stringNode.getText()); ! } ! /** * An attempt to reproduce bug 677176, which passes. --- 178,183 ---- StringNode stringNode = (StringNode)node[0]; assertStringEquals("First String node contents","a\r\n\r\nb",stringNode.getText()); ! } ! /** * An attempt to reproduce bug 677176, which passes. *************** *** 203,213 **** "<body>" + "</body>" + ! "</html>" ! ); parser.registerScanners(); parseAndAssertNodeCount(10); assertType("fourth node",MetaTag.class,node[4]); MetaTag metaTag = (MetaTag)node[4]; ! assertStringEquals( "content", --- 203,213 ---- "<body>" + "</body>" + ! "</html>" ! ); parser.registerScanners(); parseAndAssertNodeCount(10); assertType("fourth node",MetaTag.class,node[4]); MetaTag metaTag = (MetaTag)node[4]; ! assertStringEquals( "content", *************** *** 216,220 **** ); } ! public void testStringWithLineBreaks() throws Exception { createParser("Testing &\nRefactoring"); --- 216,220 ---- ); } ! public void testStringWithLineBreaks() throws Exception { createParser("Testing &\nRefactoring"); *************** *** 224,227 **** assertStringEquals("text","Testing &\r\nRefactoring",stringNode.toPlainTextString()); } ! } --- 224,227 ---- assertStringEquals("text","Testing &\r\nRefactoring",stringNode.toPlainTextString()); } ! } |