Thread: [Htmlparser-cvs] htmlparser/src/org/htmlparser/tests/scannersTests CompositeTagScannerTest.java,1.41
Brought to you by:
derrickoswald
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/scannersTests In directory sc8-pr-cvs1:/tmp/cvs-serv26197/tests/scannersTests Modified Files: CompositeTagScannerTest.java ImageScannerTest.java LinkScannerTest.java TableScannerTest.java TagScannerTest.java Log Message: Removed lexer level AbstractNode. Removed data package from parser level tags. Separated tag creation from recursion in NodeFactory interface. Index: CompositeTagScannerTest.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/scannersTests/CompositeTagScannerTest.java,v retrieving revision 1.41 retrieving revision 1.42 diff -C2 -d -r1.41 -r1.42 *** CompositeTagScannerTest.java 6 Oct 2003 01:43:28 -0000 1.41 --- CompositeTagScannerTest.java 20 Oct 2003 01:28:04 -0000 1.42 *************** *** 29,40 **** package org.htmlparser.tests.scannersTests; import org.htmlparser.Node; import org.htmlparser.StringNode; import org.htmlparser.scanners.CompositeTagScanner; import org.htmlparser.tags.CompositeTag; import org.htmlparser.tags.Tag; - import org.htmlparser.tags.data.CompositeTagData; - import org.htmlparser.tags.data.TagData; import org.htmlparser.tests.ParserTestCase; import org.htmlparser.util.ParserException; --- 29,41 ---- package org.htmlparser.tests.scannersTests; + import java.util.Vector; import org.htmlparser.Node; import org.htmlparser.StringNode; + import org.htmlparser.lexer.Page; import org.htmlparser.scanners.CompositeTagScanner; import org.htmlparser.tags.CompositeTag; import org.htmlparser.tags.Tag; import org.htmlparser.tests.ParserTestCase; + import org.htmlparser.util.NodeList; import org.htmlparser.util.ParserException; *************** *** 53,57 **** scanner = new CompositeTagScanner(arr) { ! public Tag createTag(TagData tagData, CompositeTagData compositeTagData) throws ParserException { return null; } --- 54,59 ---- scanner = new CompositeTagScanner(arr) { ! public Tag createTag(Page page, int start, int end, Vector attributes, Tag startTag, Tag endTag, NodeList children) throws ParserException ! { return null; } *************** *** 79,84 **** assertEquals("starting loc",0,customTag.getStartTag().elementBegin()); assertEquals("ending loc",9,customTag.getStartTag().elementEnd()); ! assertEquals("starting line position",0,customTag.tagData.getStartLine()); ! assertEquals("ending line position",0,customTag.tagData.getEndLine()); assertStringEquals("html",html,customTag.toHtml()); } --- 81,86 ---- assertEquals("starting loc",0,customTag.getStartTag().elementBegin()); assertEquals("ending loc",9,customTag.getStartTag().elementEnd()); ! // assertEquals("starting line position",0,customTag.tagData.getStartLine()); ! // assertEquals("ending line position",0,customTag.tagData.getEndLine()); assertStringEquals("html",html,customTag.toHtml()); } *************** *** 92,97 **** assertEquals("starting loc",0,customTag.getStartTag().elementBegin()); assertEquals("ending loc",8,customTag.getStartTag().elementEnd()); ! assertEquals("starting line position",0,customTag.tagData.getStartLine()); ! assertEquals("ending line position",0,customTag.tagData.getEndLine()); assertEquals("html",html,customTag.toHtml()); } --- 94,99 ---- assertEquals("starting loc",0,customTag.getStartTag().elementBegin()); assertEquals("ending loc",8,customTag.getStartTag().elementEnd()); ! // assertEquals("starting line position",0,customTag.tagData.getStartLine()); ! // assertEquals("ending line position",0,customTag.tagData.getEndLine()); assertEquals("html",html,customTag.toHtml()); } *************** *** 108,113 **** assertEquals("starting loc",0,customTag.getStartTag().elementBegin()); assertEquals("ending loc",8,customTag.getStartTag().elementEnd()); ! assertEquals("starting line position",0,customTag.tagData.getStartLine()); ! assertEquals("ending line position",0,customTag.tagData.getEndLine()); Node child = customTag.childAt(0); --- 110,115 ---- assertEquals("starting loc",0,customTag.getStartTag().elementBegin()); assertEquals("ending loc",8,customTag.getStartTag().elementEnd()); ! // assertEquals("starting line position",0,customTag.tagData.getStartLine()); ! // assertEquals("ending line position",0,customTag.tagData.getEndLine()); Node child = customTag.childAt(0); *************** *** 258,263 **** assertEquals("starting loc",0,customTag.getStartTag().elementBegin()); assertEquals("ending loc",8,customTag.getStartTag().elementEnd()); ! assertEquals("starting line position",0,customTag.tagData.getStartLine()); ! assertEquals("ending line position",0,customTag.tagData.getEndLine()); assertStringEquals("html",html + "</custom>",customTag.toHtml()); } --- 260,265 ---- assertEquals("starting loc",0,customTag.getStartTag().elementBegin()); assertEquals("ending loc",8,customTag.getStartTag().elementEnd()); ! // assertEquals("starting line position",0,customTag.tagData.getStartLine()); ! // assertEquals("ending line position",0,customTag.tagData.getEndLine()); assertStringEquals("html",html + "</custom>",customTag.toHtml()); } *************** *** 271,276 **** assertEquals("starting loc",0,customTag.getStartTag().elementBegin()); assertEquals("ending loc",8,customTag.getStartTag().elementEnd()); ! assertEquals("starting line position",0,customTag.tagData.getStartLine()); ! assertEquals("ending line position",0,customTag.tagData.getEndLine()); assertStringEquals("html",html + "</custom>",customTag.toHtml()); } --- 273,278 ---- assertEquals("starting loc",0,customTag.getStartTag().elementBegin()); assertEquals("ending loc",8,customTag.getStartTag().elementEnd()); ! // assertEquals("starting line position",0,customTag.tagData.getStartLine()); ! // assertEquals("ending line position",0,customTag.tagData.getEndLine()); assertStringEquals("html",html + "</custom>",customTag.toHtml()); } *************** *** 284,289 **** assertEquals("starting loc",0,customTag.getStartTag().elementBegin()); assertEquals("ending loc",8,customTag.getStartTag().elementEnd()); ! assertEquals("starting line position",0,customTag.tagData.getStartLine()); ! assertEquals("ending line position",1,customTag.tagData.getEndLine()); assertStringEquals("html", html + "</custom>", customTag.toHtml() ); --- 286,291 ---- assertEquals("starting loc",0,customTag.getStartTag().elementBegin()); assertEquals("ending loc",8,customTag.getStartTag().elementEnd()); ! // assertEquals("starting line position",0,customTag.tagData.getStartLine()); ! // assertEquals("ending line position",1,customTag.tagData.getEndLine()); assertStringEquals("html", html + "</custom>", customTag.toHtml() ); *************** *** 302,307 **** assertEquals("ending loc",8,customTag.getStartTag().elementEnd()); assertEquals("ending loc of custom tag",17,customTag.elementEnd()); ! assertEquals("starting line position",0,customTag.tagData.getStartLine()); ! assertEquals("ending line position",0,customTag.tagData.getEndLine()); assertStringEquals("1st custom tag", tag1 + "</custom>", customTag.toHtml()); customTag = (CustomTag)node[1]; --- 304,309 ---- assertEquals("ending loc",8,customTag.getStartTag().elementEnd()); assertEquals("ending loc of custom tag",17,customTag.elementEnd()); ! // assertEquals("starting line position",0,customTag.tagData.getStartLine()); ! // assertEquals("ending line position",0,customTag.tagData.getEndLine()); assertStringEquals("1st custom tag", tag1 + "</custom>", customTag.toHtml()); customTag = (CustomTag)node[1]; *************** *** 327,332 **** assertEquals("starting loc",9,customTag.getStartTag().elementBegin()); assertEquals("ending loc",17,customTag.getStartTag().elementEnd()); ! assertEquals("starting line position",0,customTag.tagData.getStartLine()); ! assertEquals("ending line position",1,customTag.tagData.getEndLine()); assertStringEquals("another tag html",another,anotherTag.toHtml()); assertStringEquals("custom tag html",custom,customTag.toHtml()); --- 329,334 ---- assertEquals("starting loc",9,customTag.getStartTag().elementBegin()); assertEquals("ending loc",17,customTag.getStartTag().elementEnd()); ! // assertEquals("starting line position",0,customTag.tagData.getStartLine()); ! // assertEquals("ending line position",1,customTag.tagData.getEndLine()); assertStringEquals("another tag html",another,anotherTag.toHtml()); assertStringEquals("custom tag html",custom,customTag.toHtml()); *************** *** 347,352 **** AnotherTag anotherTag = (AnotherTag)customTag.childAt(0); assertEquals("another tag ending loc",17,anotherTag.elementEnd()); ! assertEquals("starting line position",0,customTag.tagData.getStartLine()); ! assertEquals("ending line position",0,customTag.tagData.getEndLine()); assertStringEquals("html","<custom><another></another></custom>",customTag.toHtml()); } --- 349,354 ---- AnotherTag anotherTag = (AnotherTag)customTag.childAt(0); assertEquals("another tag ending loc",17,anotherTag.elementEnd()); ! // assertEquals("starting line position",0,customTag.tagData.getStartLine()); ! // assertEquals("ending line position",0,customTag.tagData.getEndLine()); assertStringEquals("html","<custom><another></another></custom>",customTag.toHtml()); } *************** *** 367,372 **** assertEquals("starting loc",0,customTag.getStartTag().elementBegin()); assertEquals("ending loc",8,customTag.getStartTag().elementEnd()); ! assertEquals("starting line position",0,customTag.tagData.getStartLine()); ! assertEquals("ending line position",0,customTag.tagData.getEndLine()); AnotherTag anotherTag = (AnotherTag)customTag.childAt(0); assertEquals("anotherTag child count",1,anotherTag.getChildCount()); --- 369,374 ---- assertEquals("starting loc",0,customTag.getStartTag().elementBegin()); assertEquals("ending loc",8,customTag.getStartTag().elementEnd()); ! // assertEquals("starting line position",0,customTag.tagData.getStartLine()); ! // assertEquals("ending line position",0,customTag.tagData.getEndLine()); AnotherTag anotherTag = (AnotherTag)customTag.childAt(0); assertEquals("anotherTag child count",1,anotherTag.getChildCount()); *************** *** 494,506 **** parser.addScanner(new CustomScanner() { ! public Tag createTag( ! TagData tagData, ! CompositeTagData compositeTagData) { ! url = tagData.getUrlBeingParsed(); ! return super.createTag( ! tagData, ! compositeTagData ! ); ! } }); parseAndAssertNodeCount(1); --- 496,513 ---- parser.addScanner(new CustomScanner() { ! public Tag createTag(Page page, int start, int end, Vector attributes, Tag startTag, Tag endTag, NodeList children) throws ParserException ! { ! url = page.getUrl (); ! return (super.createTag (page, start, end, attributes, startTag, endTag, children)); ! } ! // public Tag createTag( ! // TagData tagData, ! // CompositeTagData compositeTagData) { ! // url = tagData.getUrlBeingParsed(); ! // return super.createTag( ! // tagData, ! // compositeTagData ! // ); ! // } }); parseAndAssertNodeCount(1); *************** *** 564,569 **** } ! public Tag createTag(TagData tagData, CompositeTagData compositeTagData) { ! return new CustomTag(tagData, compositeTagData); } } --- 571,588 ---- } ! public Tag createTag(Page page, int start, int end, Vector attributes, Tag startTag, Tag endTag, NodeList children) throws ParserException ! { ! CustomTag ret; ! ! ret = new CustomTag (); ! ret.setPage (page); ! ret.setStartPosition (start); ! ret.setEndPosition (end); ! ret.setAttributesEx (attributes); ! ret.setStartTag (startTag); ! ret.setEndTag (endTag); ! ret.setChildren (children); ! ! return (ret); } } *************** *** 583,588 **** } ! public Tag createTag(TagData tagData, CompositeTagData compositeTagData) { ! return new AnotherTag(tagData, compositeTagData); } protected boolean isBrokenTag() { --- 602,619 ---- } ! public Tag createTag(Page page, int start, int end, Vector attributes, Tag startTag, Tag endTag, NodeList children) throws ParserException ! { ! AnotherTag ret; ! ! ret = new AnotherTag (); ! ret.setPage (page); ! ret.setStartPosition (start); ! ret.setEndPosition (end); ! ret.setAttributesEx (attributes); ! ret.setStartTag (startTag); ! ret.setEndTag (endTag); ! ret.setChildren (children); ! ! return (ret); } protected boolean isBrokenTag() { *************** *** 593,606 **** public static class CustomTag extends CompositeTag { ! public TagData tagData; ! public CustomTag(TagData tagData, CompositeTagData compositeTagData) { ! super(tagData,compositeTagData); ! this.tagData = tagData; } } public static class AnotherTag extends CompositeTag { ! public AnotherTag(TagData tagData, CompositeTagData compositeTagData) { ! super(tagData,compositeTagData); } } --- 624,637 ---- public static class CustomTag extends CompositeTag { ! // public TagData tagData; ! public CustomTag(/*TagData data, CompositeTagData compositeTagData*/) { ! // super(data.getPage (), data.getTagBegin (), data.getTagEnd (), data.getAttributes (),compositeTagData); ! // tagData = data; } } public static class AnotherTag extends CompositeTag { ! public AnotherTag(/*TagData data, CompositeTagData compositeTagData*/) { ! // super(data.getPage (), data.getTagBegin (), data.getTagEnd (), data.getAttributes (),compositeTagData); } } Index: ImageScannerTest.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/scannersTests/ImageScannerTest.java,v retrieving revision 1.33 retrieving revision 1.34 diff -C2 -d -r1.33 -r1.34 *** ImageScannerTest.java 5 Oct 2003 13:49:54 -0000 1.33 --- ImageScannerTest.java 20 Oct 2003 01:28:04 -0000 1.34 *************** *** 38,42 **** import org.htmlparser.tags.TableRow; import org.htmlparser.tags.Tag; - import org.htmlparser.tags.data.TagData; import org.htmlparser.tests.ParserTestCase; import org.htmlparser.util.LinkProcessor; --- 38,41 ---- Index: LinkScannerTest.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/scannersTests/LinkScannerTest.java,v retrieving revision 1.41 retrieving revision 1.42 diff -C2 -d -r1.41 -r1.42 *** LinkScannerTest.java 18 Oct 2003 20:50:37 -0000 1.41 --- LinkScannerTest.java 20 Oct 2003 01:28:04 -0000 1.42 *************** *** 40,44 **** import org.htmlparser.tags.LinkTag; import org.htmlparser.tags.Tag; - import org.htmlparser.tags.data.TagData; import org.htmlparser.tests.ParserTestCase; import org.htmlparser.util.ParserException; --- 40,43 ---- *************** *** 157,174 **** } ! /** ! * This is the reproduction of a bug which causes a null pointer exception ! */ ! public void testExtractLinkInvertedCommasBug() throws ParserException ! { ! String link = "r/anorth/top.html"; ! Vector attributes = new Vector (); ! attributes.addElement (new Attribute ("A", null)); ! attributes.addElement (new Attribute ("HREF", link)); ! Tag tag = new Tag(null, 0, 0, attributes); ! String url = "c:\\cvs\\html\\binaries\\yahoo.htm"; ! LinkScanner scanner = new LinkScanner(); ! assertEquals("Extracted Link","r/anorth/top.html",scanner.extractLink(tag,url)); ! } /** --- 156,173 ---- } ! // /** ! // * This is the reproduction of a bug which causes a null pointer exception ! // */ ! // public void testExtractLinkInvertedCommasBug() throws ParserException ! // { ! // String link = "r/anorth/top.html"; ! // Vector attributes = new Vector (); ! // attributes.addElement (new Attribute ("A", null)); ! // attributes.addElement (new Attribute ("HREF", link)); ! // Tag tag = new Tag(null, 0, 0, attributes); ! // String url = "c:\\cvs\\html\\binaries\\yahoo.htm"; ! // LinkScanner scanner = new LinkScanner(); ! // assertEquals("Extracted Link","r/anorth/top.html",scanner.extractLink(tag,url)); ! // } /** Index: TableScannerTest.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/scannersTests/TableScannerTest.java,v retrieving revision 1.36 retrieving revision 1.37 diff -C2 -d -r1.36 -r1.37 *** TableScannerTest.java 6 Oct 2003 01:43:28 -0000 1.36 --- TableScannerTest.java 20 Oct 2003 01:28:04 -0000 1.37 *************** *** 104,108 **** assertEquals("columns",1,tr.getColumnCount()); TableColumn td = tr.getColumns()[0]; ! Node node = td.childAt(0); assertType("node",TableTag.class,node); TableTag table2 = (TableTag)node; --- 104,108 ---- assertEquals("columns",1,tr.getColumnCount()); TableColumn td = tr.getColumns()[0]; ! Node node = td.childAt(1); assertType("node",TableTag.class,node); TableTag table2 = (TableTag)node; Index: TagScannerTest.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/scannersTests/TagScannerTest.java,v retrieving revision 1.31 retrieving revision 1.32 diff -C2 -d -r1.31 -r1.32 *** TagScannerTest.java 5 Oct 2003 13:49:54 -0000 1.31 --- TagScannerTest.java 20 Oct 2003 01:28:04 -0000 1.32 *************** *** 29,38 **** package org.htmlparser.tests.scannersTests; import org.htmlparser.Node; import org.htmlparser.Parser; import org.htmlparser.lexer.Lexer; import org.htmlparser.scanners.TagScanner; import org.htmlparser.tags.Tag; - import org.htmlparser.tags.data.TagData; import org.htmlparser.tests.ParserTestCase; import org.htmlparser.util.NodeIterator; --- 29,40 ---- package org.htmlparser.tests.scannersTests; + + import java.util.Vector; import org.htmlparser.Node; import org.htmlparser.Parser; import org.htmlparser.lexer.Lexer; + import org.htmlparser.lexer.Page; import org.htmlparser.scanners.TagScanner; import org.htmlparser.tags.Tag; import org.htmlparser.tests.ParserTestCase; import org.htmlparser.util.NodeIterator; *************** *** 121,125 **** public boolean evaluate(String s,TagScanner previousOpenScanner) { return false; } public String [] getID() { return null; } ! protected Tag createTag(TagData tagData, Tag tag, String url) { return null; } }; String result = scanner.removeChars(test,"\r\n"); --- 123,127 ---- public boolean evaluate(String s,TagScanner previousOpenScanner) { return false; } public String [] getID() { return null; } ! protected Tag createTag (Page page, int start, int end, Vector attributes, Tag tag, String url) { return null; } }; String result = scanner.removeChars(test,"\r\n"); |