1 /* HTML_parsing.java --
2 Copyright (C) 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package test.gnu.javax.swing.text.html.parser;
43 * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
45 public class HTML_parsing
49 * This is used for profiling.
51 public static void main(String[] args)
53 long t = System.currentTimeMillis();
56 HTML_parsing p = new HTML_parsing();
57 for (int i = 0; i < 2000; i++)
61 System.out.print('.');
67 System.out.println("TIME " + (System.currentTimeMillis() - t));
70 public void testHTMLParsing()
73 Parser_Test v = new Parser_Test();
74 v.hideImplied = false;
76 // Test subsequent tags.
77 v.verify("<b><i><u>text</b><i></u>",
78 "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><b><i><u>'text'</b><i></u></i></i></body></html>"
82 v.verify("hex: U eqdec: = ampnamed: &",
83 "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'>'hex: U eqdec: = ampnamed: &'</body></html>"
87 v.verify("<html><head></head><body><!--a-->< !--b--><! --c--><!-- d--><!--e --><!--f-- ><!--g--><!---h---><!-- i --><!--- j ---><!-- -- --> <b> <!---------->",
88 "<html><head></head><body>{a}{b}{c}{ d}{e }{f}{g}{-h-}{ i }{- j -}{ -- }<b>{------}</b></body></html>"
91 // Test unclosed tags.
92 v.verify("<hr id = 1 class = c<hr id=2>",
93 "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><hr class='c' id='1'/><hr id='2'/></body></html>"
96 // Test errors and unclosed tags.
97 v.verify("<b#r><hr id = 1 # class = c<hr id=2>",
98 "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><b><hr id='1'/>'# class = c'<hr id='2'/></b></body></html>"
102 v.verify("<hr id=1><script a=b c=d><hr id=1></script><hr id=1>",
103 "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><hr id='1'/><script a='b' c='d'>'<hr id=1>'</script><hr id='1'/></body></html>"
106 // Test valid attributes.
107 v.verify("<hr id='i' title=\"tit\" class=cl><hr><hr id = 2>",
108 "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><hr class='cl' id='i' title='tit'/><hr/><hr id='2'/></body></html>"
111 // Test unknown attribute without value.
112 v.verify("<hr audrius title=\"tit\">",
113 "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><hr audrius='#DEFAULT' title='tit'/></body></html>"
116 // Test known attributes witout value.
117 v.verify("<option id=a selected><option id=b selected = selected class=cC><input checked>",
118 "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><option id='a' selected='selected'></option></body><body _implied_='true'><option class='cC' id='b' selected='selected'></option><input checked='checked'/></body></html>"
121 // Test table content model.
122 v.verify("<table>a</table>",
123 "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><table><tbody _implied_='true'><tr _implied_='true'><td _implied_='true'>'a'</td></tr></tbody></table></body></html>"
126 // Test table content model.
127 v.verify("<table><caption>cap</caption>a</table>",
128 "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><table><caption>'cap'</caption><tbody _implied_='true'><tr _implied_='true'><td _implied_='true'>'a'</td></tr></tbody></table></body></html>"
131 // Test typical table.
132 v.verify("<table><tr><td>x</td><td>y</td><td>z</td></table>",
133 "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><table><tbody _implied_='true'><tr><td>'x'</td><td>'y'</td><td>'z'</td></tr></tbody></table></body></html>"
136 // Test nested table.
137 v.verify("<table><tr><td><table>nested</table>x</td><td>y</td><td>z</td></table>",
138 "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><table><tbody _implied_='true'><tr><td><table><tbody _implied_='true'><tr _implied_='true'><td _implied_='true'>'nested'</td></tr></tbody></table>'x'</td><td>'y'</td><td>'z'</td></tr></tbody></table></body></html>"
141 // Test simple nested list.
142 v.verify("<ul><li>a</li><ul><li>na</li><li>nb</li></ul><li>b</li></ul>",
143 "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><ul><li>'a'</li><ul><li>'na'</li><li>'nb'</li></ul><li>'b'</li></ul></body></html>"
146 // Test simple non-nested list.
147 v.verify("<ul><li>a</li><li>na</li><li>nb</li><li>b</li></ul>",
148 "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><ul><li>'a'</li><li>'na'</li><li>'nb'</li><li>'b'</li></ul></body></html>"
151 // Test list without closing tags (obsolete list form).
152 v.verify("<ul><li>a<li>na<li>nb<li>b</ul>",
153 "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><ul><li>'a'</li><li>'na'</li><li>'nb'</li><li>'b'</li></ul></body></html>"
156 // Test list without closing tags (obsolete list form).
157 v.verify("<ul><li>a<ul><li>na<li>nb</ul><li>b</ul>",
158 "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><ul><li>'a'<ul><li>'na'</li><li>'nb'</li></ul></li><li>'b'</li></ul></body></html>"
161 // Test Obsolete table.
162 v.verify("<table><tr><td>a<td>b<td>c</tr>",
163 "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><table><tbody _implied_='true'><tr><td>'a'</td><td>'b'</td><td>'c'</td></tr></tbody></table></body></html>"
166 // Test html no head no body.
167 v.verify("<html>text</html>",
168 "<html><head _implied_='true'></head><body _implied_='true'>'text'</body></html>"
172 v.verify("<head></head>text",
173 "<html _implied_='true'><head></head><body _implied_='true'>'text'</body></html>"
176 // Test head and body.
177 v.verify("<head><title>ti</title></head><body>text",
178 "<html _implied_='true'><head><title>'ti'</title></head><body>'text'</body></html>"
181 // Test title and text.
182 v.verify("<title>title</title>text",
183 "<html _implied_='true'><head _implied_='true'><title>'title'</title></head><body _implied_='true'>'text'</body></html>"
187 v.verify("<html>text</html>",
188 "<html><head _implied_='true'></head><body _implied_='true'>'text'</body></html>"
192 v.verify("<body>text</body>",
193 "<html _implied_='true'><head _implied_='true'></head><body>'text'</body></html>"
197 v.verify("<head></head>text",
198 "<html _implied_='true'><head></head><body _implied_='true'>'text'</body></html>"
201 // Test obsolete table.
202 v.verify("<table><tr><td>a</td><tr><td>a</td>",
203 "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><table><tbody _implied_='true'><tr><td>'a'</td></tr><tr><td>'a'</td></tr></tbody></table></body></html>"
206 // Test obsolete table.
207 v.verify("<table><tr><td>a<td>b<tr><td>a<td>b<td>c",
208 "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><table><tbody _implied_='true'><tr><td>'a'</td><td>'b'</td></tr><tr><td>'a'</td><td>'b'</td><td>'c'</td></tr></tbody></table></body></html>"
212 v.verify("<html><head><style><hr id=2></style></head><hr id = b>",
213 "<html><head><style>'<hr id=2>'</style></head><body _implied_='true'><hr id='b'/></body></html>"
217 v.verify("<style><hr id=2></style>x",
218 "<html _implied_='true'><head _implied_='true'><style>'<hr id=2>'</style></head><body _implied_='true'>'x'</body></html>"
221 // Test entities in attributes.
222 v.verify("<hr id='id_AZ' class= \"Y_&\" >",
223 "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><hr class='Y_&' id='id_AZ'/></body></html>"
227 v.verify("<table><COLGROUP width=\"25\"><COL span=\"45\"><COL id=\"identifier\"></COLGROUP><td>a<td>b<tr>x",
228 "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><table><colgroup width='25'><col span='45'/><col id='identifier'/></colgroup><tbody _implied_='true'><tr _implied_='true'><td>'a'</td><td>'b'</td></tr><tr><td _implied_='true'>'x'</td></tr></tbody></table></body></html>"
231 // Test definition list, obsolete.
232 v.verify("<dl><dt>ha<dd>a<dt>hb<dd>b",
233 "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><dl><dt>'ha'</dt><dd>'a'</dd><dt>'hb'</dt><dd>'b'</dd></dl></body></html>"
236 // Test definition list.
237 v.verify("<html><head></head><body><dl><dt>'ha'</dt><dd>'a'</dd><dt>'hb'</dt><dd>'b'</dd></dl></body></html>",
238 "<html><head></head><body><dl><dt>''ha''</dt><dd>''a''</dd><dt>''hb''</dt><dd>''b''</dd></dl></body></html>"
242 v.verify("<p>b<p>c<p>d",
243 "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><p>'b'</p><p>'c'</p><p>'d'</p></body></html>"
247 v.verify("<p>'b'</p><p>'c'</p><p>'d'</p>",
248 "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><p>''b''</p><p>''c''</p><p>''d''</p></body></html>"
251 // Test select obsolete.
252 v.verify("<form><select><option value='hi' disabled>a<option selected>b<option>normal",
253 "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><form><select><option disabled='disabled' value='hi'>'a'</option><option selected='selected'>'b'</option><option>'normal'</option></select></form></body></html>"
256 // Test select current.
257 v.verify("<form><select><option>'a'</option><option SELECTED='selected'>'b'</option></select></form>",
258 "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><form><select><option>''a''</option><option selected='selected'>''b''</option></select></form></body></html>"
261 // Test select current.
262 v.verify("<form><select><option>after<optgroup><option>'a'</option><option SELECTED='selected'>'b'</option></optgroup></select></form>",
263 "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><form><select><option>'after'</option><optgroup><option>''a''</option><option selected='selected'>''b''</option></optgroup></select></form></body></html>"
268 "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'>'<'<i>'text'</i></body></html>"
271 // Test << antihang with spaces.
272 v.verify(" < < i>text",
273 "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'>'<'<i>'text'</i></body></html>"
276 // Test Standalone <.
277 v.verify("Text <wrong tag is it! <b> text ",
278 "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'>'Text''<wrong tag is it!'<b>'text'</b></body></html>"