1 19 20 33 package org.htmlparser.tests.scannersTests; 34 35 import org.htmlparser.scanners.DivScanner; 36 import org.htmlparser.scanners.InputTagScanner; 37 import org.htmlparser.scanners.TableScanner; 38 import org.htmlparser.tags.Div; 39 import org.htmlparser.tags.InputTag; 40 import org.htmlparser.tags.TableTag; 41 import org.htmlparser.tests.ParserTestCase; 42 import org.htmlparser.util.ParserException; 43 44 public class DivScannerTest extends ParserTestCase 45 { 46 47 public DivScannerTest(String name) 48 { 49 super(name); 50 } 51 52 public void testScan() throws ParserException 53 { 54 createParser("<table><div align=\"left\">some text</div></table>"); 55 parser.registerScanners(); 56 parser.addScanner(new TableScanner(parser)); 57 parser.addScanner(new DivScanner()); 58 parseAndAssertNodeCount(1); 59 assertType("node should be table", TableTag.class, node[0]); 60 TableTag tableTag = (TableTag) node[0]; 61 Div div = (Div) tableTag.searchFor(Div.class).toNodeArray()[0]; 62 assertEquals("div contents", "some text", div.toPlainTextString()); 63 } 64 65 68 public void testInputInDiv() throws ParserException 69 { 70 createParser("<div><INPUT type=\"text\" name=\"X\">Hello</INPUT></div>"); 71 parser.addScanner(new DivScanner()); 72 parser.addScanner(new InputTagScanner()); 73 parseAndAssertNodeCount(1); 74 assertType("node should be div", Div.class, node[0]); 75 Div div = (Div) node[0]; 76 assertType("child not input", InputTag.class, div.getChild(0)); 77 } 78 } 79 | Popular Tags |