1 27 package org.htmlparser.tests; 28 29 import java.util.Arrays ; 30 31 import junit.framework.TestSuite; 32 33 import org.htmlparser.PrototypicalNodeFactory; 34 import org.htmlparser.tests.scannersTests.CompositeTagScannerTest.CustomTag; 35 import org.htmlparser.util.ParserException; 36 37 43 public class LineNumberAssignedByNodeReaderTest extends ParserTestCase { 44 45 static 46 { 47 System.setProperty ("org.htmlparser.tests.LineNumberAssignedByNodeReaderTest", "LineNumberAssignedByNodeReaderTest"); 48 } 49 50 public LineNumberAssignedByNodeReaderTest(String name) { 51 super(name); 52 } 53 54 60 public void testLineNumbers1() throws ParserException 61 { 62 testLineNumber("<Custom/>", 1, 0, 0, 0); 63 } 64 65 public void testLineNumbers2() throws ParserException 66 { 67 testLineNumber("<Custom />", 1, 0, 0, 0); 68 } 69 70 public void testLineNumbers3() throws ParserException 71 { 72 testLineNumber("<Custom></Custom>", 1, 0, 0, 0); 73 } 74 75 public void testLineNumbers4() throws ParserException 76 { 77 testLineNumber("<Custom>Content</Custom>", 1, 0, 0, 0); 78 } 79 80 public void testLineNumbers5() throws ParserException 81 { 82 testLineNumber("<Custom>Content<Custom></Custom>", 1, 0, 0, 0); 83 } 84 85 public void testLineNumbers6() throws ParserException 86 { 87 testLineNumber( 88 "<Custom>\n" + 89 " Content\n" + 90 "</Custom>", 91 1, 0, 0, 2 92 ); 93 } 94 95 public void testLineNumbers7() throws ParserException 96 { 97 testLineNumber( 98 "Foo\n" + 99 "<Custom>\n" + 100 " Content\n" + 101 "</Custom>", 102 2, 1, 1, 3 103 ); 104 } 105 106 public void testLineNumbers8() throws ParserException 107 { 108 testLineNumber( 109 "Foo\n" + 110 "<Custom>\n" + 111 " <Custom>SubContent</Custom>\n" + 112 "</Custom>", 113 2, 1, 1, 3 114 ); 115 } 116 117 public void testLineNumbers9() throws ParserException 118 { 119 char[] oneHundredNewLines = new char[100]; 120 Arrays.fill(oneHundredNewLines, '\n'); 121 testLineNumber( 122 "Foo\n" + 123 new String (oneHundredNewLines) + 124 "<Custom>\n" + 125 " <Custom>SubContent</Custom>\n" + 126 "</Custom>", 127 2, 1, 101, 103 128 ); 129 } 130 131 142 private void testLineNumber(String xml, int numNodes, int useNode, int expectedStartLine, int expectedEndLine) throws ParserException { 143 createParser(xml); 144 parser.setNodeFactory (new PrototypicalNodeFactory (new CustomTag ())); 145 parseAndAssertNodeCount(numNodes); 146 assertType("custom node",CustomTag.class,node[useNode]); 147 CustomTag tag = (CustomTag)node[useNode]; 148 assertEquals("start line", expectedStartLine, tag.getStartingLineNumber ()); 149 assertEquals("end line", expectedEndLine, tag.getEndTag ().getEndingLineNumber ()); 150 } 151 152 public static TestSuite suite() { 153 TestSuite suite = new TestSuite("Line Number Tests"); 154 suite.addTestSuite(LineNumberAssignedByNodeReaderTest.class); 155 return (suite); 156 } 157 } 158 | Popular Tags |