blob: 2573401707f7778dea5c4c6029f153a0bec08c45 [file] [log] [blame]
Bram Moolenaarf9660b52016-04-16 22:19:15 +02001" Test commands that jump somewhere.
2
Bram Moolenaar226630a2016-10-08 19:21:31 +02003" Create a new buffer using "lines" and place the cursor on the word after the
4" first occurrence of return and invoke "cmd". The cursor should now be
5" positioned at the given line and col.
6func XTest_goto_decl(cmd, lines, line, col)
Bram Moolenaarf9660b52016-04-16 22:19:15 +02007 new
Bram Moolenaar226630a2016-10-08 19:21:31 +02008 call setline(1, a:lines)
9 /return/
10 normal! W
11 execute 'norm! ' . a:cmd
12 call assert_equal(a:line, line('.'))
13 call assert_equal(a:col, col('.'))
Bram Moolenaarf9660b52016-04-16 22:19:15 +020014 quit!
15endfunc
Bram Moolenaar23c60f22016-06-15 22:03:48 +020016
Bram Moolenaar226630a2016-10-08 19:21:31 +020017func Test_gD()
18 let lines = [
Bram Moolenaar936c48f2016-10-09 15:50:48 +020019 \ 'int x;',
20 \ '',
21 \ 'int func(void)',
22 \ '{',
23 \ ' return x;',
24 \ '}',
25 \ ]
Bram Moolenaar226630a2016-10-08 19:21:31 +020026 call XTest_goto_decl('gD', lines, 1, 5)
27endfunc
28
29func Test_gD_too()
30 let lines = [
31 \ 'Filename x;',
32 \ '',
33 \ 'int Filename',
34 \ 'int func() {',
35 \ ' Filename x;',
36 \ ' return x;',
37 \ ]
38 call XTest_goto_decl('gD', lines, 1, 10)
39endfunc
40
41func Test_gD_comment()
42 let lines = [
Bram Moolenaar936c48f2016-10-09 15:50:48 +020043 \ '/* int x; */',
44 \ 'int x;',
45 \ '',
46 \ 'int func(void)',
47 \ '{',
48 \ ' return x;',
49 \ '}',
50 \ ]
Bram Moolenaar226630a2016-10-08 19:21:31 +020051 call XTest_goto_decl('gD', lines, 2, 5)
52endfunc
53
54func Test_gD_inline_comment()
55 let lines = [
Bram Moolenaar936c48f2016-10-09 15:50:48 +020056 \ 'int y /* , x */;',
57 \ 'int x;',
58 \ '',
59 \ 'int func(void)',
60 \ '{',
61 \ ' return x;',
62 \ '}',
63 \ ]
Bram Moolenaar226630a2016-10-08 19:21:31 +020064 call XTest_goto_decl('gD', lines, 2, 5)
65endfunc
66
67func Test_gD_string()
68 let lines = [
Bram Moolenaar936c48f2016-10-09 15:50:48 +020069 \ 'char *s[] = "x";',
70 \ 'int x = 1;',
71 \ '',
72 \ 'int func(void)',
73 \ '{',
74 \ ' return x;',
75 \ '}',
76 \ ]
Bram Moolenaar226630a2016-10-08 19:21:31 +020077 call XTest_goto_decl('gD', lines, 2, 5)
78endfunc
79
80func Test_gD_string_same_line()
81 let lines = [
Bram Moolenaar936c48f2016-10-09 15:50:48 +020082 \ 'char *s[] = "x", int x = 1;',
83 \ '',
84 \ 'int func(void)',
85 \ '{',
86 \ ' return x;',
87 \ '}',
88 \ ]
Bram Moolenaar226630a2016-10-08 19:21:31 +020089 call XTest_goto_decl('gD', lines, 1, 22)
90endfunc
91
92func Test_gD_char()
93 let lines = [
Bram Moolenaar936c48f2016-10-09 15:50:48 +020094 \ "char c = 'x';",
95 \ 'int x = 1;',
96 \ '',
97 \ 'int func(void)',
98 \ '{',
99 \ ' return x;',
100 \ '}',
101 \ ]
Bram Moolenaar226630a2016-10-08 19:21:31 +0200102 call XTest_goto_decl('gD', lines, 2, 5)
103endfunc
104
105func Test_gd()
106 let lines = [
Bram Moolenaar936c48f2016-10-09 15:50:48 +0200107 \ 'int x;',
108 \ '',
109 \ 'int func(int x)',
110 \ '{',
111 \ ' return x;',
112 \ '}',
113 \ ]
Bram Moolenaar226630a2016-10-08 19:21:31 +0200114 call XTest_goto_decl('gd', lines, 3, 14)
115endfunc
116
117func Test_gd_not_local()
118 let lines = [
Bram Moolenaar936c48f2016-10-09 15:50:48 +0200119 \ 'int func1(void)',
120 \ '{',
121 \ ' return x;',
122 \ '}',
123 \ '',
124 \ 'int func2(int x)',
125 \ '{',
126 \ ' return x;',
127 \ '}',
128 \ ]
Bram Moolenaar226630a2016-10-08 19:21:31 +0200129 call XTest_goto_decl('gd', lines, 3, 10)
130endfunc
131
132func Test_gd_kr_style()
133 let lines = [
Bram Moolenaar936c48f2016-10-09 15:50:48 +0200134 \ 'int func(x)',
135 \ ' int x;',
136 \ '{',
137 \ ' return x;',
138 \ '}',
139 \ ]
Bram Moolenaar226630a2016-10-08 19:21:31 +0200140 call XTest_goto_decl('gd', lines, 2, 7)
141endfunc
142
143func Test_gd_missing_braces()
144 let lines = [
Bram Moolenaar936c48f2016-10-09 15:50:48 +0200145 \ 'def func1(a)',
146 \ ' a + 1',
147 \ 'end',
148 \ '',
149 \ 'a = 1',
150 \ '',
151 \ 'def func2()',
152 \ ' return a',
153 \ 'end',
154 \ ]
Bram Moolenaar226630a2016-10-08 19:21:31 +0200155 call XTest_goto_decl('gd', lines, 1, 11)
156endfunc
157
158func Test_gd_comment()
159 let lines = [
Bram Moolenaar936c48f2016-10-09 15:50:48 +0200160 \ 'int func(void)',
161 \ '{',
162 \ ' /* int x; */',
163 \ ' int x;',
164 \ ' return x;',
165 \ '}',
166 \]
Bram Moolenaar226630a2016-10-08 19:21:31 +0200167 call XTest_goto_decl('gd', lines, 4, 7)
168endfunc
169
170func Test_gd_comment_in_string()
171 let lines = [
Bram Moolenaar936c48f2016-10-09 15:50:48 +0200172 \ 'int func(void)',
173 \ '{',
174 \ ' char *s ="//"; int x;',
175 \ ' int x;',
176 \ ' return x;',
177 \ '}',
178 \]
Bram Moolenaar226630a2016-10-08 19:21:31 +0200179 call XTest_goto_decl('gd', lines, 3, 22)
180endfunc
181
182func Test_gd_string_in_comment()
183 set comments=
184 let lines = [
Bram Moolenaar936c48f2016-10-09 15:50:48 +0200185 \ 'int func(void)',
186 \ '{',
187 \ ' /* " */ int x;',
188 \ ' int x;',
189 \ ' return x;',
190 \ '}',
191 \]
Bram Moolenaar226630a2016-10-08 19:21:31 +0200192 call XTest_goto_decl('gd', lines, 3, 15)
193 set comments&
194endfunc
195
196func Test_gd_inline_comment()
197 let lines = [
Bram Moolenaar936c48f2016-10-09 15:50:48 +0200198 \ 'int func(/* x is an int */ int x)',
199 \ '{',
200 \ ' return x;',
201 \ '}',
202 \ ]
Bram Moolenaar226630a2016-10-08 19:21:31 +0200203 call XTest_goto_decl('gd', lines, 1, 32)
204endfunc
205
206func Test_gd_inline_comment_only()
207 let lines = [
Bram Moolenaar936c48f2016-10-09 15:50:48 +0200208 \ 'int func(void) /* one lonely x */',
209 \ '{',
210 \ ' return x;',
211 \ '}',
212 \ ]
Bram Moolenaar226630a2016-10-08 19:21:31 +0200213 call XTest_goto_decl('gd', lines, 3, 10)
214endfunc
215
216func Test_gd_inline_comment_body()
217 let lines = [
Bram Moolenaar936c48f2016-10-09 15:50:48 +0200218 \ 'int func(void)',
219 \ '{',
220 \ ' int y /* , x */;',
221 \ '',
222 \ ' for (/* int x = 0 */; y < 2; y++);',
223 \ '',
224 \ ' int x = 0;',
225 \ '',
226 \ ' return x;',
227 \ '}',
228 \ ]
Bram Moolenaar226630a2016-10-08 19:21:31 +0200229 call XTest_goto_decl('gd', lines, 7, 7)
230endfunc
231
232func Test_gd_trailing_multiline_comment()
233 let lines = [
Bram Moolenaar936c48f2016-10-09 15:50:48 +0200234 \ 'int func(int x) /* x is an int */',
235 \ '{',
236 \ ' return x;',
237 \ '}',
238 \ ]
Bram Moolenaar226630a2016-10-08 19:21:31 +0200239 call XTest_goto_decl('gd', lines, 1, 14)
240endfunc
241
242func Test_gd_trailing_comment()
243 let lines = [
Bram Moolenaar936c48f2016-10-09 15:50:48 +0200244 \ 'int func(int x) // x is an int',
245 \ '{',
246 \ ' return x;',
247 \ '}',
248 \ ]
Bram Moolenaar226630a2016-10-08 19:21:31 +0200249 call XTest_goto_decl('gd', lines, 1, 14)
250endfunc
251
252func Test_gd_string()
253 let lines = [
Bram Moolenaar936c48f2016-10-09 15:50:48 +0200254 \ 'int func(void)',
255 \ '{',
256 \ ' char *s = "x";',
257 \ ' int x = 1;',
258 \ '',
259 \ ' return x;',
260 \ '}',
261 \ ]
Bram Moolenaar226630a2016-10-08 19:21:31 +0200262 call XTest_goto_decl('gd', lines, 4, 7)
263endfunc
264
265func Test_gd_string_only()
266 let lines = [
Bram Moolenaar936c48f2016-10-09 15:50:48 +0200267 \ 'int func(void)',
268 \ '{',
269 \ ' char *s = "x";',
270 \ '',
271 \ ' return x;',
272 \ '}',
273 \ ]
Bram Moolenaar226630a2016-10-08 19:21:31 +0200274 call XTest_goto_decl('gd', lines, 5, 10)
Bram Moolenaar23c60f22016-06-15 22:03:48 +0200275endfunc
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100276
277" Check that setting 'cursorline' does not change curswant
278func Test_cursorline_keep_col()
279 new
280 call setline(1, ['long long long line', 'short line'])
281 normal ggfi
282 let pos = getcurpos()
283 normal j
284 set cursorline
285 normal k
286 call assert_equal(pos, getcurpos())
287 bwipe!
288 set nocursorline
289endfunc
290