-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
executable file
·243 lines (211 loc) · 8.21 KB
/
test.py
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
#!/usr/bin/env python3
import unittest
import _ctags_tester
CTAGS_CONF = 'ctags.conf'
class CoffeescriptTest(unittest.TestCase):
def ctags_tester(self, source_code):
return _ctags_tester.CTagsTester(self, '.coffee', CTAGS_CONF, source_code)
def test_class_method(self):
c = self.ctags_tester(' create: ->')
c.check(
expect_symbol='create',
expect_vim_search_cmd='/^ create: ->/;"',
expect_symbol_type='m')
def test_at_class_method(self):
c = self.ctags_tester(' @_setWorkspaceXml: (workspace, codeXml) ->')
c.check(
expect_symbol='_setWorkspaceXml',
expect_vim_search_cmd='/^ @_setWorkspaceXml: (workspace, codeXml) ->/;"',
expect_symbol_type='m')
def test_class_constructor(self):
c = self.ctags_tester('class stratego.CamperAppEditor extends phaser.State')
c.check(
expect_symbol='CamperAppEditor',
expect_vim_search_cmd='/^class stratego.CamperAppEditor extends phaser.State/;"',
expect_symbol_type='c')
def test_local_function(self):
c = self.ctags_tester('local_function = (gfx, focusObj) ->')
c.check(
expect_symbol='local_function',
expect_vim_search_cmd='/^local_function = (gfx, focusObj) ->/;"',
expect_symbol_type='f')
def test_global_function(self):
c = self.ctags_tester('window.global_function = (gfx, focusObj) ->')
c.check(
expect_symbol='global_function',
expect_vim_search_cmd='/^window.global_function = (gfx, focusObj) ->/;"',
expect_symbol_type='f')
def test_pkg_function(self):
c = self.ctags_tester('window.pkg.pkg_function = (gfx, focusObj) ->')
c.check(
expect_symbol='pkg_function',
expect_vim_search_cmd='/^window.pkg.pkg_function = (gfx, focusObj) ->/;"',
expect_symbol_type='f')
def test_module_function(self):
c = self.ctags_tester('module.module_function = (a, b) ->')
c.check(
expect_symbol='module_function',
expect_vim_search_cmd='/^module.module_function = (a, b) ->/;"',
expect_symbol_type='f')
def test_exports_function(self):
c = self.ctags_tester('exports.exports_function = (a, b) ->')
c.check(
expect_symbol='exports_function',
expect_vim_search_cmd='/^exports.exports_function = (a, b) ->/;"',
expect_symbol_type='f')
class JavascriptTest(unittest.TestCase):
def ctags_tester(self, source_code):
return _ctags_tester.CTagsTester(self, '.js', CTAGS_CONF, source_code)
def test_functions(self):
c = self.ctags_tester('''
function global_function(a, b){}
var object_class = {
constructor: function(){}
object_method: function(){}
}
var assigned_function = function(){}
Namespace.namespaced_func = function (game, x, y, key, frame) {}
''')
c.check(
expect_symbol='global_function',
expect_vim_search_cmd='/^function global_function(a, b){}$/;"',
expect_symbol_type='f')
c.check(
expect_symbol='object_method',
expect_vim_search_cmd='/^ object_method: function(){}$/;"',
expect_symbol_type='f')
c.check(
expect_symbol='assigned_function',
expect_vim_search_cmd='/^var assigned_function = function(){}$/;"',
expect_symbol_type='f')
c.check(
expect_symbol='namespaced_func',
expect_vim_search_cmd='/^Namespace.namespaced_func = function (game, x, y, key, frame) {}$/;"',
expect_symbol_type='f')
def test_var(self):
'''
Create tags for variables, arrays, and objects.
'''
c = self.ctags_tester('''
var myarray = [1, 2];
var myobject = {a: 1};
var myvar = 1;
var myfunc = function(){};
''')
c.check(
expect_symbol='myarray',
expect_vim_search_cmd='/^var myarray = [1, 2];$/;"',
expect_symbol_type='a')
c.check(
expect_symbol='myobject',
expect_vim_search_cmd='/^var myobject = {a: 1};$/;"',
expect_symbol_type='o')
c.check(
expect_symbol='myvar',
expect_vim_search_cmd='/^var myvar = 1;$/;"',
expect_symbol_type='r')
c.check(
expect_symbol='myfunc',
expect_vim_search_cmd='/^var myfunc = function(){};$/;"',
expect_symbol_type='f')
def test_namespaced_vars(self):
c = self.ctags_tester('''
my_namespace.myarray = [1, 2];
my_namespace.myobject = {a: 1};
my_namespace.myvar = 1;
my_namespace.myfunc = function(){};
''')
c.check(
expect_symbol='myarray',
expect_vim_search_cmd='/^my_namespace.myarray = [1, 2];$/;"',
expect_symbol_type='a')
c.check(
expect_symbol='myobject',
expect_vim_search_cmd='/^my_namespace.myobject = {a: 1};$/;"',
expect_symbol_type='o')
c.check(
expect_symbol='myvar',
expect_vim_search_cmd='/^my_namespace.myvar = 1;$/;"',
expect_symbol_type='r')
c.check(
expect_symbol='myfunc',
expect_vim_search_cmd='/^my_namespace.myfunc = function(){};$/;"',
expect_symbol_type='f')
def test_jquery(self):
'''
Tags for jQuery bind() handlers.
It creates symbols like `#foo.click` which is great for viewing in TagBar
although less useful for jumping to tags.
'''
c = self.ctags_tester('''
$("#foo").bind("dollar_bind_event", function() {
jQuery('#foo').bind("jquery_bind_event", function() {
$(bar).bind("var_bind_event", function() {
jQuery( '#with_spaces' ).bind( "jquery_bind_event" , function() {
''')
# $("#foo").click('click_event', function() {
# $("#foo").dblclick('click_event', function() {
# $("#foo").focus('click_event', function() {
# $("#foo").focusin('click_event', function() {
# $("#foo").focusout('click_event', function() {
# $("#foo").hover('click_event', function() {
# $("#foo").keydown('click_event', function() {
# $("#foo").keypress('click_event', function() {
# $("#foo").keyup('click_event', function() {
# ''')
c.check(
expect_symbol='"#foo".dollar_bind_event',
expect_symbol_type='f')
c.check(
expect_symbol="'#foo'.jquery_bind_event",
expect_symbol_type='f')
c.check(
expect_symbol="bar.var_bind_event",
expect_symbol_type='f')
c.check(
expect_symbol="'#with_spaces'.jquery_bind_event",
expect_symbol_type='f')
def test_rspec_style_tests(self):
'''
Tags for blocks of Jasmine tests.
'''
c = self.ctags_tester('''
describe("Dog", function() {
describe("bark", function() {
context("while running", function() {
it("is loud", function() {
});
});
});
});
''')
# Don't include indentation for `describe` so searching for tag will reveal specs.
c.check(
expect_symbol='Dog',
expect_symbol_type='f')
c.check(
expect_symbol='bark',
expect_symbol_type='f')
# For `context` and `it` blocks, include indentation so TagBar's output shows file structure
c.check(
expect_symbol='. while running',
expect_symbol_type='f')
c.check(
expect_symbol='. is loud',
expect_symbol_type='f')
class SCSSTest(unittest.TestCase):
def ctags_tester(self, source_code):
return _ctags_tester.CTagsTester(self, '.scss', CTAGS_CONF, source_code)
def test_mixin(self):
c = self.ctags_tester('''
@mixin medium_text {}
@function my_function {}
''')
c.check(
expect_symbol='medium_text',
expect_symbol_type='m')
c.check(
expect_symbol='my_function',
expect_symbol_type='f')
if __name__=='__main__':
unittest.main()