1 19 20 33 package org.htmlparser.tests.scannersTests; 34 35 import junit.framework.TestSuite; 36 import org.htmlparser.scanners.*; 37 import org.htmlparser.tags.*; 38 import org.htmlparser.tests.ParserTestCase; 39 import org.htmlparser.util.ParserException; 40 41 public class HeadScannerTest extends ParserTestCase 42 { 43 44 public HeadScannerTest(String name) 45 { 46 super(name); 47 } 48 49 public void testSimpleHead() throws ParserException 50 { 51 createParser("<HTML><HEAD></HEAD></HTML>"); 52 HeadScanner headScanner = new HeadScanner(); 53 parser.registerDomScanners(); 54 parseAndAssertNodeCount(1); 55 assertTrue(node[0] instanceof Html); 56 Html htmlTag = (Html) node[0]; 57 assertTrue(htmlTag.getChild(0) instanceof HeadTag); 58 } 59 60 public void testSimpleHeadWithoutEndTag() throws ParserException 61 { 62 createParser("<HTML><HEAD></HTML>"); 63 HeadScanner headScanner = new HeadScanner(); 64 parser.registerDomScanners(); 65 parseAndAssertNodeCount(1); 66 assertTrue(node[0] instanceof Html); 67 Html htmlTag = (Html) node[0]; 68 assertTrue(htmlTag.getChild(0) instanceof HeadTag); 69 HeadTag headTag = (HeadTag) htmlTag.getChild(0); 70 assertEquals("toHtml()", "<HEAD></HEAD>", headTag.toHtml()); 71 assertEquals( 72 "toHtml()", 73 "<HTML><HEAD></HEAD></HTML>", 74 htmlTag.toHtml()); 75 } 76 77 public void testSimpleHeadWithBody() throws ParserException 78 { 79 createParser("<HTML><HEAD><BODY></HTML>"); 80 HeadScanner headScanner = new HeadScanner(); 81 parser.registerDomScanners(); 82 parseAndAssertNodeCount(1); 83 assertTrue(node[0] instanceof Html); 84 Html htmlTag = (Html) node[0]; 85 assertTrue(htmlTag.getChild(0) instanceof HeadTag); 86 HeadTag headTag = (HeadTag) htmlTag.getChild(0); 88 assertEquals("toHtml()", "<HEAD></HEAD>", headTag.toHtml()); 89 assertEquals( 90 "toHtml()", 91 "<HTML><HEAD></HEAD><BODY></BODY></HTML>", 92 htmlTag.toHtml()); 93 } 94 95 public static TestSuite suite() 96 { 97 return new TestSuite(HeadScannerTest.class); 98 } 99 100 public static void main(String [] args) 101 { 102 new junit.awtui.TestRunner().start( 103 new String [] { HeadScannerTest.class.getName()}); 104 } 105 106 } 107 | Popular Tags |