-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathtest_rhtml.py
More file actions
285 lines (241 loc) · 11.2 KB
/
test_rhtml.py
File metadata and controls
285 lines (241 loc) · 11.2 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
275
276
277
278
279
280
281
282
283
#!/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 RHTML 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.util import indent, dedent, banner, markup_text, unmark_text
from testlib import TestError, TestSkipped, TestFailed, tag
from citestsupport import CodeIntelTestCase, writefile
log = logging.getLogger("test")
class LexRHTMLTestCase(CodeIntelTestCase):
lang = "RHTML"
def test_basic(self):
self.assertLex(dedent("""
<html><head><title>foo</title><head>
<body>
<SCE_UDL_TPL_OPERATOR><%</SCE_UDL_TPL_OPERATOR><SCE_UDL_SSL_COMMENTBLOCK># foo </SCE_UDL_SSL_COMMENTBLOCK><SCE_UDL_TPL_OPERATOR>%></SCE_UDL_TPL_OPERATOR>
<body></html>
"""))
# Access with command
# ci2 test udl RHTMLCpln
class RHTMLCplnTestCase(CodeIntelTestCase):
lang = "RHTML"
def test_pass(self):
self.assertEqual(1, 1)
class RHTMLCpln2TestCase(CodeIntelTestCase):
lang = "RHTML"
test_dir = join(os.getcwd(), "tmp")
# Some basic tests patterned on tests in test_ruby
@tag("knownfailure")
def test_citdl_expr_from_trg(self):
self.assertCITDLExprIs("<%= z.<|>", "z")
class RHTMLTestCase(CodeIntelTestCase):
lang = "RHTML"
test_dir = join(os.getcwd(), "tmp", "rhtml")
@tag("knownfailure")
def test_ruby_complete(self):
# Tests for Ruby mode in UDL files.
#
# These are copied and pasted out of the RubyTestCase class.
# I would have preferred to pull the functions out, add a prolog
# to each string argument to put the code into Ruby mode,
# but that doesn't seem easy to do in Python.
ruby1 = "<%= "
# New tests
rails_view_name = "ruby-complete-rails-view-methods"
object_methods_name = "ruby-complete-object-methods"
self.assertTriggerMatches(ruby1 + "opti", name=rails_view_name)
self.assertTriggerMatches(ruby1 + "opt", name=rails_view_name)
self.assertNoTrigger(ruby1 + "op")
self.assertNoTrigger(ruby1 + "o")
self.assertNoTrigger(ruby1 + " ")
self.assertNoTrigger(ruby1 + "\t")
self.assertNoTrigger(ruby1 + "\n")
self.assertNoTrigger(ruby1 + " opt")
self.assertTriggerMatches(ruby1 + "opt", name=rails_view_name)
self.assertTriggerMatches(ruby1 + "Time.", name=object_methods_name)
# Tests from existing items
calltip_sig_name = "ruby-complete-calltip-call-signature"
self.assertTriggerMatches(ruby1 + dedent("""\
b2 = String.new("testing")
b2.between?("""),
name=calltip_sig_name)
self.assertTriggerMatches(ruby1 + dedent("""\
require 'fileutils'
FileUtils::cd("""),
name=calltip_sig_name)
self.assertTriggerMatches(ruby1 + dedent("""\
require 'fileutils'
include FileUtils
cd("""),
name=calltip_sig_name)
self.assertNoTrigger(ruby1 + "print 'cd(") # string
self.assertNoTrigger(ruby1 + "# cd(") # comment
self.assertNoTrigger(ruby1 + "if(") # reserved word
self.assertNoTrigger(ruby1 + dedent("""\
require 'fileutils'
include FileUtils
cd (""")) #space
self.assertTriggerMatches(dedent("""<%\
require 'net/imap'
imap = Net::IMAP.new('example.com')
imap."""),
name=object_methods_name)
self.assertTriggerMatches(dedent("""<%\
class MyClass
def method1(arg1, rest)
end
def method2
end
end
myc = MyClass."""),
name=object_methods_name)
self.assertTriggerMatches(dedent("""<%\
class MyClass
def method1(arg1, rest)
end
def method2
end
end
myc = MyClass.new
myc."""),
name=object_methods_name)
module_methods_name = "ruby-complete-module-names"
self.assertTriggerMatches(dedent("""<%\
require 'fileutils'
FileUtils::"""),
name=module_methods_name)
self.assertTriggerMatches("<%= ActionView::Helpers::DateHelper::",
name=module_methods_name)
instance_vars_name = "ruby-complete-instance-vars"
class_vars_name = "ruby-complete-class-vars"
global_vars_name = "ruby-complete-global-vars"
self.assertTriggerMatches("<%= @", name=instance_vars_name)
self.assertTriggerMatches("<% if @", name=instance_vars_name)
self.assertTriggerMatches("<%= @@", name=class_vars_name)
self.assertTriggerMatches("<% if @@", name=class_vars_name)
self.assertTriggerMatches("<%= $", name=global_vars_name)
self.assertTriggerMatches("<% if $", name=global_vars_name)
# These aren't styled as variables
self.assertNoTrigger("<%# @")
self.assertNoTrigger("<%# @@")
self.assertNoTrigger("<%# $")
self.assertNoTrigger("<%= 'a string: @")
self.assertNoTrigger("<%= 'a string: @@")
self.assertNoTrigger("<%= \"a string: @")
self.assertNoTrigger("<%= \"a string: $")
def _setup_gansta_rhtml_buf(self):
gangsta_rhtml = join(self.test_dir, "gangsta.rhtml")
writefile(gangsta_rhtml, dedent("""
<html>
<head> <title>this RHTML file has JS and Ruby code</title>
<script type="application/x-javascript">
function yoyoyo(span) {
//...
}
</script>
</head>
<body>
<h1>Gansta Rap</h1>
<% def spitit
"word"
end %>
<ul> <li onclick="yoyoyo();"><%= spitit %></li> </ul>
</body>
</html>
"""))
gangsta_buf = self.mgr.buf_from_path(gangsta_rhtml, lang="RHTML")
return gangsta_buf
def test_multiple_blobs(self):
lang = "RHTML"
buf = self._setup_gansta_rhtml_buf()
rb_blob = buf.blob_from_lang["Ruby"]
self.failUnless(rb_blob is not None)
self.failUnless(rb_blob[0].get("name") == "spitit")
js_blob = buf.blob_from_lang["JavaScript"]
self.failUnless(js_blob is not None)
self.failUnless(js_blob[0].get("name") == "yoyoyo")
class Nothing:
def test_citdl_expr_from_trg(self):
test_cases = """
z.<|> z
send(<|> send
foo.instance_of?(<|> foo.instance_of?
File.open(<|> File.open
Zlib::Deflate.deflate(<|> Zlib::Deflate.deflate
# These trigger types are disabled until eval for them is
# implemented.
#@assigned.<|> @assigned
#@@foo.<|> @foo
#$blah.<|> @blah
# Skipping this one for now because we'd need to do the smarter
# convert-literals-to-class-instance thang first.
#0.step(<|> Numeric.step
@ingredients.<|> @ingredients
@ingredients.has_key?(<|> @ingredients.has_key?
# Literals
0.<|> Fixnum
3.14.<|> Float
1e-6.<|> Float
'...'.<|> String
"...".<|> String
''.<|> String
"".<|> String
[].<|> Array
{}.<|> Hash
0.step(<|> Fixnum.step
'...'.step(<|> String.step
[1,2,3].each(<|> Array.each
"""
for line in test_cases.splitlines(0):
if not line.strip(): continue
if line.lstrip().startswith("#"): continue
buffer, expected_citdl_expr = line.split()
buffer = "<%= " + buffer + "%>"
self.assertCITDLExprIs(buffer, expected_citdl_expr)
self.assertCITDLExprIs("<%= z = Zlib::Deflate.new()\nz.<|> %>", "z")
#---- mainline
if __name__ == "__main__":
unittest.main()