1" Test commands that jump somewhere. 2 3" 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) 7 new 8 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('.')) 14 quit! 15endfunc 16 17func Test_gD() 18 let lines =<< trim [CODE] 19 int x; 20 21 int func(void) 22 { 23 return x; 24 } 25 [CODE] 26 27 call XTest_goto_decl('gD', lines, 1, 5) 28endfunc 29 30func Test_gD_too() 31 let lines =<< trim [CODE] 32 Filename x; 33 34 int Filename 35 int func() { 36 Filename x; 37 return x; 38 [CODE] 39 40 call XTest_goto_decl('gD', lines, 1, 10) 41endfunc 42 43func Test_gD_comment() 44 let lines =<< trim [CODE] 45 /* int x; */ 46 int x; 47 48 int func(void) 49 { 50 return x; 51 } 52 [CODE] 53 54 call XTest_goto_decl('gD', lines, 2, 5) 55endfunc 56 57func Test_gD_inline_comment() 58 let lines =<< trim [CODE] 59 int y /* , x */; 60 int x; 61 62 int func(void) 63 { 64 return x; 65 } 66 [CODE] 67 68 call XTest_goto_decl('gD', lines, 2, 5) 69endfunc 70 71func Test_gD_string() 72 let lines =<< trim [CODE] 73 char *s[] = "x"; 74 int x = 1; 75 76 int func(void) 77 { 78 return x; 79 } 80 [CODE] 81 82 call XTest_goto_decl('gD', lines, 2, 5) 83endfunc 84 85func Test_gD_string_same_line() 86 let lines =<< trim [CODE] 87 char *s[] = "x", int x = 1; 88 89 int func(void) 90 { 91 return x; 92 } 93 [CODE] 94 95 call XTest_goto_decl('gD', lines, 1, 22) 96endfunc 97 98func Test_gD_char() 99 let lines =<< trim [CODE] 100 char c = 'x'; 101 int x = 1; 102 103 int func(void) 104 { 105 return x; 106 } 107 [CODE] 108 109 call XTest_goto_decl('gD', lines, 2, 5) 110endfunc 111 112func Test_gd() 113 let lines =<< trim [CODE] 114 int x; 115 116 int func(int x) 117 { 118 return x; 119 } 120 [CODE] 121 122 call XTest_goto_decl('gd', lines, 3, 14) 123endfunc 124 125func Test_gd_not_local() 126 let lines =<< trim [CODE] 127 int func1(void) 128 { 129 return x; 130 } 131 132 int func2(int x) 133 { 134 return x; 135 } 136 [CODE] 137 138 call XTest_goto_decl('gd', lines, 3, 10) 139endfunc 140 141func Test_gd_kr_style() 142 let lines =<< trim [CODE] 143 int func(x) 144 int x; 145 { 146 return x; 147 } 148 [CODE] 149 150 call XTest_goto_decl('gd', lines, 2, 7) 151endfunc 152 153func Test_gd_missing_braces() 154 let lines =<< trim [CODE] 155 def func1(a) 156 a + 1 157 end 158 159 a = 1 160 161 def func2() 162 return a 163 end 164 [CODE] 165 166 call XTest_goto_decl('gd', lines, 1, 11) 167endfunc 168 169func Test_gd_comment() 170 let lines =<< trim [CODE] 171 int func(void) 172 { 173 /* int x; */ 174 int x; 175 return x; 176 } 177 [CODE] 178 179 call XTest_goto_decl('gd', lines, 4, 7) 180endfunc 181 182func Test_gd_comment_in_string() 183 let lines =<< trim [CODE] 184 int func(void) 185 { 186 char *s ="//"; int x; 187 int x; 188 return x; 189 } 190 [CODE] 191 192 call XTest_goto_decl('gd', lines, 3, 22) 193endfunc 194 195func Test_gd_string_in_comment() 196 set comments= 197 let lines =<< trim [CODE] 198 int func(void) 199 { 200 /* " */ int x; 201 int x; 202 return x; 203 } 204 [CODE] 205 206 call XTest_goto_decl('gd', lines, 3, 15) 207 set comments& 208endfunc 209 210func Test_gd_inline_comment() 211 let lines =<< trim [CODE] 212 int func(/* x is an int */ int x) 213 { 214 return x; 215 } 216 [CODE] 217 218 call XTest_goto_decl('gd', lines, 1, 32) 219endfunc 220 221func Test_gd_inline_comment_only() 222 let lines =<< trim [CODE] 223 int func(void) /* one lonely x */ 224 { 225 return x; 226 } 227 [CODE] 228 229 call XTest_goto_decl('gd', lines, 3, 10) 230endfunc 231 232func Test_gd_inline_comment_body() 233 let lines =<< trim [CODE] 234 int func(void) 235 { 236 int y /* , x */; 237 238 for (/* int x = 0 */; y < 2; y++); 239 240 int x = 0; 241 242 return x; 243 } 244 [CODE] 245 246 call XTest_goto_decl('gd', lines, 7, 7) 247endfunc 248 249func Test_gd_trailing_multiline_comment() 250 let lines =<< trim [CODE] 251 int func(int x) /* x is an int */ 252 { 253 return x; 254 } 255 [CODE] 256 257 call XTest_goto_decl('gd', lines, 1, 14) 258endfunc 259 260func Test_gd_trailing_comment() 261 let lines =<< trim [CODE] 262 int func(int x) // x is an int 263 { 264 return x; 265 } 266 [CODE] 267 268 call XTest_goto_decl('gd', lines, 1, 14) 269endfunc 270 271func Test_gd_string() 272 let lines =<< trim [CODE] 273 int func(void) 274 { 275 char *s = "x"; 276 int x = 1; 277 278 return x; 279 } 280 [CODE] 281 call XTest_goto_decl('gd', lines, 4, 7) 282endfunc 283 284func Test_gd_string_only() 285 let lines =<< trim [CODE] 286 int func(void) 287 { 288 char *s = "x"; 289 290 return x; 291 } 292 [CODE] 293 294 call XTest_goto_decl('gd', lines, 5, 10) 295endfunc 296 297" Check that setting 'cursorline' does not change curswant 298func Test_cursorline_keep_col() 299 new 300 call setline(1, ['long long long line', 'short line']) 301 normal ggfi 302 let pos = getcurpos() 303 normal j 304 set cursorline 305 normal k 306 call assert_equal(pos, getcurpos()) 307 bwipe! 308 set nocursorline 309endfunc 310 311func Test_gd_local_block() 312 let lines =<< trim [CODE] 313 int main() 314 { 315 char *a = "NOT NULL"; 316 if(a) 317 { 318 char *b = a; 319 printf("%s\n", b); 320 } 321 else 322 { 323 char *b = "NULL"; 324 return b; 325 } 326 327 return 0; 328 } 329 [CODE] 330 331 call XTest_goto_decl('1gd', lines, 11, 11) 332endfunc 333 334func Test_motion_if_elif_else_endif() 335 new 336 let lines =<< trim END 337 /* Test pressing % on #if, #else #elsif and #endif, 338 * with nested #if 339 */ 340 #if FOO 341 /* ... */ 342 # if BAR 343 /* ... */ 344 # endif 345 #elif BAR 346 /* ... */ 347 #else 348 /* ... */ 349 #endif 350 351 #define FOO 1 352 END 353 call setline(1, lines) 354 /#if FOO 355 norm % 356 call assert_equal([9, 1], getpos('.')[1:2]) 357 norm % 358 call assert_equal([11, 1], getpos('.')[1:2]) 359 norm % 360 call assert_equal([13, 1], getpos('.')[1:2]) 361 norm % 362 call assert_equal([4, 1], getpos('.')[1:2]) 363 /# if BAR 364 norm $% 365 call assert_equal([8, 1], getpos('.')[1:2]) 366 norm $% 367 call assert_equal([6, 1], getpos('.')[1:2]) 368 369 " Test for [# and ]# command 370 call cursor(5, 1) 371 normal [# 372 call assert_equal([4, 1], getpos('.')[1:2]) 373 call cursor(5, 1) 374 normal ]# 375 call assert_equal([9, 1], getpos('.')[1:2]) 376 call cursor(10, 1) 377 normal [# 378 call assert_equal([9, 1], getpos('.')[1:2]) 379 call cursor(10, 1) 380 normal ]# 381 call assert_equal([11, 1], getpos('.')[1:2]) 382 383 " Finding a match before the first line or after the last line should fail 384 normal gg 385 call assert_beeps('normal [#') 386 normal G 387 call assert_beeps('normal ]#') 388 389 " Finding a match for a macro definition (#define) should fail 390 normal G 391 call assert_beeps('normal %') 392 393 bw! 394endfunc 395 396func Test_motion_c_comment() 397 new 398 a 399/* 400 * Test pressing % on beginning/end 401 * of C comments. 402 */ 403/* Another comment */ 404. 405 norm gg0% 406 call assert_equal([4, 3], getpos('.')[1:2]) 407 norm % 408 call assert_equal([1, 1], getpos('.')[1:2]) 409 norm gg0l% 410 call assert_equal([4, 3], getpos('.')[1:2]) 411 norm h% 412 call assert_equal([1, 1], getpos('.')[1:2]) 413 414 norm G^ 415 norm % 416 call assert_equal([5, 21], getpos('.')[1:2]) 417 norm % 418 call assert_equal([5, 1], getpos('.')[1:2]) 419 420 bw! 421endfunc 422 423" vim: shiftwidth=2 sts=2 expandtab 424