KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > htmlparser > tests > tagTests > EndTagTest


1 // HTMLParser Library $Name: v1_5_20050313 $ - A java-based parser for HTML
2
// http://sourceforge.org/projects/htmlparser
3
// Copyright (C) 2004 Somik Raha
4
//
5
// Revision Control Information
6
//
7
// $Source: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/tagTests/EndTagTest.java,v $
8
// $Author: derrickoswald $
9
// $Date: 2004/07/02 00:49:31 $
10
// $Revision: 1.39 $
11
//
12
// This library is free software; you can redistribute it and/or
13
// modify it under the terms of the GNU Lesser General Public
14
// License as published by the Free Software Foundation; either
15
// version 2.1 of the License, or (at your option) any later version.
16
//
17
// This library is distributed in the hope that it will be useful,
18
// but WITHOUT ANY WARRANTY; without even the implied warranty of
19
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20
// Lesser General Public License for more details.
21
//
22
// You should have received a copy of the GNU Lesser General Public
23
// License along with this library; if not, write to the Free Software
24
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
//
26

27 package org.htmlparser.tests.tagTests;
28
29 import org.htmlparser.PrototypicalNodeFactory;
30 import org.htmlparser.Tag;
31 import org.htmlparser.tests.ParserTestCase;
32 import org.htmlparser.util.ParserException;
33
34 public class EndTagTest extends ParserTestCase {
35
36     static
37     {
38         System.setProperty ("org.htmlparser.tests.tagTests.EndTagTest", "EndTagTest");
39     }
40
41     public EndTagTest(String JavaDoc name) {
42         super(name);
43     }
44
45     public void testToHTML() throws ParserException {
46         createParser("<HTML></HTML>");
47         parser.setNodeFactory (new PrototypicalNodeFactory (true));
48         parseAndAssertNodeCount(2);
49         // The node should be a tag
50
assertTrue("Node should be a Tag",node[1] instanceof Tag);
51         Tag endTag = (Tag)node[1];
52         assertTrue("Node should be an end Tag",endTag.isEndTag ());
53         assertEquals("Raw String","</HTML>",endTag.toHtml());
54     }
55
56     public void testEndTagFind() throws ParserException {
57         String JavaDoc testHtml =
58             "<SCRIPT>document.write(d+\".com\")</SCRIPT><BR>";
59         createParser(testHtml);
60         parser.setNodeFactory (new PrototypicalNodeFactory (true));
61         int pos = testHtml.indexOf("</SCRIPT>");
62         parseAndAssertNodeCount(4);
63         assertTrue("Node should be a Tag",node[2] instanceof Tag);
64         Tag endTag = (Tag)node[2];
65         assertTrue("Node should be an end Tag",endTag.isEndTag ());
66         assertEquals("endtag element begin",pos,endTag.getStartPosition ());
67         assertEquals("endtag element end",pos+9,endTag.getEndPosition ());
68     }
69 }
70
Popular Tags