-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathtest_html.py
More file actions
274 lines (248 loc) · 10.3 KB
/
test_html.py
File metadata and controls
274 lines (248 loc) · 10.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
#!/usr/bin/env python
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License
# Version 1.1 (the "License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS"
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
# License for the specific language governing rights and limitations
# under the License.
#
# The Original Code is Komodo code.
#
# The Initial Developer of the Original Code is ActiveState Software Inc.
# Portions created by ActiveState Software Inc are Copyright (C) 2000-2007
# ActiveState Software Inc. All Rights Reserved.
#
# Contributor(s):
# ActiveState Software Inc
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
"""Test HTML codeintel support."""
from __future__ import absolute_import
import os
import sys
import re
from os.path import join, dirname, abspath, exists, basename
from glob import glob
from pprint import pprint, pformat
import unittest
import logging
from codeintel2.common import *
from codeintel2.environment import SimplePrefsEnvironment
from codeintel2.util import indent, dedent, banner, markup_text, unmark_text
from testlib import TestError, TestSkipped, TestFailed, tag
from citestsupport import CodeIntelTestCase, override_encoding
log = logging.getLogger("test")
class HTMLTestCase(CodeIntelTestCase):
lang = "HTML"
_ci_env_prefs_ = {
"defaultHTMLDecl": "-//W3C//DTD HTML 4.01//EN",
}
def _test_xhtml_completions_base_test(self, raw_content, expected):
xhmltdoctypes = [
# XHTML 1.0 Strict
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"\n "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">',
# XHTML 1.0 Transitional
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"\n "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">',
# XHTML 1.0 Frameset
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"\n "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">',
]
for doctype in xhmltdoctypes:
content = raw_content % doctype
self.assertCompletionsInclude(content,expected)
def _test_html_completions_base_test(self, raw_content, expected):
htmldoctypes = [
# HTML 4.01 Strict
'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"\n "http://www.w3.org/TR/html4/strict.dtd">',
# HTML 4.01 Transitional
'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"\n "http://www.w3.org/TR/html4/loose.dtd">',
'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">',
# XXX the following DTD parsing fails. frameset does not include
# the tags our tests are running against, and 3.2/2.0 dtd is broken
# HTML 4.01 Frameset
#'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"\n "http://www.w3.org/TR/html4/frameset.dtd">',
#'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN">',
# HTML 3.2
#'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">',
# HTML 2.0
#'<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">',
# No doctype
'',
]
for doctype in htmldoctypes:
content = raw_content % doctype
self.assertCompletionsInclude(content,expected)
def test_completions_in_head(self):
raw_content = dedent("""\
%s
<html>
<head>
<title>my title</title>
<<|>
</head>
<body>
</body>
</html>
""")
self._test_xhtml_completions_base_test(
raw_content, [("element", "style")])
self._test_html_completions_base_test(
raw_content, [("element", "style")])
def test_completions_in_head_bug64997(self):
raw_content = dedent("""\
%s
<html>
<head>
<<|>
""")
self._test_xhtml_completions_base_test(
raw_content, [("element", "style")])
self._test_html_completions_base_test(
raw_content, [("element", "style")])
def test_should_be_input_inside_form(self):
# though common use is for input to be anywhere, it *is not valid*
# html as defined by w3c, thus the div tag
content = dedent("""\
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head> <title>my title</title> </head>
<body>
<form action="form_action.asp" method="get"><div>
First name:
<<|>
</div></form>
</body>
</html>
""")
self.assertCompletionsInclude(content,
[("element", "input")])
def test_do_not_close_html_img(self):
# Raised by Alex Fernandez on komodo-beta about k4b1.
html_content = dedent("""\
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head> <title>my title</title> </head>
<body>
<p>blah blah...
<img src="somefile.jpg" alt="blah">
</<|>p>
</body>
</html>
""")
self.assertCompletionsDoNotInclude(html_content, [("element", "img>")])
# invalid XHTML usage, without the xml declaration, it is treated like
# html from a parser point of view, so close tags are handled differently
html_content = dedent("""\
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head> <title>my title</title> </head>
<body>
<p>blah blah...
<img src="somefile.jpg" alt="blah">
</<|>
""")
self.assertCompletionsDoNotInclude(html_content, [("element", "img>")])
def test_close_xhtml_img(self):
xhtml_content = dedent("""<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head> <title>my title</title> </head>
<body>
<p>blah blah...
<img src="somefile.jpg" alt="blah">
</<|>img>
</p>
</body>
</html>
""")
self.assertCompletionsAre(xhtml_content,
[("element", "img>")])
@tag("bug66149")
def test_attr_enum_cpln(self):
self.assertCompletionsAre(
dedent("""
<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html dir="<|>>
</html>
"""),
[("attribute_value", 'ltr'), ("attribute_value", 'rtl')])
self.assertCompletionsAre(
dedent("""
<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html dir='<|>>
</html>
"""),
[("attribute_value", "ltr"), ("attribute_value", "rtl")])
@tag("bug99976")
def test_completions_invalid_html(self):
self.assertCompletionsInclude(
dedent("""
<html>
</foo>
<<|>
</html>
"""),
[("element", 'p'), ("element", 'div')])
@tag("bug100250")
def test_completions_dtd(self):
sample = dedent("""
<html>
<body>
<<|>
</body>
</html>""")
env = SimplePrefsEnvironment()
buf, data = self._get_buf_and_data(sample, self.lang, env=env)
# Test HTML4...
env.set_pref("defaultHTMLDecl", "-//W3C//DTD HTML 4.01//EN")
self.assertCompletionsInclude2(buf, data["pos"], [("element", "script")], unload=False)
self.assertCompletionsDoNotInclude2(buf, data["pos"], [("element", "section")], unload=False)
# Flip to HTML5...
env.set_pref("defaultHTMLDecl", "-//W3C//DTD HTML 5//EN")
self.assertCompletionsInclude2(buf, data["pos"], [("element", "script")], unload=False)
self.assertCompletionsInclude2(buf, data["pos"], [("element", "section")], unload=False)
# And back to HTML4 again
env.set_pref("defaultHTMLDecl", "-//W3C//DTD HTML 4.01//EN")
self.assertCompletionsInclude2(buf, data["pos"], [("element", "script")], unload=False)
self.assertCompletionsDoNotInclude2(buf, data["pos"], [("element", "section")], unload=False)
@tag("bug100557")
@override_encoding("ascii")
def test_unicode(self):
self.assertCompletionsInclude(
dedent(u"""
<!DOCTYPE html>
<html>
<body>
<a title="\u2603">
\u2603\u2603\u2603
</a>
<<|>
</body>
</html>
"""),
[("element", "p")])