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