[Htmlparser-cvs] htmlparser/src/org/htmlparser/tests FunctionalTests.java,1.48,1.49 LineNumberAssign
Brought to you by:
derrickoswald
From: <der...@us...> - 2003-11-01 21:55:47
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests In directory sc8-pr-cvs1:/tmp/cvs-serv2656/tests Modified Files: FunctionalTests.java LineNumberAssignedByNodeReaderTest.java ParserTestCase.java Log Message: Create nodes by cloning from a list of prototypes in the Parser (NodeFactory). So now, the startTag() is the CompositeTag, and the CompositeTagScanner just adds children. This is an intermediate code drop on the way to integrating the scanners with the tags; the scanners no longer create the tags (but they still create the prototypical ones). Index: FunctionalTests.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/FunctionalTests.java,v retrieving revision 1.48 retrieving revision 1.49 diff -C2 -d -r1.48 -r1.49 *** FunctionalTests.java 29 Oct 2003 03:31:18 -0000 1.48 --- FunctionalTests.java 1 Nov 2003 21:55:43 -0000 1.49 *************** *** 33,36 **** --- 33,37 ---- import java.io.InputStream; import java.io.InputStreamReader; + import java.io.Reader; import java.net.MalformedURLException; import java.net.URL; *************** *** 67,96 **** // First count the image tags as is int imgTagCount; ! imgTagCount = findImageTagCount(); ! try { ! int parserImgTagCount = countImageTagsWithHTMLParser(); ! assertEquals("Image Tag Count",imgTagCount,parserImgTagCount); ! } ! catch (ParserException e) { ! throw new ParserException("Error thrown in call to countImageTagsWithHTMLParser()",e); ! } ! } ! public int findImageTagCount() { int imgTagCount = 0; ! try { ! URL url = new URL("http://education.yahoo.com/"); ! InputStream is = url.openStream(); ! BufferedReader reader; ! reader = new BufferedReader(new InputStreamReader(is)); ! imgTagCount = countImageTagsWithoutHTMLParser(reader); ! is.close(); ! } ! catch (MalformedURLException e) { ! System.err.println("URL was malformed!"); } ! catch (IOException e) { ! System.err.println("IO Exception occurred while trying to open stream"); } return imgTagCount; --- 68,86 ---- // First count the image tags as is int imgTagCount; ! int parserImgTagCount = countImageTagsWithHTMLParser(); ! imgTagCount = findImageTagCount(getParser ()); ! assertEquals("Image Tag Count",imgTagCount,parserImgTagCount); } ! public int findImageTagCount(Parser parser) { int imgTagCount = 0; ! parser.reset (); ! try ! { ! imgTagCount = countImageTagsWithoutHTMLParser(parser); } ! catch (IOException e) ! { ! System.err.println ("IO Exception occurred while counting tags"); } return imgTagCount; *************** *** 100,103 **** --- 90,94 ---- Parser parser = new Parser("http://education.yahoo.com/",new DefaultParserFeedback()); parser.addScanner(new ImageScanner("-i")); + setParser (parser); int parserImgTagCount = 0; Node node; *************** *** 111,119 **** } ! public int countImageTagsWithoutHTMLParser(BufferedReader reader) throws IOException { String line; ! int imgTagCount = 0; do { ! line = reader.readLine(); if (line!=null) { // Check the line for image tags --- 102,115 ---- } ! public int countImageTagsWithoutHTMLParser (Parser parser) throws IOException ! { ! BufferedReader lines; String line; ! int imgTagCount; ! ! imgTagCount = 0; ! lines = new BufferedReader (parser.getLexer ().getPage ().getSource ()); do { ! line = lines.readLine(); if (line!=null) { // Check the line for image tags Index: LineNumberAssignedByNodeReaderTest.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/LineNumberAssignedByNodeReaderTest.java,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** LineNumberAssignedByNodeReaderTest.java 26 Oct 2003 19:46:25 -0000 1.26 --- LineNumberAssignedByNodeReaderTest.java 1 Nov 2003 21:55:43 -0000 1.27 *************** *** 61,70 **** * @throws ParserException if there is a problem parsing the test data */ ! public void testLineNumbers() throws ParserException { testLineNumber("<Custom/>", 1, 0, 0, 0); testLineNumber("<Custom />", 1, 0, 0, 0); testLineNumber("<Custom></Custom>", 1, 0, 0, 0); testLineNumber("<Custom>Content</Custom>", 1, 0, 0, 0); testLineNumber("<Custom>Content<Custom></Custom>", 1, 0, 0, 0); testLineNumber( "<Custom>\n" + --- 61,91 ---- * @throws ParserException if there is a problem parsing the test data */ ! public void testLineNumbers1() throws ParserException ! { testLineNumber("<Custom/>", 1, 0, 0, 0); + } + + public void testLineNumbers2() throws ParserException + { testLineNumber("<Custom />", 1, 0, 0, 0); + } + + public void testLineNumbers3() throws ParserException + { testLineNumber("<Custom></Custom>", 1, 0, 0, 0); + } + + public void testLineNumbers4() throws ParserException + { testLineNumber("<Custom>Content</Custom>", 1, 0, 0, 0); + } + + public void testLineNumbers5() throws ParserException + { testLineNumber("<Custom>Content<Custom></Custom>", 1, 0, 0, 0); + } + + public void testLineNumbers6() throws ParserException + { testLineNumber( "<Custom>\n" + *************** *** 73,76 **** --- 94,101 ---- 1, 0, 0, 2 ); + } + + public void testLineNumbers7() throws ParserException + { testLineNumber( "Foo\n" + *************** *** 80,83 **** --- 105,112 ---- 2, 1, 1, 3 ); + } + + public void testLineNumbers8() throws ParserException + { testLineNumber( "Foo\n" + *************** *** 87,90 **** --- 116,123 ---- 2, 1, 1, 3 ); + } + + public void testLineNumbers9() throws ParserException + { char[] oneHundredNewLines = new char[100]; Arrays.fill(oneHundredNewLines, '\n'); *************** *** 117,121 **** CustomTag tag = (CustomTag)node[useNode]; assertEquals("start line", expectedStartLine, tag.getStartingLineNumber ()); ! assertEquals("end line", expectedEndLine, tag.getEndingLineNumber ()); } --- 150,154 ---- CustomTag tag = (CustomTag)node[useNode]; assertEquals("start line", expectedStartLine, tag.getStartingLineNumber ()); ! assertEquals("end line", expectedEndLine, tag.getEndTag ().getEndingLineNumber ()); } Index: ParserTestCase.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/ParserTestCase.java,v retrieving revision 1.37 retrieving revision 1.38 diff -C2 -d -r1.37 -r1.38 *** ParserTestCase.java 1 Nov 2003 04:03:21 -0000 1.37 --- ParserTestCase.java 1 Nov 2003 21:55:43 -0000 1.38 *************** *** 99,102 **** --- 99,112 ---- } + public Parser getParser () + { + return (parser); + } + + public void setParser (Parser parser) + { + this.parser = parser; + } + public void assertStringEquals(String message, String expected, String actual) { |