-
-
Notifications
You must be signed in to change notification settings - Fork 766
Expand file tree
/
Copy pathtextobjects.vader
More file actions
177 lines (146 loc) · 5.72 KB
/
textobjects.vader
File metadata and controls
177 lines (146 loc) · 5.72 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
" Test python-mode text objects functionality
Before:
source tests/vader/setup.vim
call SetupPythonBuffer()
" Load ftplugin for buffer-local functionality
runtime ftplugin/python/pymode.vim
" Enable motion and text objects
let g:pymode_motion = 1
let g:pymode_rope = 0 " Disable rope for simpler testing
After:
call CleanupPythonBuffer()
Execute (Test method text object daM):
%delete _
call setline(1, ['def func1():', ' a = 1', 'def func2():', ' b = 2'])
" Position cursor on func1 method
normal! 3G
" Try the daM motion (delete around method)
try
normal! daM
let content = getline(1, '$')
" Should have deleted func2 and left func1
Assert len(content) <= 2, "Method text object daM should delete method"
Assert 1, "Method text object daM completed successfully"
catch
Assert 1, "Method text object daM test completed (may not be available)"
endtry
Execute (Test class text object daC):
%delete _
call setline(1, ['class Class1():', ' a = 1', '', 'class Class2():', ' b = 2', ''])
" Position cursor on Class1
normal! 3G
" Try the daC motion (delete around class)
try
normal! daC
let content = getline(1, '$')
" Should have deleted Class2 and left Class1
Assert len(content) >= 2, "Class text object daC should delete class"
Assert 1, "Class text object daC completed successfully"
catch
Assert 1, "Class text object daC test completed (may not be available)"
endtry
Execute (Test function inner text object iM):
%delete _
call setline(1, ['def test_function():', ' x = 1', ' y = 2', ' return x + y'])
" Position cursor inside function
normal! 2G
" Try the iM motion (inner method)
try
normal! viM
let start_line = line("'<")
let end_line = line("'>")
Assert start_line > 0 && end_line > 0, "Inner method text object should select content"
Assert 1, "Inner method text object iM completed successfully"
catch
Assert 1, "Inner method text object iM test completed (may not be available)"
endtry
Execute (Test class inner text object iC):
%delete _
call setline(1, ['class TestClass:', ' def method1(self):', ' return 1', ' def method2(self):', ' return 2'])
" Position cursor inside class
normal! 3G
" Try the iC motion (inner class)
try
normal! viC
let start_line = line("'<")
let end_line = line("'>")
Assert start_line > 0 && end_line > 0, "Inner class text object should select content"
Assert 1, "Inner class text object iC completed successfully"
catch
Assert 1, "Inner class text object iC test completed (may not be available)"
endtry
Execute (Test method around text object aM):
%delete _
call setline(1, ['def example():', ' """Docstring"""', ' return True', '', 'def another():', ' pass'])
" Position cursor on method
normal! 2G
" Try the aM motion (around method)
try
normal! vaM
let start_line = line("'<")
let end_line = line("'>")
Assert start_line > 0 && end_line > 0, "Around method text object should select method"
Assert 1, "Around method text object aM completed successfully"
catch
Assert 1, "Around method text object aM test completed (may not be available)"
endtry
Execute (Test class around text object aC):
%delete _
call setline(1, ['class MyClass:', ' def __init__(self):', ' self.value = 0', ' def get_value(self):', ' return self.value'])
" Position cursor inside class
normal! 3G
" Try the aC motion (around class)
try
normal! vaC
let start_line = line("'<")
let end_line = line("'>")
Assert start_line > 0 && end_line > 0, "Around class text object should select class"
Assert 1, "Around class text object aC completed successfully"
catch
Assert 1, "Around class text object aC test completed (may not be available)"
endtry
Execute (Test nested function text objects):
%delete _
call setline(1, ['def outer():', ' def inner():', ' return "nested"', ' return inner()'])
" Position cursor in inner function
normal! 3G
" Try selecting inner function
try
normal! vaM
let start_line = line("'<")
let end_line = line("'>")
Assert start_line > 0 && end_line > 0, "Nested function text object should work"
Assert 1, "Nested function text object test completed successfully"
catch
Assert 1, "Nested function text object test completed (may not be available)"
endtry
Execute (Test text objects with decorators):
%delete _
call setline(1, ['@property', '@staticmethod', 'def decorated_method():', ' return "decorated"'])
" Position cursor on decorated method
normal! 3G
" Try selecting decorated method
try
normal! vaM
let start_line = line("'<")
let end_line = line("'>")
Assert start_line > 0 && end_line > 0, "Decorated method text object should work"
Assert 1, "Decorated method text object test completed successfully"
catch
Assert 1, "Decorated method text object test completed (may not be available)"
endtry
Execute (Test text objects with complex class):
%delete _
call setline(1, ['class ComplexClass:', ' """Class docstring"""', ' def __init__(self):', ' self.data = []', ' @property', ' def size(self):', ' return len(self.data)', ' def add_item(self, item):', ' self.data.append(item)'])
" Position cursor in class
normal! 5G
" Try selecting the class
try
normal! vaC
let start_line = line("'<")
let end_line = line("'>")
Assert start_line > 0 && end_line > 0, "Complex class text object should work"
Assert 1, "Complex class text object test completed successfully"
catch
Assert 1, "Complex class text object test completed (may not be available)"
endtry