robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
aa1d8a2702
master
1" Test for various Normal mode commands 2 3source shared.vim 4source check.vim 5source view_util.vim 6source vim9.vim 7source screendump.vim 8 9func Setup_NewWindow () 1010 new 11call setline ( 1 , range ( 1 , 100 )) 12endfunc 13 14func MyFormatExpr () 15" Adds '->$' at lines having numbers followed by trailing whitespace 16for ln in range ( v: lnum , v: lnum + v: count - 1 ) 17let line = getline ( ln ) 18if getline ( ln ) =~# '\d\s\+$' 19call setline ( ln , substitute ( line , '\s\+$' , '' , '' ) . '->$' ) 20endif 21endfor 22endfunc 23 24func CountSpaces ( type , ...) 25" for testing operatorfunc 26" will count the number of spaces 27" and return the result in g:a 28let sel_save = & selection 29let & selection = "inclusive" 30let reg_save = @@ 31 32if a: 0 " Invoked from Visual mode, use gv command. 33silent exe "normal! gvy" 34elseif a: type == 'line' 35silent exe "normal! '[V']y" 36else 37silent exe "normal! `[v`]y" 38endif 39let g: a = strlen ( substitute ( @@, '[^ ]' , '' , 'g' )) 40let & selection = sel_save 41let @@= reg_save 42endfunc 43 44func OpfuncDummy ( type , ...) 45" for testing operatorfunc 46let g: opt = & linebreak 47 48if a: 0 " Invoked from Visual mode, use gv command. 49silent exe "normal! gvy" 50elseif a: type == 'line' 51silent exe "normal! '[V']y" 52else 53silent exe "normal! `[v`]y" 54endif 55" Create a new dummy window 56new 57let g: bufnr = bufnr ( '%' ) 58endfunc 59 60func Test_normal00_optrans () 61new 62call append ( 0 , [ '1 This is a simple test: abcd' , '2 This is the second line' , '3 this is the third line' ]) 631 64exe "norm! Sfoobar\<esc>" 65call assert_equal ([ 'foobar' , '2 This is the second line' , '3 this is the third line' , '' ], getline ( 1 , '$' )) 662 67exe "norm! $vbsone" 68call assert_equal ([ 'foobar' , '2 This is the second one' , '3 this is the third line' , '' ], getline ( 1 , '$' )) 69norm ! VS Second line here 70call assert_equal ([ 'foobar' , ' Second line here' , '3 this is the third line' , '' ], getline ( 1 , '$' )) 71 %d 72call append ( 0 , [ '4 This is a simple test: abcd' , '5 This is the second line' , '6 this is the third line' ]) 73call append ( 0 , [ '1 This is a simple test: abcd' , '2 This is the second line' , '3 this is the third line' ]) 74 751 76norm ! 2D 77call assert_equal ([ '3 this is the third line' , '4 This is a simple test: abcd' , '5 This is the second line' , '6 this is the third line' , '' ], getline ( 1 , '$' )) 78" Nvim: no "#" flag in 'cpoptions'. 79" set cpo+=# 80" norm! 4D 81" call assert_equal(['', '4 This is a simple test: abcd', '5 This is the second line', '6 this is the third line', ''], getline(1,'$')) 82 83" clean up 84set cpo -= # 85bw ! 86endfunc 87 88func Test_normal01_keymodel () 89call Setup_NewWindow () 90" Test 1: depending on 'keymodel' <s-down> does something different 9150 92call feedkeys ( "V\<S-Up>y" , 'tx' ) 93call assert_equal ([ '47' , '48' , '49' , '50' ], getline ( "'<" , "'>" )) 94set keymodel = startsel 9550 96call feedkeys ( "V\<S-Up>y" , 'tx' ) 97call assert_equal ([ '49' , '50' ], getline ( "'<" , "'>" )) 98" Start visual mode when keymodel = startsel 9950 100call feedkeys ( "\<S-Up>y" , 'tx' ) 101call assert_equal ([ '49' , '5' ], getreg ( 0 , 0 , 1 )) 102" Use the different Shift special keys 10350 104call feedkeys ( "\<S-Right>\<S-Left>\<S-Up>\<S-Down>\<S-Home>\<S-End>y" , 'tx' ) 105call assert_equal ([ '50' ], getline ( "'<" , "'>" )) 106call assert_equal ([ '50' , '' ], getreg ( 0 , 0 , 1 )) 107 108" Do not start visual mode when keymodel= 109set keymodel = 11050 111call feedkeys ( "\<S-Up>y$" , 'tx' ) 112call assert_equal ([ '42' ], getreg ( 0 , 0 , 1 )) 113" Stop visual mode when keymodel=stopsel 114set keymodel = stopsel 11550 116call feedkeys ( "Vkk\<Up>yy" , 'tx' ) 117call assert_equal ([ '47' ], getreg ( 0 , 0 , 1 )) 118 119set keymodel = 12050 121call feedkeys ( "Vkk\<Up>yy" , 'tx' ) 122call assert_equal ([ '47' , '48' , '49' , '50' ], getreg ( 0 , 0 , 1 )) 123 124" Test for using special keys to start visual selection 125 %d 126call setline ( 1 , [ 'red fox tail' , 'red fox tail' , 'red fox tail' ]) 127set keymodel = startsel 128" Test for <S-PageUp> and <S-PageDown> 129call cursor ( 1 , 1 ) 130call feedkeys ( "\<S-PageDown>y" , 'xt' ) 131call assert_equal ([ 0 , 1 , 1 , 0 ], getpos ( "'<" )) 132call assert_equal ([ 0 , 3 , 1 , 0 ], getpos ( "'>" )) 133call feedkeys ( "Gz\<CR>8|\<S-PageUp>y" , 'xt' ) 134call assert_equal ([ 0 , 3 , 1 , 0 ], getpos ( "'<" )) 135call assert_equal ([ 0 , 3 , 8 , 0 ], getpos ( "'>" )) 136" Test for <S-C-Home> and <S-C-End> 137call cursor ( 2 , 12 ) 138call feedkeys ( "\<S-C-Home>y" , 'xt' ) 139call assert_equal ([ 0 , 1 , 1 , 0 ], getpos ( "'<" )) 140call assert_equal ([ 0 , 2 , 12 , 0 ], getpos ( "'>" )) 141call cursor ( 1 , 4 ) 142call feedkeys ( "\<S-C-End>y" , 'xt' ) 143call assert_equal ([ 0 , 1 , 4 , 0 ], getpos ( "'<" )) 144call assert_equal ([ 0 , 3 , 13 , 0 ], getpos ( "'>" )) 145" Test for <S-C-Left> and <S-C-Right> 146call cursor ( 2 , 5 ) 147call feedkeys ( "\<S-C-Right>y" , 'xt' ) 148call assert_equal ([ 0 , 2 , 5 , 0 ], getpos ( "'<" )) 149call assert_equal ([ 0 , 2 , 9 , 0 ], getpos ( "'>" )) 150call cursor ( 2 , 9 ) 151call feedkeys ( "\<S-C-Left>y" , 'xt' ) 152call assert_equal ([ 0 , 2 , 5 , 0 ], getpos ( "'<" )) 153call assert_equal ([ 0 , 2 , 9 , 0 ], getpos ( "'>" )) 154 155set keymodel & 156 157" clean up 158bw ! 159endfunc 160 161func Test_normal03_join () 162" basic join test 163call Setup_NewWindow () 16450 165norm ! VJ 166call assert_equal ( '50 51' , getline ( '.' )) 167$ 168norm ! J 169call assert_equal ( '100' , getline ( '.' )) 170$ 171norm ! V9-gJ 172call assert_equal ( '919293949596979899100' , getline ( '.' )) 173call setline ( 1 , range ( 1 , 100 )) 174$ 175: j 10 176call assert_equal ( '100' , getline ( '.' )) 177call assert_beeps ( 'normal GVJ' ) 178" clean up 179bw ! 180endfunc 181 182" basic filter test 183func Test_normal04_filter () 184" only test on non windows platform 185CheckNotMSWindows 186call Setup_NewWindow () 1871 188call feedkeys ( "!!sed -e 's/^/| /'\n" , 'tx' ) 189call assert_equal ( '| 1' , getline ( '.' )) 19090 191: sil :! echo one 192call feedkeys ( '.' , 'tx' ) 193call assert_equal ( '| 90' , getline ( '.' )) 19495 195set cpo += ! 196" 2 <CR>, 1: for executing the command, 197" 2: clear hit-enter-prompt 198call feedkeys ( "!!\n" , 'tx' ) 199call feedkeys ( ":!echo one\n\n" , 'tx' ) 200call feedkeys ( "." , 'tx' ) 201call assert_equal ( 'one' , getline ( '.' )) 202set cpo -= ! 203bw ! 204endfunc 205 206func Test_normal05_formatexpr () 207" basic formatexpr test 208call Setup_NewWindow () 209 %d _ 210call setline ( 1 , [ 'here: 1 ' , '2' , 'here: 3 ' , '4' , 'not here: ' ]) 2111 212set formatexpr = MyFormatExpr () 213norm ! gqG 214call assert_equal ([ 'here: 1->$' , '2' , 'here: 3->$' , '4' , 'not here: ' ], getline ( 1 , '$' )) 215set formatexpr = 216bw ! 217endfunc 218 219func Test_normal05_formatexpr_newbuf () 220" Edit another buffer in the 'formatexpr' function 221new 222func ! Format () 223edit another 224endfunc 225set formatexpr = Format () 226norm gqG 227bw ! 228set formatexpr = 229endfunc 230 231func Test_normal05_formatexpr_setopt () 232" Change the 'formatexpr' value in the function 233new 234func ! Format () 235set formatexpr = 236endfunc 237set formatexpr = Format () 238norm gqG 239bw ! 240set formatexpr = 241endfunc 242 243" When 'formatexpr' returns non-zero, internal formatting is used. 244func Test_normal_formatexpr_returns_nonzero () 245new 246call setline ( 1 , [ 'one' , 'two' ]) 247func ! Format () 248return 1 249endfunc 250setlocal formatexpr = Format () 251normal VGgq 252call assert_equal ([ 'one two' ], getline ( 1 , '$' )) 253 254setlocal formatexpr = 255delfunc Format 256bwipe ! 257endfunc 258 259" Test for using a script-local function for 'formatexpr' 260func Test_formatexpr_scriptlocal_func () 261func ! s: Format () 262let g: FormatArgs = [ v: lnum , v: count ] 263endfunc 264set formatexpr = s :Format() 265call assert_equal ( expand ( '<SID>' ) .. 'Format()' , & formatexpr ) 266call assert_equal ( expand ( '<SID>' ) .. 'Format()' , & g: formatexpr ) 267new |only 268call setline ( 1 , range ( 1 , 40 )) 269let g: FormatArgs = [] 270normal ! 2GVjgq 271call assert_equal ([ 2 , 2 ], g: FormatArgs ) 272bw ! 273set formatexpr = <SID>Format() 274call assert_equal ( expand ( '<SID>' ) .. 'Format()' , & formatexpr ) 275call assert_equal ( expand ( '<SID>' ) .. 'Format()' , & g: formatexpr ) 276new |only 277call setline ( 1 , range ( 1 , 40 )) 278let g: FormatArgs = [] 279normal ! 4GVjgq 280call assert_equal ([ 4 , 2 ], g: FormatArgs ) 281bw ! 282let & formatexpr = 's:Format()' 283call assert_equal ( expand ( '<SID>' ) .. 'Format()' , & g: formatexpr ) 284new |only 285call setline ( 1 , range ( 1 , 40 )) 286let g: FormatArgs = [] 287normal ! 6GVjgq 288call assert_equal ([ 6 , 2 ], g: FormatArgs ) 289bw ! 290let & formatexpr = '<SID>Format()' 291call assert_equal ( expand ( '<SID>' ) .. 'Format()' , & g: formatexpr ) 292new |only 293call setline ( 1 , range ( 1 , 40 )) 294let g: FormatArgs = [] 295normal ! 8GVjgq 296call assert_equal ([ 8 , 2 ], g: FormatArgs ) 297bw ! 298setlocal formatexpr = 299setglobal formatexpr=s:Format() 300call assert_equal ( expand ( '<SID>' ) .. 'Format()' , & g: formatexpr ) 301call assert_equal ( '' , & formatexpr ) 302new 303call assert_equal ( expand ( '<SID>' ) .. 'Format()' , & formatexpr ) 304call setline ( 1 , range ( 1 , 40 )) 305let g: FormatArgs = [] 306normal ! 10GVjgq 307call assert_equal ([ 10 , 2 ], g: FormatArgs ) 308bw ! 309setglobal formatexpr=<SID>Format() 310call assert_equal ( expand ( '<SID>' ) .. 'Format()' , & g: formatexpr ) 311call assert_equal ( '' , & formatexpr ) 312new 313call assert_equal ( expand ( '<SID>' ) .. 'Format()' , & formatexpr ) 314call setline ( 1 , range ( 1 , 40 )) 315let g: FormatArgs = [] 316normal ! 12GVjgq 317call assert_equal ([ 12 , 2 ], g: FormatArgs ) 318bw ! 319let & g: formatexpr = 's:Format()' 320call assert_equal ( expand ( '<SID>' ) .. 'Format()' , & g: formatexpr ) 321call assert_equal ( '' , & formatexpr ) 322new 323call assert_equal ( expand ( '<SID>' ) .. 'Format()' , & formatexpr ) 324call setline ( 1 , range ( 1 , 40 )) 325let g: FormatArgs = [] 326normal ! 14GVjgq 327call assert_equal ([ 14 , 2 ], g: FormatArgs ) 328bw ! 329let & g: formatexpr = '<SID>Format()' 330call assert_equal ( expand ( '<SID>' ) .. 'Format()' , & g: formatexpr ) 331call assert_equal ( '' , & formatexpr ) 332new 333call assert_equal ( expand ( '<SID>' ) .. 'Format()' , & formatexpr ) 334call setline ( 1 , range ( 1 , 40 )) 335let g: FormatArgs = [] 336normal ! 16GVjgq 337call assert_equal ([ 16 , 2 ], g: FormatArgs ) 338bw ! 339set formatexpr = 340delfunc s:Format 341bw ! 342endfunc 343 344" basic test for formatprg 345func Test_normal06_formatprg () 346" only test on non windows platform 347CheckNotMSWindows 348 349" uses sed to number non-empty lines 350call writefile ([ '#!/bin/sh' , 'sed ''/./=''|sed ''/./{' , 'N' , 's/\n/ /' , '}''' ], 'Xsed_format.sh' , 'D' ) 351call system ( 'chmod +x ./Xsed_format.sh' ) 352let text = [ 'a' , '' , 'c' , '' , ' ' , 'd' , 'e' ] 353let expected = [ '1 a' , '' , '3 c' , '' , '5 ' , '6 d' , '7 e' ] 354 35510 new 356call setline ( 1 , text ) 357set formatprg = ./Xsed_format.sh 358norm ! gggqG 359call assert_equal ( expected , getline ( 1 , '$' )) 360 %d 361 362call setline ( 1 , text ) 363set formatprg = donothing 364setlocal formatprg = ./Xsed_format.sh 365norm ! gggqG 366call assert_equal ( expected , getline ( 1 , '$' )) 367 %d 368 369" Check for the command-line ranges added to 'formatprg' 370set formatprg = cat 371call setline ( 1 , [ 'one' , 'two' , 'three' , 'four' , 'five' ]) 372call feedkeys ( 'gggqG' , 'xt' ) 373call assert_equal ( '.,$!cat' , @:) 374call feedkeys ( '2Ggq2j' , 'xt' ) 375call assert_equal ( '.,.+2!cat' , @:) 376 377bw ! 378" clean up 379set formatprg = 380setlocal formatprg = 381endfunc 382 383func Test_normal07_internalfmt () 384" basic test for internal formatter to textwidth of 12 385let list = range ( 1 , 11 ) 386call map ( list , 'v:val." "' ) 38710 new 388call setline ( 1 , list ) 389set tw = 12 390norm ! ggVGgq 391call assert_equal ([ '1 2 3' , '4 5 6' , '7 8 9' , '10 11 ' ], getline ( 1 , '$' )) 392" clean up 393set tw = 0 394bw ! 395endfunc 396 397" basic tests for foldopen/folddelete 398func Test_normal08_fold () 399CheckFeature folding 400call Setup_NewWindow () 40150 402setl foldenable fdm = marker 403" First fold 404norm ! V4jzf 405" check that folds have been created 406call assert_equal ([ '50/* {{{ */' , '51' , '52' , '53' , '54/* }}} */' ], getline ( 50 , 54 )) 407" Second fold 40846 409norm ! V10jzf 410" check that folds have been created 411call assert_equal ( '46/* {{{ */' , getline ( 46 )) 412call assert_equal ( '60/* }}} */' , getline ( 60 )) 413norm ! k 414call assert_equal ( '45' , getline ( '.' )) 415norm ! j 416call assert_equal ( '46/* {{{ */' , getline ( '.' )) 417norm ! j 418call assert_equal ( '61' , getline ( '.' )) 419norm ! k 420" open a fold 421norm ! Vzo 422norm ! k 423call assert_equal ( '45' , getline ( '.' )) 424norm ! j 425call assert_equal ( '46/* {{{ */' , getline ( '.' )) 426norm ! j 427call assert_equal ( '47' , getline ( '.' )) 428norm ! k 429norm ! zcVzO 430call assert_equal ( '46/* {{{ */' , getline ( '.' )) 431norm ! j 432call assert_equal ( '47' , getline ( '.' )) 433norm ! j 434call assert_equal ( '48' , getline ( '.' )) 435norm ! j 436call assert_equal ( '49' , getline ( '.' )) 437norm ! j 438call assert_equal ( '50/* {{{ */' , getline ( '.' )) 439norm ! j 440call assert_equal ( '51' , getline ( '.' )) 441" delete folds 442: 46 443" collapse fold 444norm ! V14jzC 445" delete all folds recursively 446norm ! VzD 447call assert_equal ([ '46' , '47' , '48' , '49' , '50' , '51' , '52' , '53' , '54' , '55' , '56' , '57' , '58' , '59' , '60' ], getline ( 46 , 60 )) 448 449" clean up 450setl nofoldenable fdm = marker 451bw ! 452endfunc 453 454func Test_normal09a_operatorfunc () 455" Test operatorfunc 456call Setup_NewWindow () 457" Add some spaces for counting 45850 , 60 s /$/ / 459unlet ! g: a 460let g: a = 0 461nmap <buffer><silent> ,, :set opfunc=CountSpaces< CR > g@ 462vmap <buffer><silent> ,, :< C-U > call CountSpaces(visualmode(), 1)< CR > 46350 464norm V2j,, 465call assert_equal ( 6 , g: a ) 466norm V,, 467call assert_equal ( 2 , g: a ) 468norm ,,l 469call assert_equal ( 0 , g: a ) 47050 471exe "norm 0\<c-v>10j2l,," 472call assert_equal ( 11 , g: a ) 47350 474norm V10j,, 475call assert_equal ( 22 , g: a ) 476 477" clean up 478unmap <buffer> ,, 479set opfunc = 480unlet ! g: a 481bw ! 482endfunc 483 484func Test_normal09b_operatorfunc () 485" Test operatorfunc 486call Setup_NewWindow () 487" Add some spaces for counting 48850 , 60 s /$/ / 489unlet ! g: opt 490set linebreak 491nmap <buffer><silent> ,, :set opfunc=OpfuncDummy< CR > g@ 49250 493norm ,,j 494exe "bd!" g: bufnr 495call assert_true ( & linebreak ) 496call assert_equal ( g: opt , & linebreak ) 497set nolinebreak 498norm ,,j 499exe "bd!" g: bufnr 500call assert_false ( & linebreak ) 501call assert_equal ( g: opt , & linebreak ) 502 503" clean up 504unmap <buffer> ,, 505set opfunc = 506call assert_fails ( 'normal Vg@' , 'E774:' ) 507bw ! 508unlet ! g: opt 509endfunc 510 511func OperatorfuncRedo ( _ ) 512let g: opfunc_count = v: count 513endfunc 514 515func Underscorize ( _ ) 516normal ! '[V']r_ 517endfunc 518 519func Test_normal09c_operatorfunc () 520" Test redoing operatorfunc 521new 522call setline ( 1 , 'some text' ) 523set operatorfunc = OperatorfuncRedo 524normal v3g@ 525call assert_equal ( 3 , g: opfunc_count ) 526let g: opfunc_count = 0 527normal . 528call assert_equal ( 3 , g: opfunc_count ) 529 530bw ! 531unlet g: opfunc_count 532 533" Test redoing Visual mode 534set operatorfunc = Underscorize 535new 536call setline ( 1 , [ 'first' , 'first' , 'third' , 'third' , 'second' ]) 537normal ! 1GVjg@ 538normal ! 3G. 539" Nvim: "." re-executes the captured keysequence ("Vjg@"), not an equal-size 540" reselect. At the last line the replayed "j" fails, aborting the replay: 541" nothing is applied (and the pending Visual mode is left active). 542normal ! 5G. 543exe "normal! \<Esc>" 544call assert_equal ([ '_____' , '_____' , '_____' , '_____' , 'second' ], getline ( 1 , '$' )) 545bwipe ! 546set operatorfunc = 547endfunc 548 549" Test for different ways of setting the 'operatorfunc' option 550func Test_opfunc_callback () 551new 552func OpFunc1 ( callnr , type ) 553let g: OpFunc1Args = [ a: callnr , a: type ] 554endfunc 555func OpFunc2 ( type ) 556let g: OpFunc2Args = [ a: type ] 557endfunc 558 559let lines =<< trim END 560#" Test for using a function name 561LET &opfunc = 'g:OpFunc2' 562LET g:OpFunc2Args = [] 563normal! g@l 564call assert_equal(['char'], g:OpFunc2Args) 565 566#" Test for using a function() 567set opfunc=function('g:OpFunc1',\ [10]) 568LET g:OpFunc1Args = [] 569normal! g@l 570call assert_equal([10, 'char'], g:OpFunc1Args) 571 572#" Using a funcref variable to set 'operatorfunc' 573VAR Fn = function('g:OpFunc1', [11]) 574LET &opfunc = Fn 575LET g:OpFunc1Args = [] 576normal! g@l 577call assert_equal([11, 'char'], g:OpFunc1Args) 578 579#" Using a string(funcref_variable) to set 'operatorfunc' 580LET Fn = function('g:OpFunc1', [12]) 581LET &operatorfunc = string(Fn) 582LET g:OpFunc1Args = [] 583normal! g@l 584call assert_equal([12, 'char'], g:OpFunc1Args) 585 586#" Test for using a funcref() 587set operatorfunc=funcref('g:OpFunc1',\ [13]) 588LET g:OpFunc1Args = [] 589normal! g@l 590call assert_equal([13, 'char'], g:OpFunc1Args) 591 592#" Using a funcref variable to set 'operatorfunc' 593LET Fn = funcref('g:OpFunc1', [14]) 594LET &opfunc = Fn 595LET g:OpFunc1Args = [] 596normal! g@l 597call assert_equal([14, 'char'], g:OpFunc1Args) 598 599#" Using a string(funcref_variable) to set 'operatorfunc' 600LET Fn = funcref('g:OpFunc1', [15]) 601LET &opfunc = string(Fn) 602LET g:OpFunc1Args = [] 603normal! g@l 604call assert_equal([15, 'char'], g:OpFunc1Args) 605 606#" Test for using a lambda function using set 607VAR optval = "LSTART a LMIDDLE OpFunc1(16, a) LEND" 608LET optval = substitute(optval, ' ', '\\ ', 'g') 609exe "set opfunc=" .. optval 610LET g:OpFunc1Args = [] 611normal! g@l 612call assert_equal([16, 'char'], g:OpFunc1Args) 613 614#" Test for using a lambda function using LET 615LET &opfunc = LSTART a LMIDDLE OpFunc1(17, a) LEND 616LET g:OpFunc1Args = [] 617normal! g@l 618call assert_equal([17, 'char'], g:OpFunc1Args) 619 620#" Set 'operatorfunc' to a string(lambda expression) 621LET &opfunc = 'LSTART a LMIDDLE OpFunc1(18, a) LEND' 622LET g:OpFunc1Args = [] 623normal! g@l 624call assert_equal([18, 'char'], g:OpFunc1Args) 625 626#" Set 'operatorfunc' to a variable with a lambda expression 627VAR Lambda = LSTART a LMIDDLE OpFunc1(19, a) LEND 628LET &opfunc = Lambda 629LET g:OpFunc1Args = [] 630normal! g@l 631call assert_equal([19, 'char'], g:OpFunc1Args) 632 633#" Set 'operatorfunc' to a string(variable with a lambda expression) 634LET Lambda = LSTART a LMIDDLE OpFunc1(20, a) LEND 635LET &opfunc = string(Lambda) 636LET g:OpFunc1Args = [] 637normal! g@l 638call assert_equal([20, 'char'], g:OpFunc1Args) 639 640#" Try to use 'operatorfunc' after the function is deleted 641func g:TmpOpFunc1(type) 642let g:TmpOpFunc1Args = [21, a:type] 643endfunc 644LET &opfunc = function('g:TmpOpFunc1') 645delfunc g:TmpOpFunc1 646call test_garbagecollect_now() 647LET g:TmpOpFunc1Args = [] 648call assert_fails('normal! g@l', 'E117:') 649call assert_equal([], g:TmpOpFunc1Args) 650 651#" Try to use a function with two arguments for 'operatorfunc' 652func g:TmpOpFunc2(x, y) 653let g:TmpOpFunc2Args = [a:x, a:y] 654endfunc 655set opfunc=TmpOpFunc2 656LET g:TmpOpFunc2Args = [] 657call assert_fails('normal! g@l', 'E119:') 658call assert_equal([], g:TmpOpFunc2Args) 659delfunc TmpOpFunc2 660 661#" Try to use a lambda function with two arguments for 'operatorfunc' 662LET &opfunc = LSTART a, b LMIDDLE OpFunc1(22, b) LEND 663LET g:OpFunc1Args = [] 664call assert_fails('normal! g@l', 'E119:') 665call assert_equal([], g:OpFunc1Args) 666 667#" Test for clearing the 'operatorfunc' option 668set opfunc='' 669set opfunc& 670call assert_fails("set opfunc=function('abc')", "E700:") 671call assert_fails("set opfunc=funcref('abc')", "E700:") 672 673#" set 'operatorfunc' to a non-existing function 674LET &opfunc = function('g:OpFunc1', [23]) 675call assert_fails("set opfunc=function('NonExistingFunc')", 'E700:') 676call assert_fails("LET &opfunc = function('NonExistingFunc')", 'E700:') 677LET g:OpFunc1Args = [] 678normal! g@l 679call assert_equal([23, 'char'], g:OpFunc1Args) 680END 681call CheckTransLegacySuccess ( lines ) 682 683" Test for using a script-local function name 684func s: OpFunc3 ( type ) 685let g: OpFunc3Args = [ a: type ] 686endfunc 687set opfunc = s:OpFunc3 688let g: OpFunc3Args = [] 689normal ! g@l 690call assert_equal ([ 'char' ], g: OpFunc3Args ) 691 692let & opfunc = 's:OpFunc3' 693let g: OpFunc3Args = [] 694normal ! g@l 695call assert_equal ([ 'char' ], g: OpFunc3Args ) 696delfunc s:OpFunc3 697 698" Using Vim9 lambda expression in legacy context should fail 699set opfunc = (a)\ =>\ OpFunc1(24,\ a) 700let g: OpFunc1Args = [] 701call assert_fails ( 'normal! g@l' , 'E117:' ) 702call assert_equal ([], g: OpFunc1Args ) 703 704" set 'operatorfunc' to a partial with dict. This used to cause a crash. 705func SetOpFunc () 706let operator = { 'execute' : function ( 'OperatorExecute' )} 707let & opfunc = operator . execute 708endfunc 709func OperatorExecute ( _ ) dict 710endfunc 711call SetOpFunc () 712call test_garbagecollect_now () 713set operatorfunc = 714delfunc SetOpFunc 715delfunc OperatorExecute 716 717" Vim9 tests 718let lines =<< trim END 719vim9script 720 721def g:Vim9opFunc(val: number, type: string): void 722g:OpFunc1Args = [val, type] 723enddef 724 725# Test for using a def function with opfunc 726set opfunc=function('g:Vim9opFunc',\ [60]) 727g:OpFunc1Args = [] 728normal! g@l 729assert_equal([60, 'char'], g:OpFunc1Args) 730 731# Test for using a global function name 732&opfunc = g:OpFunc2 733g:OpFunc2Args = [] 734normal! g@l 735assert_equal(['char'], g:OpFunc2Args) 736bw! 737 738# Test for using a script-local function name 739def LocalOpFunc(type: string): void 740g:LocalOpFuncArgs = [type] 741enddef 742&opfunc = LocalOpFunc 743g:LocalOpFuncArgs = [] 744normal! g@l 745assert_equal(['char'], g:LocalOpFuncArgs) 746bw! 747END 748call CheckScriptSuccess ( lines ) 749 750" setting 'opfunc' to a script local function outside of a script context 751" should fail 752let cleanup =<< trim END 753call writefile([execute('messages')], 'Xtest.out') 754qall 755END 756call writefile ( cleanup , 'Xverify.vim' ) 757call RunVim ([], [], "-c \"set opfunc=s:abc\" -S Xverify.vim" ) 758call assert_match ( 'E81: Using <SID> not in a' , readfile ( 'Xtest.out' )[ 0 ]) 759call delete ( 'Xtest.out' ) 760call delete ( 'Xverify.vim' ) 761 762" cleanup 763set opfunc & 764delfunc OpFunc1 765delfunc OpFunc2 766unlet g: OpFunc1Args g: OpFunc2Args 767 %bw ! 768endfunc 769 770func Test_normal10_expand () 771" Test for expand() 77210 new 773call setline ( 1 , [ '1' , 'ifooar,,cbar' ]) 7742 775norm ! $ 776call assert_equal ( 'cbar' , expand ( '<cword>' )) 777call assert_equal ( 'ifooar,,cbar' , expand ( '<cWORD>' )) 778 779call setline ( 1 , [ 'prx = list[idx];' ]) 7801 781let expected = [ '' , 'prx' , 'prx' , 'prx' , 782 \'list' , 'list' , 'list' , 'list' , 'list' , 'list' , 'list' , 783 \'idx' , 'idx' , 'idx' , 'idx' , 784 \'list[idx]' , 785 \'];' , 786 \] 787for i in range ( 1 , 16 ) 788exe 'norm ' . i . '|' 789call assert_equal ( expected [ i ], expand ( '<cexpr>' ), 'i == ' . i ) 790endfor 791 792" Test for <cexpr> in state.val and ptr->val 793call setline ( 1 , 'x = state.val;' ) 794call cursor ( 1 , 10 ) 795call assert_equal ( 'state.val' , expand ( '<cexpr>' )) 796call setline ( 1 , 'x = ptr->val;' ) 797call cursor ( 1 , 9 ) 798call assert_equal ( 'ptr->val' , expand ( '<cexpr>' )) 799 800if executable ( 'echo' ) 801" Test expand(`...`) i.e. backticks command expansion. 802" MS-Windows has a trailing space. 803call assert_match ( '^abcde *$' , expand ( '`echo abcde`' )) 804endif 805 806" Test expand(`=...`) i.e. backticks expression expansion 807call assert_equal ( '5' , expand ( '`=2+3`' )) 808call assert_equal ( '3.14' , expand ( '`=3.14`' )) 809 810" clean up 811bw ! 812endfunc 813 814" Test for expand() in latin1 encoding 815func Test_normal_expand_latin1 () 816new 817let save_enc = & encoding 818" set encoding=latin1 819call setline ( 1 , 'val = item->color;' ) 820call cursor ( 1 , 11 ) 821call assert_equal ( 'color' , expand ( "<cword>" )) 822call assert_equal ( 'item->color' , expand ( "<cexpr>" )) 823let & encoding = save_enc 824bw ! 825endfunc 826 827func Test_normal11_showcmd () 828" test for 'showcmd' 82910 new 830exe "norm! ofoobar\<esc>" 831call assert_equal ( 2 , line ( '$' )) 832set showcmd 833exe "norm! ofoobar2\<esc>" 834call assert_equal ( 3 , line ( '$' )) 835exe "norm! VAfoobar3\<esc>" 836call assert_equal ( 3 , line ( '$' )) 837exe "norm! 0d3\<del>2l" 838call assert_equal ( 'obar2foobar3' , getline ( '.' )) 839" test for the visual block size displayed in the status line 840call setline ( 1 , [ 'aaaaa' , 'bbbbb' , 'ccccc' ]) 841call feedkeys ( "ggl\<C-V>lljj" , 'xt' ) 842redraw ! 843call assert_match ( '3x3$' , Screenline ( & lines )) 844call feedkeys ( "\<C-V>" , 'xt' ) 845" test for visually selecting a multi-byte character 846call setline ( 1 , [ "\U2206" ]) 847call feedkeys ( "ggv" , 'xt' ) 848redraw ! 849call assert_match ( '1-3$' , Screenline ( & lines )) 850call feedkeys ( "v" , 'xt' ) 851" test for visually selecting the end of line 852call setline ( 1 , [ "foobar" ]) 853call feedkeys ( "$vl" , 'xt' ) 854redraw ! 855call assert_match ( '2$' , Screenline ( & lines )) 856call feedkeys ( "y" , 'xt' ) 857call assert_equal ( "r\n" , @") 858bw ! 859endfunc 860 861" Test for nv_error and normal command errors 862func Test_normal12_nv_error () 86310 new 864call setline ( 1 , range ( 1 , 5 )) 865" should not do anything, just beep 866call assert_beeps ( 'exe "norm! <c-k>"' ) 867call assert_equal ( map ( range ( 1 , 5 ), 'string(v:val)' ), getline ( 1 , '$' )) 868call assert_beeps ( 'normal! G2dd' ) 869call assert_beeps ( "normal! g\<C-A>" ) 870call assert_beeps ( "normal! g\<C-X>" ) 871call assert_beeps ( "normal! g\<C-B>" ) 872" call assert_beeps("normal! vQ\<Esc>") 873call assert_beeps ( "normal! 2[[" ) 874call assert_beeps ( "normal! 2]]" ) 875call assert_beeps ( "normal! 2[]" ) 876call assert_beeps ( "normal! 2][" ) 877call assert_beeps ( "normal! 4[z" ) 878call assert_beeps ( "normal! 4]z" ) 879call assert_beeps ( "normal! 4[c" ) 880call assert_beeps ( "normal! 4]c" ) 881call assert_beeps ( "normal! 200%" ) 882call assert_beeps ( "normal! %" ) 883call assert_beeps ( "normal! 2{" ) 884call assert_beeps ( "normal! 2}" ) 885call assert_beeps ( "normal! r\<Right>" ) 886call assert_beeps ( "normal! 8ry" ) 887call assert_beeps ( 'normal! "@' ) 888bw ! 889endfunc 890 891func Test_normal13_help () 892" Test for F1 893call assert_equal ( 1 , winnr ()) 894call feedkeys ( "\<f1>" , 'txi' ) 895call assert_match ( 'help\.txt' , bufname ( '%' )) 896call assert_equal ( 2 , winnr ( '$' )) 897bw ! 898endfunc 899 900func Test_normal14_page () 901" basic test for Ctrl-F and Ctrl-B 902call Setup_NewWindow () 903exe "norm! \<c-f>" 904call assert_equal ( '9' , getline ( '.' )) 905exe "norm! 2\<c-f>" 906call assert_equal ( '25' , getline ( '.' )) 907exe "norm! 2\<c-b>" 908call assert_equal ( '18' , getline ( '.' )) 9091 910set scrolloff = 5 911exe "norm! 2\<c-f>" 912call assert_equal ( '21' , getline ( '.' )) 913exe "norm! \<c-b>" 914call assert_equal ( '13' , getline ( '.' )) 9151 916set scrolloff = 99 917exe "norm! \<c-f>" 918call assert_equal ( '13' , getline ( '.' )) 919set scrolloff = 0 920100 921exe "norm! $\<c-b>" 922call assert_equal ([ 0 , 92 , 1 , 0 , 1 ], getcurpos ()) 923100 924set nostartofline 925exe "norm! $\<c-b>" 926call assert_equal ([ 0 , 92 , 2 , 0 , v: maxcol ], getcurpos ()) 927" cleanup 928set startofline 929bw ! 930endfunc 931 932func Test_normal14_page_eol () 93310 new 934norm oxxxxxxx 935exe "norm 2\<c-f>" 936" check with valgrind that cursor is put back in column 1 937exe "norm 2\<c-b>" 938bw ! 939endfunc 940 941" Test for errors with z command 942func Test_normal_z_error () 943call assert_beeps ( 'normal! z2p' ) 944call assert_beeps ( 'normal! zK' ) 945call assert_beeps ( 'normal! cz1' ) 946endfunc 947 948func Test_normal15_z_scroll_vert () 949" basic test for z commands that scroll the window 950call Setup_NewWindow () 951100 952norm ! >> 953" Test for z<cr> 954exe "norm! z\<cr>" 955call assert_equal ( ' 100' , getline ( '.' )) 956call assert_equal ( 100 , winsaveview ()[ 'topline' ]) 957call assert_equal ([ 0 , 100 , 2 , 0 , 9 ], getcurpos ()) 958 959" Test for zt 96021 961norm ! >>0zt 962call assert_equal ( ' 21' , getline ( '.' )) 963call assert_equal ( 21 , winsaveview ()[ 'topline' ]) 964call assert_equal ([ 0 , 21 , 1 , 0 , 8 ], getcurpos ()) 965 966" Test for zb 96730 968norm ! >>$ztzb 969call assert_equal ( ' 30' , getline ( '.' )) 970call assert_equal ( 30 , winsaveview ()[ 'topline' ] + winheight ( 0 ) - 1 ) 971call assert_equal ([ 0 , 30 , 3 , 0 , v: maxcol ], getcurpos ()) 972 973" Test for z- 9741 97530 976norm ! 0z- 977call assert_equal ( ' 30' , getline ( '.' )) 978call assert_equal ( 30 , winsaveview ()[ 'topline' ] + winheight ( 0 ) - 1 ) 979call assert_equal ([ 0 , 30 , 2 , 0 , 9 ], getcurpos ()) 980 981" Test for z{height}<cr> 982call assert_equal ( 10 , winheight ( 0 )) 983exe "norm! z12\<cr>" 984call assert_equal ( 12 , winheight ( 0 )) 985exe "norm! z15\<Del>0\<cr>" 986call assert_equal ( 10 , winheight ( 0 )) 987 988" Test for z. 9891 99021 991norm ! 0z. 992call assert_equal ( ' 21' , getline ( '.' )) 993call assert_equal ( 17 , winsaveview ()[ 'topline' ]) 994call assert_equal ([ 0 , 21 , 2 , 0 , 9 ], getcurpos ()) 995 996" Test for zz 9971 99821 999norm ! 0zz 1000call assert_equal ( ' 21' , getline ( '.' )) 1001call assert_equal ( 17 , winsaveview ()[ 'topline' ]) 1002call assert_equal ([ 0 , 21 , 1 , 0 , 8 ], getcurpos ()) 1003 1004" Test for z+ 100511 1006norm ! zt 1007norm ! z+ 1008call assert_equal ( ' 21' , getline ( '.' )) 1009call assert_equal ( 21 , winsaveview ()[ 'topline' ]) 1010call assert_equal ([ 0 , 21 , 2 , 0 , 9 ], getcurpos ()) 1011 1012" Test for [count]z+ 10131 1014norm ! 21z+ 1015call assert_equal ( ' 21' , getline ( '.' )) 1016call assert_equal ( 21 , winsaveview ()[ 'topline' ]) 1017call assert_equal ([ 0 , 21 , 2 , 0 , 9 ], getcurpos ()) 1018 1019" Test for z+ with [count] greater than buffer size 10201 1021norm ! 1000z+ 1022call assert_equal ( ' 100' , getline ( '.' )) 1023call assert_equal ( 100 , winsaveview ()[ 'topline' ]) 1024call assert_equal ([ 0 , 100 , 2 , 0 , 9 ], getcurpos ()) 1025 1026" Test for z+ from the last buffer line 1027norm ! Gz.z+ 1028call assert_equal ( ' 100' , getline ( '.' )) 1029call assert_equal ( 100 , winsaveview ()[ 'topline' ]) 1030call assert_equal ([ 0 , 100 , 2 , 0 , 9 ], getcurpos ()) 1031 1032" Test for z^ 1033norm ! 22z+0 1034norm ! z^ 1035call assert_equal ( ' 21' , getline ( '.' )) 1036call assert_equal ( 12 , winsaveview ()[ 'topline' ]) 1037call assert_equal ([ 0 , 21 , 2 , 0 , 9 ], getcurpos ()) 1038 1039" Test for z^ from first buffer line 1040norm ! ggz^ 1041call assert_equal ( '1' , getline ( '.' )) 1042call assert_equal ( 1 , winsaveview ()[ 'topline' ]) 1043call assert_equal ([ 0 , 1 , 1 , 0 , 1 ], getcurpos ()) 1044 1045" Test for [count]z^ 10461 1047norm ! 30z^ 1048call assert_equal ( ' 21' , getline ( '.' )) 1049call assert_equal ( 12 , winsaveview ()[ 'topline' ]) 1050call assert_equal ([ 0 , 21 , 2 , 0 , 9 ], getcurpos ()) 1051 1052" cleanup 1053bw ! 1054endfunc 1055 1056func Test_normal16_z_scroll_hor () 1057" basic test for z commands that scroll the window 105810 new 105915 vsp 1060set nowrap listchars = 1061let lineA = 'abcdefghijklmnopqrstuvwxyz' 1062let lineB = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' 1063$ put =lineA 1064$ put =lineB 10651 d 1066 1067" Test for zl and zh with a count 1068norm ! 0z10l 1069call assert_equal ([ 11 , 1 ], [ col ( '.' ), wincol ()]) 1070norm ! z4h 1071call assert_equal ([ 11 , 5 ], [ col ( '.' ), wincol ()]) 1072normal ! 2gg 1073 1074" Test for zl 10751 1076norm ! 5zl 1077call assert_equal ( lineA , getline ( '.' )) 1078call assert_equal ( 6 , col ( '.' )) 1079call assert_equal ( 5 , winsaveview ()[ 'leftcol' ]) 1080norm ! yl 1081call assert_equal ( 'f' , @0) 1082 1083" Test for zh 1084norm ! 2zh 1085call assert_equal ( lineA , getline ( '.' )) 1086call assert_equal ( 6 , col ( '.' )) 1087norm ! yl 1088call assert_equal ( 'f' , @0) 1089call assert_equal ( 3 , winsaveview ()[ 'leftcol' ]) 1090 1091" Test for zL 1092norm ! zL 1093call assert_equal ( 11 , col ( '.' )) 1094norm ! yl 1095call assert_equal ( 'k' , @0) 1096call assert_equal ( 10 , winsaveview ()[ 'leftcol' ]) 1097norm ! 2zL 1098call assert_equal ( 25 , col ( '.' )) 1099norm ! yl 1100call assert_equal ( 'y' , @0) 1101call assert_equal ( 24 , winsaveview ()[ 'leftcol' ]) 1102 1103" Test for zH 1104norm ! 2zH 1105call assert_equal ( 25 , col ( '.' )) 1106call assert_equal ( 10 , winsaveview ()[ 'leftcol' ]) 1107norm ! yl 1108call assert_equal ( 'y' , @0) 1109 1110" Test for zs 1111norm ! $zs 1112call assert_equal ( 26 , col ( '.' )) 1113call assert_equal ( 25 , winsaveview ()[ 'leftcol' ]) 1114norm ! yl 1115call assert_equal ( 'z' , @0) 1116 1117" Test for ze 1118norm ! ze 1119call assert_equal ( 26 , col ( '.' )) 1120call assert_equal ( 11 , winsaveview ()[ 'leftcol' ]) 1121norm ! yl 1122call assert_equal ( 'z' , @0) 1123 1124" Test for zs and ze with folds 1125 %fold 1126norm ! $zs 1127call assert_equal ( 26 , col ( '.' )) 1128call assert_equal ( 0 , winsaveview ()[ 'leftcol' ]) 1129norm ! yl 1130call assert_equal ( 'z' , @0) 1131norm ! ze 1132call assert_equal ( 26 , col ( '.' )) 1133call assert_equal ( 0 , winsaveview ()[ 'leftcol' ]) 1134norm ! yl 1135call assert_equal ( 'z' , @0) 1136 1137" cleanup 1138set wrap listchars = eol:$ 1139bw ! 1140endfunc 1141 1142func Test_normal17_z_scroll_hor2 () 1143" basic test for z commands that scroll the window 1144" using 'sidescrolloff' setting 114510 new 114620 vsp 1147set nowrap listchars = sidescrolloff = 5 1148let lineA = 'abcdefghijklmnopqrstuvwxyz' 1149let lineB = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' 1150$ put =lineA 1151$ put =lineB 11521 d 1153 1154" Test for zl 11551 1156norm ! 5zl 1157call assert_equal ( lineA , getline ( '.' )) 1158call assert_equal ( 11 , col ( '.' )) 1159call assert_equal ( 5 , winsaveview ()[ 'leftcol' ]) 1160norm ! yl 1161call assert_equal ( 'k' , @0) 1162 1163" Test for zh 1164norm ! 2zh 1165call assert_equal ( lineA , getline ( '.' )) 1166call assert_equal ( 11 , col ( '.' )) 1167norm ! yl 1168call assert_equal ( 'k' , @0) 1169call assert_equal ( 3 , winsaveview ()[ 'leftcol' ]) 1170 1171" Test for zL 1172norm ! 0zL 1173call assert_equal ( 16 , col ( '.' )) 1174norm ! yl 1175call assert_equal ( 'p' , @0) 1176call assert_equal ( 10 , winsaveview ()[ 'leftcol' ]) 1177norm ! 2zL 1178call assert_equal ( 26 , col ( '.' )) 1179norm ! yl 1180call assert_equal ( 'z' , @0) 1181call assert_equal ( 15 , winsaveview ()[ 'leftcol' ]) 1182 1183" Test for zH 1184norm ! 2zH 1185call assert_equal ( 15 , col ( '.' )) 1186call assert_equal ( 0 , winsaveview ()[ 'leftcol' ]) 1187norm ! yl 1188call assert_equal ( 'o' , @0) 1189 1190" Test for zs 1191norm ! $zs 1192call assert_equal ( 26 , col ( '.' )) 1193call assert_equal ( 20 , winsaveview ()[ 'leftcol' ]) 1194norm ! yl 1195call assert_equal ( 'z' , @0) 1196 1197" Test for ze 1198norm ! ze 1199call assert_equal ( 26 , col ( '.' )) 1200call assert_equal ( 11 , winsaveview ()[ 'leftcol' ]) 1201norm ! yl 1202call assert_equal ( 'z' , @0) 1203 1204" cleanup 1205set wrap listchars = eol:$sidescrolloff = 0 1206bw ! 1207endfunc 1208 1209func Test_large_sidescrolloff_no_overflow () 121010 new 121120 vsp 1212setlocal nowrap sidescrolloff = 2147483647 1213call setline ( 1 , repeat ( 'a' , 40 )) 1214 1215normal ! $ 1216redraw ! 1217call assert_equal ( 29 , winsaveview (). leftcol ) 1218 1219normal ! zs 1220redraw ! 1221call assert_equal ( 29 , winsaveview (). leftcol ) 1222 1223normal ! ze 1224redraw ! 1225call assert_equal ( 29 , winsaveview (). leftcol ) 1226 1227normal ! 0 1228redraw ! 1229call assert_equal ( 0 , winsaveview (). leftcol ) 1230 1231bw ! 1232endfunc 1233 1234" Test for commands that scroll the window horizontally. Test with folds. 1235" H, M, L, CTRL-E, CTRL-Y, CTRL-U, CTRL-D, PageUp, PageDown commands 1236func Test_vert_scroll_cmds () 123715 new 1238call setline ( 1 , range ( 1 , 100 )) 1239exe "normal! 30ggz\<CR>" 1240set foldenable 124133 , 36 fold 124240 , 43 fold 124346 , 49 fold 1244let h = winheight ( 0 ) 1245 1246" Test for H, M and L commands 1247" Top of the screen = 30 1248" Folded lines = 9 1249" Bottom of the screen = 30 + h + 9 - 1 1250normal ! 4L 1251call assert_equal ( 35 + h , line ( '.' )) 1252normal ! 4H 1253call assert_equal ( 33 , line ( '.' )) 1254 1255" Test for using a large count value 1256 %d 1257call setline ( 1 , range ( 1 , 4 )) 1258norm ! 6H 1259call assert_equal ( 4 , line ( '.' )) 1260 1261" Test for 'M' with folded lines 1262 %d 1263call setline ( 1 , range ( 1 , 20 )) 12641 , 5 fold 1265norm ! LM 1266call assert_equal ( 12 , line ( '.' )) 1267 1268" Test for the CTRL-E and CTRL-Y commands with folds 1269 %d 1270call setline ( 1 , range ( 1 , 10 )) 12713 , 5 fold 1272exe "normal 6G3\<C-E>" 1273call assert_equal ( 6 , line ( 'w0' )) 1274exe "normal 2\<C-Y>" 1275call assert_equal ( 2 , line ( 'w0' )) 1276 1277" Test for CTRL-Y on a folded line 1278 %d 1279call setline ( 1 , range ( 1 , 100 )) 1280exe ( h + 2 ) .. "," .. ( h + 4 ) .. "fold" 1281exe h + 5 1282normal z- 1283exe "normal \<C-Y>\<C-Y>" 1284call assert_equal ( h + 1 , line ( 'w$' )) 1285 1286" Test for CTRL-Y from the first line and CTRL-E from the last line 1287 %d 1288set scrolloff = 2 1289call setline ( 1 , range ( 1 , 4 )) 1290exe "normal gg\<C-Y>" 1291call assert_equal ( 1 , line ( 'w0' )) 1292call assert_equal ( 1 , line ( '.' )) 1293exe "normal G4\<C-E>\<C-E>" 1294call assert_equal ( 4 , line ( 'w$' )) 1295call assert_equal ( 4 , line ( '.' )) 1296set scrolloff & 1297 1298" Using <PageUp> and <PageDown> in an empty buffer should beep 1299 %d 1300call assert_beeps ( 'exe "normal \<PageUp>"' ) 1301call assert_beeps ( 'exe "normal \<C-B>"' ) 1302call assert_beeps ( 'exe "normal \<PageDown>"' ) 1303call assert_beeps ( 'exe "normal \<C-F>"' ) 1304 1305" Test for <C-U> and <C-D> with fold 1306 %d 1307call setline ( 1 , range ( 1 , 100 )) 130810 , 35 fold 1309set scroll = 10 1310exe "normal \<C-D>" 1311call assert_equal ( 36 , line ( '.' )) 1312exe "normal \<C-D>" 1313call assert_equal ( 46 , line ( '.' )) 1314exe "normal \<C-U>" 1315call assert_equal ( 36 , line ( '.' )) 1316exe "normal \<C-U>" 1317call assert_equal ( 1 , line ( '.' )) 1318exe "normal \<C-U>" 1319call assert_equal ( 1 , line ( '.' )) 1320set scroll & 1321 1322" Test for scrolling to the top of the file with <C-U> and a fold 132310 1324normal ztL 1325exe "normal \<C-U>\<C-U>" 1326call assert_equal ( 1 , line ( 'w0' )) 1327 1328" Test for CTRL-D on a folded line 1329 %d 1330call setline ( 1 , range ( 1 , 100 )) 133150 , 100 fold 133275 1333normal z- 1334exe "normal \<C-D>" 1335call assert_equal ( 50 , line ( '.' )) 1336call assert_equal ( 100 , line ( 'w$' )) 1337normal z. 1338let lnum = winline () 1339exe "normal \<C-D>" 1340call assert_equal ( lnum , winline ()) 1341call assert_equal ( 50 , line ( '.' )) 1342normal zt 1343exe "normal \<C-D>" 1344call assert_equal ( 50 , line ( 'w0' )) 1345 1346" Test for <S-CR>. Page down. 1347 %d 1348call setline ( 1 , range ( 1 , 100 )) 1349call feedkeys ( "\<S-CR>" , 'xt' ) 1350call assert_equal ( 14 , line ( 'w0' )) 1351call assert_equal ( 28 , line ( 'w$' )) 1352 1353" Test for <S-->. Page up. 1354call feedkeys ( "\<S-->" , 'xt' ) 1355call assert_equal ( 1 , line ( 'w0' )) 1356call assert_equal ( 15 , line ( 'w$' )) 1357 1358set foldenable & 1359bwipe ! 1360endfunc 1361 1362func Test_scroll_in_ex_mode () 1363" This was using invalid memory because w_botline was invalid. 1364let lines =<< trim END 1365diffsplit 1366norm os00( 1367call writefile(['done'], 'Xdone') 1368qa! 1369END 1370call writefile ( lines , 'Xscript' , 'D' ) 1371call assert_equal ( 1 , RunVim ([], [], '--clean -X -Z -e -s -S Xscript' )) 1372call assert_equal ([ 'done' ], readfile ( 'Xdone' )) 1373 1374call delete ( 'Xdone' ) 1375endfunc 1376 1377func Test_scroll_and_paste_in_ex_mode () 1378throw 'Skipped: does not work when Nvim is run from :!' 1379" This used to crash because of moving cursor to line 0. 1380let lines =<< trim END 1381v/foo/vi|YY9PYQ 1382v/bar/vi|YY9PYQ 1383v/bar/exe line('.') == 1 ? "vi|Y\<C-B>9PYQ" : "vi|YQ" 1384call writefile(['done'], 'Xdone') 1385qa! 1386END 1387call writefile ( lines , 'Xscript' , 'D' ) 1388call assert_equal ( 1 , RunVim ([], [], '-u NONE -i NONE -n -X -Z -e -s -S Xscript' )) 1389call assert_equal ([ 'done' ], readfile ( 'Xdone' )) 1390 1391call delete ( 'Xdone' ) 1392endfunc 1393 1394" Test for the 'sidescroll' option 1395func Test_sidescroll_opt () 1396new 139720 vnew 1398 1399" scroll by 2 characters horizontally 1400set sidescroll = 2 nowrap 1401call setline ( 1 , repeat ( 'a' , 40 )) 1402normal g$l 1403call assert_equal ( 19 , screenpos ( 0 , 1 , 21 ). col ) 1404normal l 1405call assert_equal ( 20 , screenpos ( 0 , 1 , 22 ). col ) 1406normal g0h 1407call assert_equal ( 2 , screenpos ( 0 , 1 , 2 ). col ) 1408call assert_equal ( 20 , screenpos ( 0 , 1 , 20 ). col ) 1409 1410" when 'sidescroll' is 0, cursor positioned at the center 1411set sidescroll = 0 1412normal g$l 1413call assert_equal ( 11 , screenpos ( 0 , 1 , 21 ). col ) 1414normal g0h 1415call assert_equal ( 10 , screenpos ( 0 , 1 , 10 ). col ) 1416 1417 %bw ! 1418set wrap & sidescroll & 1419endfunc 1420 1421" basic tests for foldopen/folddelete 1422func Test_normal18_z_fold () 1423CheckFeature folding 1424call Setup_NewWindow () 142550 1426setl foldenable fdm = markerfoldlevel = 5 1427 1428call assert_beeps ( 'normal! zj' ) 1429call assert_beeps ( 'normal! zk' ) 1430 1431" Test for zF 1432" First fold 1433norm ! 4zF 1434" check that folds have been created 1435call assert_equal ([ '50/* {{{ */' , '51' , '52' , '53/* }}} */' ], getline ( 50 , 53 )) 1436 1437" Test for zd 143851 1439norm ! 2zF 1440call assert_equal ( 2 , foldlevel ( '.' )) 1441norm ! kzd 1442call assert_equal ([ '50' , '51/* {{{ */' , '52/* }}} */' , '53' ], getline ( 50 , 53 )) 1443norm ! j 1444call assert_equal ( 1 , foldlevel ( '.' )) 1445 1446" Test for zD 1447" also deletes partially selected folds recursively 144851 1449norm ! zF 1450call assert_equal ( 2 , foldlevel ( '.' )) 1451norm ! kV2jzD 1452call assert_equal ([ '50' , '51' , '52' , '53' ], getline ( 50 , 53 )) 1453 1454" Test for zE 145585 1456norm ! 4zF 145786 1458norm ! 2zF 145990 1460norm ! 4zF 1461call assert_equal ([ '85/* {{{ */' , '86/* {{{ */' , '87/* }}} */' , '88/* }}} */' , '89' , '90/* {{{ */' , '91' , '92' , '93/* }}} */' ], getline ( 85 , 93 )) 1462norm ! zE 1463call assert_equal ([ '85' , '86' , '87' , '88' , '89' , '90' , '91' , '92' , '93' ], getline ( 85 , 93 )) 1464 1465" Test for zn 146650 1467set foldlevel = 0 1468norm ! 2zF 1469norm ! zn 1470norm ! k 1471call assert_equal ( '49' , getline ( '.' )) 1472norm ! j 1473call assert_equal ( '50/* {{{ */' , getline ( '.' )) 1474norm ! j 1475call assert_equal ( '51/* }}} */' , getline ( '.' )) 1476norm ! j 1477call assert_equal ( '52' , getline ( '.' )) 1478call assert_equal ( 0 , & foldenable ) 1479 1480" Test for zN 148149 1482norm ! zN 1483call assert_equal ( '49' , getline ( '.' )) 1484norm ! j 1485call assert_equal ( '50/* {{{ */' , getline ( '.' )) 1486norm ! j 1487call assert_equal ( '52' , getline ( '.' )) 1488call assert_equal ( 1 , & foldenable ) 1489 1490" Test for zi 1491norm ! zi 1492call assert_equal ( 0 , & foldenable ) 1493norm ! zi 1494call assert_equal ( 1 , & foldenable ) 1495norm ! zi 1496call assert_equal ( 0 , & foldenable ) 1497norm ! zi 1498call assert_equal ( 1 , & foldenable ) 1499 1500" Test for za 150150 1502norm ! za 1503norm ! k 1504call assert_equal ( '49' , getline ( '.' )) 1505norm ! j 1506call assert_equal ( '50/* {{{ */' , getline ( '.' )) 1507norm ! j 1508call assert_equal ( '51/* }}} */' , getline ( '.' )) 1509norm ! j 1510call assert_equal ( '52' , getline ( '.' )) 151150 1512norm ! za 1513norm ! k 1514call assert_equal ( '49' , getline ( '.' )) 1515norm ! j 1516call assert_equal ( '50/* {{{ */' , getline ( '.' )) 1517norm ! j 1518call assert_equal ( '52' , getline ( '.' )) 1519 152049 1521norm ! 5zF 1522norm ! k 1523call assert_equal ( '48' , getline ( '.' )) 1524norm ! j 1525call assert_equal ( '49/* {{{ */' , getline ( '.' )) 1526norm ! j 1527call assert_equal ( '55' , getline ( '.' )) 152849 1529norm ! za 1530call assert_equal ( '49/* {{{ */' , getline ( '.' )) 1531norm ! j 1532call assert_equal ( '50/* {{{ */' , getline ( '.' )) 1533norm ! j 1534call assert_equal ( '52' , getline ( '.' )) 1535set nofoldenable 1536" close fold and set foldenable 1537norm ! za 1538call assert_equal ( 1 , & foldenable ) 1539 154050 1541" have to use {count}za to open all folds and make the cursor visible 1542norm ! 2za 1543norm ! 2k 1544call assert_equal ( '48' , getline ( '.' )) 1545norm ! j 1546call assert_equal ( '49/* {{{ */' , getline ( '.' )) 1547norm ! j 1548call assert_equal ( '50/* {{{ */' , getline ( '.' )) 1549norm ! j 1550call assert_equal ( '51/* }}} */' , getline ( '.' )) 1551norm ! j 1552call assert_equal ( '52' , getline ( '.' )) 1553 1554" Test for zA 155549 1556set foldlevel = 0 155750 1558norm ! zA 1559norm ! 2k 1560call assert_equal ( '48' , getline ( '.' )) 1561norm ! j 1562call assert_equal ( '49/* {{{ */' , getline ( '.' )) 1563norm ! j 1564call assert_equal ( '50/* {{{ */' , getline ( '.' )) 1565norm ! j 1566call assert_equal ( '51/* }}} */' , getline ( '.' )) 1567norm ! j 1568call assert_equal ( '52' , getline ( '.' )) 1569 1570" zA on an opened fold when foldenable is not set 157150 1572set nofoldenable 1573norm ! zA 1574call assert_equal ( 1 , & foldenable ) 1575norm ! k 1576call assert_equal ( '48' , getline ( '.' )) 1577norm ! j 1578call assert_equal ( '49/* {{{ */' , getline ( '.' )) 1579norm ! j 1580call assert_equal ( '55' , getline ( '.' )) 1581 1582" Test for zc 1583norm ! zE 158450 1585norm ! 2zF 158649 1587norm ! 5zF 1588set nofoldenable 158950 1590" There most likely is a bug somewhere: 1591" https://groups.google.com/d/msg/vim_dev/v2EkfJ_KQjI/u-Cvv94uCAAJ 1592" TODO: Should this only close the inner most fold or both folds? 1593norm ! zc 1594call assert_equal ( 1 , & foldenable ) 1595norm ! k 1596call assert_equal ( '48' , getline ( '.' )) 1597norm ! j 1598call assert_equal ( '49/* {{{ */' , getline ( '.' )) 1599norm ! j 1600call assert_equal ( '55' , getline ( '.' )) 1601set nofoldenable 160250 1603norm ! Vjzc 1604norm ! k 1605call assert_equal ( '48' , getline ( '.' )) 1606norm ! j 1607call assert_equal ( '49/* {{{ */' , getline ( '.' )) 1608norm ! j 1609call assert_equal ( '55' , getline ( '.' )) 1610 1611" Test for zC 1612set nofoldenable 161350 1614norm ! zCk 1615call assert_equal ( '48' , getline ( '.' )) 1616norm ! j 1617call assert_equal ( '49/* {{{ */' , getline ( '.' )) 1618norm ! j 1619call assert_equal ( '55' , getline ( '.' )) 1620 1621" Test for zx 1622" 1) close folds at line 49-54 1623set nofoldenable 162448 1625norm ! zx 1626call assert_equal ( 1 , & foldenable ) 1627norm ! j 1628call assert_equal ( '49/* {{{ */' , getline ( '.' )) 1629norm ! j 1630call assert_equal ( '55' , getline ( '.' )) 1631 1632" 2) do not close fold under cursor 163351 1634set nofoldenable 1635norm ! zx 1636call assert_equal ( 1 , & foldenable ) 1637norm ! 3k 1638call assert_equal ( '48' , getline ( '.' )) 1639norm ! j 1640call assert_equal ( '49/* {{{ */' , getline ( '.' )) 1641norm ! j 1642call assert_equal ( '50/* {{{ */' , getline ( '.' )) 1643norm ! j 1644call assert_equal ( '51/* }}} */' , getline ( '.' )) 1645norm ! j 1646call assert_equal ( '52' , getline ( '.' )) 1647norm ! j 1648call assert_equal ( '53' , getline ( '.' )) 1649norm ! j 1650call assert_equal ( '54/* }}} */' , getline ( '.' )) 1651norm ! j 1652call assert_equal ( '55' , getline ( '.' )) 1653 1654" 3) close one level of folds 165548 1656set nofoldenable 1657set foldlevel = 1 1658norm ! zx 1659call assert_equal ( 1 , & foldenable ) 1660call assert_equal ( '48' , getline ( '.' )) 1661norm ! j 1662call assert_equal ( '49/* {{{ */' , getline ( '.' )) 1663norm ! j 1664call assert_equal ( '50/* {{{ */' , getline ( '.' )) 1665norm ! j 1666call assert_equal ( '52' , getline ( '.' )) 1667norm ! j 1668call assert_equal ( '53' , getline ( '.' )) 1669norm ! j 1670call assert_equal ( '54/* }}} */' , getline ( '.' )) 1671norm ! j 1672call assert_equal ( '55' , getline ( '.' )) 1673 1674" Test for zX 1675" Close all folds 1676set foldlevel = 0 nofoldenable 167750 1678norm ! zX 1679call assert_equal ( 1 , & foldenable ) 1680norm ! k 1681call assert_equal ( '48' , getline ( '.' )) 1682norm ! j 1683call assert_equal ( '49/* {{{ */' , getline ( '.' )) 1684norm ! j 1685call assert_equal ( '55' , getline ( '.' )) 1686 1687" Test for zm 168850 1689set nofoldenable foldlevel = 2 1690norm ! zm 1691call assert_equal ( 1 , & foldenable ) 1692call assert_equal ( 1 , & foldlevel ) 1693norm ! zm 1694call assert_equal ( 0 , & foldlevel ) 1695norm ! zm 1696call assert_equal ( 0 , & foldlevel ) 1697norm ! k 1698call assert_equal ( '48' , getline ( '.' )) 1699norm ! j 1700call assert_equal ( '49/* {{{ */' , getline ( '.' )) 1701norm ! j 1702call assert_equal ( '55' , getline ( '.' )) 1703 1704" Test for zm with a count 170550 1706set foldlevel = 2 1707norm ! 3zm 1708call assert_equal ( 0 , & foldlevel ) 1709call assert_equal ( 49 , foldclosed ( line ( '.' ))) 1710 1711" Test for zM 171248 1713set nofoldenable foldlevel = 99 1714norm ! zM 1715call assert_equal ( 1 , & foldenable ) 1716call assert_equal ( 0 , & foldlevel ) 1717call assert_equal ( '48' , getline ( '.' )) 1718norm ! j 1719call assert_equal ( '49/* {{{ */' , getline ( '.' )) 1720norm ! j 1721call assert_equal ( '55' , getline ( '.' )) 1722 1723" Test for zr 172448 1725set nofoldenable foldlevel = 0 1726norm ! zr 1727call assert_equal ( 0 , & foldenable ) 1728call assert_equal ( 1 , & foldlevel ) 1729set foldlevel = 0 foldenable 1730norm ! zr 1731call assert_equal ( 1 , & foldenable ) 1732call assert_equal ( 1 , & foldlevel ) 1733norm ! zr 1734call assert_equal ( 2 , & foldlevel ) 1735call assert_equal ( '48' , getline ( '.' )) 1736norm ! j 1737call assert_equal ( '49/* {{{ */' , getline ( '.' )) 1738norm ! j 1739call assert_equal ( '50/* {{{ */' , getline ( '.' )) 1740norm ! j 1741call assert_equal ( '51/* }}} */' , getline ( '.' )) 1742norm ! j 1743call assert_equal ( '52' , getline ( '.' )) 1744 1745" Test for zR 174648 1747set nofoldenable foldlevel = 0 1748norm ! zR 1749call assert_equal ( 0 , & foldenable ) 1750call assert_equal ( 2 , & foldlevel ) 1751set foldenable foldlevel = 0 1752norm ! zR 1753call assert_equal ( 1 , & foldenable ) 1754call assert_equal ( 2 , & foldlevel ) 1755call assert_equal ( '48' , getline ( '.' )) 1756norm ! j 1757call assert_equal ( '49/* {{{ */' , getline ( '.' )) 1758norm ! j 1759call assert_equal ( '50/* {{{ */' , getline ( '.' )) 1760norm ! j 1761call assert_equal ( '51/* }}} */' , getline ( '.' )) 1762norm ! j 1763call assert_equal ( '52' , getline ( '.' )) 1764call append ( 50 , [ 'a /* {{{ */' , 'b /* }}} */' ]) 176548 1766call assert_equal ( '48' , getline ( '.' )) 1767norm ! j 1768call assert_equal ( '49/* {{{ */' , getline ( '.' )) 1769norm ! j 1770call assert_equal ( '50/* {{{ */' , getline ( '.' )) 1771norm ! j 1772call assert_equal ( 'a /* {{{ */' , getline ( '.' )) 1773norm ! j 1774call assert_equal ( '51/* }}} */' , getline ( '.' )) 1775norm ! j 1776call assert_equal ( '52' , getline ( '.' )) 177748 1778norm ! zR 1779call assert_equal ( 1 , & foldenable ) 1780call assert_equal ( 3 , & foldlevel ) 1781call assert_equal ( '48' , getline ( '.' )) 1782norm ! j 1783call assert_equal ( '49/* {{{ */' , getline ( '.' )) 1784norm ! j 1785call assert_equal ( '50/* {{{ */' , getline ( '.' )) 1786norm ! j 1787call assert_equal ( 'a /* {{{ */' , getline ( '.' )) 1788norm ! j 1789call assert_equal ( 'b /* }}} */' , getline ( '.' )) 1790norm ! j 1791call assert_equal ( '51/* }}} */' , getline ( '.' )) 1792norm ! j 1793call assert_equal ( '52' , getline ( '.' )) 1794 1795" clean up 1796setl nofoldenable fdm = markerfoldlevel = 0 1797bw ! 1798endfunc 1799 1800func Test_normal20_exmode () 1801" Reading from redirected file doesn't work on MS-Windows 1802CheckNotMSWindows 1803call writefile ([ '1a' , 'foo' , 'bar' , '.' , 'w! Xfile2' , 'q!' ], 'Xscript' ) 1804call writefile ([ '1' , '2' ], 'Xfile' ) 1805call system ( GetVimCommand () .. ' -e -s < Xscript Xfile' ) 1806let a = readfile ( 'Xfile2' ) 1807call assert_equal ([ '1' , 'foo' , 'bar' , '2' ], a ) 1808 1809" clean up 1810for file in [ 'Xfile' , 'Xfile2' , 'Xscript' ] 1811call delete ( file ) 1812endfor 1813bw ! 1814endfunc 1815 1816func Test_normal21_nv_hat () 1817 1818" Edit a fresh file and wipe the buffer list so that there is no alternate 1819" file present. Next, check for the expected command failures. 1820edit Xfoo | %bw 1821call assert_fails ( ':buffer #' , 'E86' ) 1822call assert_fails ( ':execute "normal! \<C-^>"' , 'E23' ) 1823call assert_fails ( "normal i\<C-R>#" , 'E23:' ) 1824 1825" Test for the expected behavior when switching between two named buffers. 1826edit Xfoo |edit Xbar 1827call feedkeys ( "\<C-^>" , 'tx' ) 1828call assert_equal ( 'Xfoo' , fnamemodify ( bufname ( '%' ), ':t' )) 1829call feedkeys ( "\<C-^>" , 'tx' ) 1830call assert_equal ( 'Xbar' , fnamemodify ( bufname ( '%' ), ':t' )) 1831 1832" Test for the expected behavior when only one buffer is named. 1833enew |let l: nr = bufnr ( '%' ) 1834call feedkeys ( "\<C-^>" , 'tx' ) 1835call assert_equal ( 'Xbar' , fnamemodify ( bufname ( '%' ), ':t' )) 1836call feedkeys ( "\<C-^>" , 'tx' ) 1837call assert_equal ( '' , bufname ( '%' )) 1838call assert_equal ( l: nr , bufnr ( '%' )) 1839 1840" Test that no action is taken by "<C-^>" when an operator is pending. 1841edit Xfoo 1842call feedkeys ( "ci\<C-^>" , 'tx' ) 1843call assert_equal ( 'Xfoo' , fnamemodify ( bufname ( '%' ), ':t' )) 1844 1845 %bw ! 1846endfunc 1847 1848func Test_normal22_zet () 1849" Test for ZZ 1850" let shell = &shell 1851" let &shell = 'sh' 1852call writefile ([ '1' , '2' ], 'Xn22file' , 'D' ) 1853let args = ' -N -i NONE --noplugins -X --headless' 1854call system ( GetVimCommand () .. args .. ' -c "%d" -c ":norm! ZZ" Xn22file' ) 1855let a = readfile ( 'Xn22file' ) 1856call assert_equal ([], a ) 1857" Test for ZQ 1858call writefile ([ '1' , '2' ], 'Xn22file' ) 1859call system ( GetVimCommand () . args . ' -c "%d" -c ":norm! ZQ" Xn22file' ) 1860let a = readfile ( 'Xn22file' ) 1861call assert_equal ([ '1' , '2' ], a ) 1862 1863" Unsupported Z command 1864call assert_beeps ( 'normal! ZW' ) 1865 1866" clean up 1867" let &shell = shell 1868endfunc 1869 1870func Test_normal23_K () 1871" Test for K command 1872new 1873call append ( 0 , [ 'helphelp.txt' , 'man' , 'aa%bb' , 'cc|dd' ]) 1874let k = & keywordprg 1875set keywordprg = :help 18761 1877norm ! VK 1878call assert_equal ( 'helphelp.txt' , fnamemodify ( bufname ( '%' ), ':t' )) 1879call assert_equal ( 'help' , & ft ) 1880call assert_match ( '\*helphelp.txt\*' , getline ( '.' )) 1881helpclose 1882norm ! 0K 1883call assert_equal ( 'helphelp.txt' , fnamemodify ( bufname ( '%' ), ':t' )) 1884call assert_equal ( 'help' , & ft ) 1885call assert_match ( 'Help on help files' , getline ( '.' )) 1886helpclose 1887 1888set keywordprg = :new 1889set iskeyword += % 1890set iskeyword += \| 18912 1892norm ! K 1893call assert_equal ( 'man' , fnamemodify ( bufname ( '%' ), ':t' )) 1894bwipe ! 18953 1896norm ! K 1897call assert_equal ( 'aa%bb' , fnamemodify ( bufname ( '%' ), ':t' )) 1898bwipe ! 1899if ! has ( 'win32' ) 19004 1901norm ! K 1902call assert_equal ( 'cc|dd' , fnamemodify ( bufname ( '%' ), ':t' )) 1903bwipe ! 1904endif 1905set iskeyword -= % 1906set iskeyword -= \| 1907 1908" Test for specifying a count to K 19091 1910com ! -nargs = * Kprog let g:Kprog_Args = <q-args> 1911set keywordprg = :Kprog 1912norm ! 3K 1913call assert_equal ( '3 helphelp' , g: Kprog_Args ) 1914delcom Kprog 1915 1916" Only expect "man" to work on Unix 1917if ! has ( "unix" ) || has ( 'nvim' ) " Nvim K uses :terminal. #15398 1918let & keywordprg = k 1919bw ! 1920return 1921endif 1922 1923let not_gnu_man = has ( 'mac' ) || has ( 'bsd' ) 1924if not_gnu_man 1925" In macOS and BSD, the option for specifying a pager is different 1926set keywordprg = man\ -P\ cat 1927else 1928set keywordprg = man\ --pager=cat 1929endif 1930" Test for using man 19312 1932let a = execute ( 'unsilent norm! K' ) 1933if not_gnu_man 1934call assert_match ( "man -P cat 'man'" , a ) 1935else 1936call assert_match ( "man --pager=cat 'man'" , a ) 1937endif 1938 1939" Error cases 1940call setline ( 1 , '#$#' ) 1941call assert_fails ( 'normal! ggK' , 'E349:' ) 1942call setline ( 1 , '---' ) 1943call assert_fails ( 'normal! ggv2lK' , 'E349:' ) 1944call setline ( 1 , [ 'abc' , 'xyz' ]) 1945call assert_fails ( "normal! gg2lv2h\<C-]>" , 'E433:' ) 1946call assert_beeps ( "normal! ggVjK" ) 1947 1948" clean up 1949let & keywordprg = k 1950bw ! 1951endfunc 1952 1953func Test_normal24_rot13 () 1954" Testing for g?? g?g? 1955new 1956call append ( 0 , 'abcdefghijklmnopqrstuvwxyzäüö' ) 19571 1958norm ! g?? 1959call assert_equal ( 'nopqrstuvwxyzabcdefghijklmäüö' , getline ( '.' )) 1960norm ! g?g? 1961call assert_equal ( 'abcdefghijklmnopqrstuvwxyzäüö' , getline ( '.' )) 1962 1963" clean up 1964bw ! 1965endfunc 1966 1967func Test_normal25_tag () 1968CheckFeature quickfix 1969 1970" Testing for CTRL-] g CTRL-] g] 1971" CTRL-W g] CTRL-W CTRL-] CTRL-W g CTRL-] 1972help helphelp 1973" Test for CTRL-] 1974call search ( '\<x\>$' ) 1975exe "norm! \<c-]>" 1976call assert_equal ( "change.txt" , fnamemodify ( bufname ( '%' ), ':t' )) 1977norm ! yiW 1978call assert_equal ( "*x*" , @0) 1979exe ":norm \<c-o>" 1980 1981" Test for g_CTRL-] 1982call search ( '\<v_u\>$' ) 1983exe "norm! g\<c-]>" 1984call assert_equal ( "change.txt" , fnamemodify ( bufname ( '%' ), ':t' )) 1985norm ! yiW 1986call assert_equal ( "*v_u*" , @0) 1987exe ":norm \<c-o>" 1988 1989" Test for g] 1990call search ( '\<i_<Esc>$' ) 1991let a = execute ( ":norm! g]" ) 1992call assert_match ( 'i_<Esc>.*insert.txt' , a ) 1993 1994if ! empty ( exepath ( 'cscope' )) && has ( 'cscope' ) 1995" setting cscopetag changes how g] works 1996set cst 1997exe "norm! g]" 1998call assert_equal ( "insert.txt" , fnamemodify ( bufname ( '%' ), ':t' )) 1999norm ! yiW 2000call assert_equal ( "*i_<Esc>*" , @0) 2001exe ":norm \<c-o>" 2002" Test for CTRL-W g] 2003exe "norm! \<C-W>g]" 2004call assert_equal ( "insert.txt" , fnamemodify ( bufname ( '%' ), ':t' )) 2005norm ! yiW 2006call assert_equal ( "*i_<Esc>*" , @0) 2007call assert_equal ( 3 , winnr ( '$' )) 2008helpclose 2009set nocst 2010endif 2011 2012" Test for CTRL-W g] 2013let a = execute ( "norm! \<C-W>g]" ) 2014call assert_match ( 'i_<Esc>.*insert.txt' , a ) 2015 2016" Test for CTRL-W CTRL-] 2017exe "norm! \<C-W>\<C-]>" 2018call assert_equal ( "insert.txt" , fnamemodify ( bufname ( '%' ), ':t' )) 2019norm ! yiW 2020call assert_equal ( "*i_<Esc>*" , @0) 2021call assert_equal ( 3 , winnr ( '$' )) 2022helpclose 2023 2024" Test for CTRL-W g CTRL-] 2025exe "norm! \<C-W>g\<C-]>" 2026call assert_equal ( "insert.txt" , fnamemodify ( bufname ( '%' ), ':t' )) 2027norm ! yiW 2028call assert_equal ( "*i_<Esc>*" , @0) 2029call assert_equal ( 3 , winnr ( '$' )) 2030helpclose 2031 2032" clean up 2033helpclose 2034endfunc 2035 2036func Test_normal26_put () 2037" Test for ]p ]P [p and [P 2038new 2039call append ( 0 , [ 'while read LINE' , 'do' , ' ((count++))' , ' if [ $? -ne 0 ]; then' , " echo 'Error writing file'" , ' fi' , 'done' ]) 20401 2041/ Error / y a 20422 2043norm ! "a]pj"a[p 2044call assert_equal ([ 'do' , "echo 'Error writing file'" , " echo 'Error writing file'" , ' ((count++))' ], getline ( 2 , 5 )) 20451 2046/ ^\s\{4} / 2047exe "norm! \"a]P3Eldt'" 2048exe "norm! j\"a[P2Eldt'" 2049call assert_equal ([ ' if [ $? -ne 0 ]; then' , " echo 'Error writing'" , " echo 'Error'" , " echo 'Error writing file'" , ' fi' ], getline ( 6 , 10 )) 2050 2051" clean up 2052bw ! 2053endfunc 2054 2055func Test_normal27_bracket () 2056" Test for [' [` ]' ]` 2057call Setup_NewWindow () 20581 , 21 s /.\+/ & b/ 20591 2060norm ! $ma 20615 2062norm ! $mb 206310 2064norm ! $mc 206515 2066norm ! $md 206720 2068norm ! $me 2069 2070" Test for [' 20719 2072norm ! 2[' 2073call assert_equal ( ' 1 b' , getline ( '.' )) 2074call assert_equal ( 1 , line ( '.' )) 2075call assert_equal ( 3 , col ( '.' )) 2076 2077" Test for ]' 2078norm ! ]' 2079call assert_equal ( ' 5 b' , getline ( '.' )) 2080call assert_equal ( 5 , line ( '.' )) 2081call assert_equal ( 3 , col ( '.' )) 2082 2083" No mark before line 1, cursor moves to first non-blank on current line 20841 2085norm ! 5|[' 2086call assert_equal ( ' 1 b' , getline ( '.' )) 2087call assert_equal ( 1 , line ( '.' )) 2088call assert_equal ( 3 , col ( '.' )) 2089 2090" No mark after line 21, cursor moves to first non-blank on current line 209121 2092norm ! 5|]' 2093call assert_equal ( ' 21 b' , getline ( '.' )) 2094call assert_equal ( 21 , line ( '.' )) 2095call assert_equal ( 3 , col ( '.' )) 2096 2097" Test for [` 2098norm ! 2[` 2099call assert_equal ( ' 15 b' , getline ( '.' )) 2100call assert_equal ( 15 , line ( '.' )) 2101call assert_equal ( 8 , col ( '.' )) 2102 2103" Test for ]` 2104norm ! ]` 2105call assert_equal ( ' 20 b' , getline ( '.' )) 2106call assert_equal ( 20 , line ( '.' )) 2107call assert_equal ( 8 , col ( '.' )) 2108 2109" No mark before line 1, cursor does not move 21101 2111norm ! 5|[` 2112call assert_equal ( ' 1 b' , getline ( '.' )) 2113call assert_equal ( 1 , line ( '.' )) 2114call assert_equal ( 5 , col ( '.' )) 2115 2116" No mark after line 21, cursor does not move 211721 2118norm ! 5|]` 2119call assert_equal ( ' 21 b' , getline ( '.' )) 2120call assert_equal ( 21 , line ( '.' )) 2121call assert_equal ( 5 , col ( '.' )) 2122 2123" Count too large for [` 2124" cursor moves to first lowercase mark 2125norm ! 99[` 2126call assert_equal ( ' 1 b' , getline ( '.' )) 2127call assert_equal ( 1 , line ( '.' )) 2128call assert_equal ( 7 , col ( '.' )) 2129 2130" Count too large for ]` 2131" cursor moves to last lowercase mark 2132norm ! 99]` 2133call assert_equal ( ' 20 b' , getline ( '.' )) 2134call assert_equal ( 20 , line ( '.' )) 2135call assert_equal ( 8 , col ( '.' )) 2136 2137" clean up 2138bw ! 2139endfunc 2140 2141" Test for ( and ) sentence movements 2142func Test_normal28_parenthesis () 2143new 2144call append ( 0 , [ 'This is a test. With some sentences!' , '' , 'Even with a question? And one more. And no sentence here' ]) 2145 2146$ 2147norm ! d( 2148call assert_equal ([ 'This is a test. With some sentences!' , '' , 'Even with a question? And one more. ' , '' ], getline ( 1 , '$' )) 2149norm ! 2d( 2150call assert_equal ([ 'This is a test. With some sentences!' , '' , ' ' , '' ], getline ( 1 , '$' )) 21511 2152norm ! 0d) 2153call assert_equal ([ 'With some sentences!' , '' , ' ' , '' ], getline ( 1 , '$' )) 2154 2155call append ( '$' , [ 'This is a long sentence' , '' , 'spanning' , 'over several lines. ' ]) 2156$ 2157norm ! $d( 2158call assert_equal ([ 'With some sentences!' , '' , ' ' , '' , 'This is a long sentence' , '' ], getline ( 1 , '$' )) 2159 2160" Move to the next sentence from a paragraph macro 2161 %d 2162call setline ( 1 , [ '.LP' , 'blue sky!. blue sky.' , 'blue sky. blue sky.' ]) 2163call cursor ( 1 , 1 ) 2164normal ) 2165call assert_equal ([ 2 , 1 ], [ line ( '.' ), col ( '.' )]) 2166normal ) 2167call assert_equal ([ 2 , 12 ], [ line ( '.' ), col ( '.' )]) 2168normal (( 2169call assert_equal ([ 1 , 1 ], [ line ( '.' ), col ( '.' )]) 2170 2171" It is an error if a next sentence is not found 2172 %d 2173call setline ( 1 , '.SH' ) 2174call assert_beeps ( 'normal )' ) 2175 2176" If only dot is present, don't treat that as a sentence 2177call setline ( 1 , '. This is a sentence.' ) 2178normal $(( 2179call assert_equal ( 3 , col ( '.' )) 2180 2181" Jumping to a fold should open the fold 2182call setline ( 1 , [ '' , '' , 'one' , 'two' , 'three' ]) 2183set foldenable 21842 , $ fold 2185call feedkeys ( ')' , 'xt' ) 2186call assert_equal ( 3 , line ( '.' )) 2187call assert_equal ( 1 , foldlevel ( '.' )) 2188call assert_equal ( -1 , foldclosed ( '.' )) 2189set foldenable & 2190 2191" clean up 2192bw ! 2193endfunc 2194 2195" Test for { and } paragraph movements 2196func Test_normal29_brace () 2197let text =<< trim [DATA] 2198A paragraph begins after each empty line, and also at each of a set of 2199paragraph macros, specified by the pairs of characters in the 'paragraphs' 2200option. The default is "IPLPPPQPP TPHPLIPpLpItpplpipbp", which corresponds to 2201the macros ".IP", ".LP", etc. (These are nroff macros, so the dot must be in 2202the first column). A section boundary is also a paragraph boundary. 2203Note that a blank line (only containing white space) is NOT a paragraph 2204boundary. 2205 2206 2207Also note that this does not include a '{' or '}' in the first column. When 2208the '{' flag is in 'cpoptions' then '{' in the first column is used as a 2209paragraph boundary |posix|. 2210{ 2211This is no paragraph 2212unless the '{' is set 2213in 'cpoptions' 2214} 2215.IP 2216The nroff macros IP separates a paragraph 2217That means, it must be a '.' 2218followed by IP 2219.LPIt does not matter, if afterwards some 2220more characters follow. 2221.SHAlso section boundaries from the nroff 2222macros terminate a paragraph. That means 2223a character like this: 2224.NH 2225End of text here 2226[DATA] 2227 2228new 2229call append ( 0 , text ) 22301 2231norm ! 0d2} 2232 2233let expected =<< trim [DATA] 2234.IP 2235The nroff macros IP separates a paragraph 2236That means, it must be a '.' 2237followed by IP 2238.LPIt does not matter, if afterwards some 2239more characters follow. 2240.SHAlso section boundaries from the nroff 2241macros terminate a paragraph. That means 2242a character like this: 2243.NH 2244End of text here 2245 2246[DATA] 2247call assert_equal ( expected , getline ( 1 , '$' )) 2248 2249norm ! 0d} 2250 2251let expected =<< trim [DATA] 2252.LPIt does not matter, if afterwards some 2253more characters follow. 2254.SHAlso section boundaries from the nroff 2255macros terminate a paragraph. That means 2256a character like this: 2257.NH 2258End of text here 2259 2260[DATA] 2261call assert_equal ( expected , getline ( 1 , '$' )) 2262 2263$ 2264norm ! d{ 2265 2266let expected =<< trim [DATA] 2267.LPIt does not matter, if afterwards some 2268more characters follow. 2269.SHAlso section boundaries from the nroff 2270macros terminate a paragraph. That means 2271a character like this: 2272 2273[DATA] 2274call assert_equal ( expected , getline ( 1 , '$' )) 2275 2276norm ! d{ 2277 2278let expected =<< trim [DATA] 2279.LPIt does not matter, if afterwards some 2280more characters follow. 2281 2282[DATA] 2283call assert_equal ( expected , getline ( 1 , '$' )) 2284 2285" Test with { in cpoptions 2286 %d 2287call append ( 0 , text ) 2288" Nvim: no "{" flag in 'cpoptions'. 2289" set cpo+={ 2290" 1 2291" norm! 0d2} 2292 2293let expected =<< trim [DATA] 2294{ 2295This is no paragraph 2296unless the '{' is set 2297in 'cpoptions' 2298} 2299.IP 2300The nroff macros IP separates a paragraph 2301That means, it must be a '.' 2302followed by IP 2303.LPIt does not matter, if afterwards some 2304more characters follow. 2305.SHAlso section boundaries from the nroff 2306macros terminate a paragraph. That means 2307a character like this: 2308.NH 2309End of text here 2310 2311[DATA] 2312" call assert_equal(expected, getline(1, '$')) 2313 2314" $ 2315" norm! d} 2316 2317let expected =<< trim [DATA] 2318{ 2319This is no paragraph 2320unless the '{' is set 2321in 'cpoptions' 2322} 2323.IP 2324The nroff macros IP separates a paragraph 2325That means, it must be a '.' 2326followed by IP 2327.LPIt does not matter, if afterwards some 2328more characters follow. 2329.SHAlso section boundaries from the nroff 2330macros terminate a paragraph. That means 2331a character like this: 2332.NH 2333End of text here 2334 2335[DATA] 2336" call assert_equal(expected, getline(1, '$')) 2337 2338" norm! gg} 2339" norm! d5} 2340 2341let expected =<< trim [DATA] 2342{ 2343This is no paragraph 2344unless the '{' is set 2345in 'cpoptions' 2346} 2347 2348[DATA] 2349" call assert_equal(expected, getline(1, '$')) 2350 2351" Jumping to a fold should open the fold 2352" %d 2353" call setline(1, ['', 'one', 'two', '']) 2354" set foldenable 2355" 2,$fold 2356" call feedkeys('}', 'xt') 2357" call assert_equal(4, line('.')) 2358" call assert_equal(1, foldlevel('.')) 2359" call assert_equal(-1, foldclosed('.')) 2360" set foldenable& 2361 2362" clean up 2363set cpo -= { 2364bw ! 2365endfunc 2366 2367" Test for section movements 2368func Test_normal_section () 2369new 2370let lines =<< trim [END] 2371int foo() 2372{ 2373if (1) 2374{ 2375a = 1; 2376} 2377} 2378[END] 2379call setline ( 1 , lines ) 2380 2381" jumping to a folded line using [[ should open the fold 23822 , 3 fold 2383call cursor ( 5 , 1 ) 2384call feedkeys ( "[[" , 'xt' ) 2385call assert_equal ( 2 , line ( '.' )) 2386call assert_equal ( -1 , foldclosedend ( line ( '.' ))) 2387 2388bwipe ! 2389endfunc 2390 2391" Test for changing case using u, U, gu, gU and ~ (tilde) commands 2392func Test_normal30_changecase () 2393new 2394call append ( 0 , 'This is a simple test: äüöß' ) 2395norm ! 1ggVu 2396call assert_equal ( 'this is a simple test: äüöß' , getline ( '.' )) 2397norm ! VU 2398call assert_equal ( 'THIS IS A SIMPLE TEST: ÄÜÖẞ' , getline ( '.' )) 2399norm ! guu 2400call assert_equal ( 'this is a simple test: äüöß' , getline ( '.' )) 2401norm ! gUgU 2402call assert_equal ( 'THIS IS A SIMPLE TEST: ÄÜÖẞ' , getline ( '.' )) 2403norm ! gugu 2404call assert_equal ( 'this is a simple test: äüöß' , getline ( '.' )) 2405norm ! gUU 2406call assert_equal ( 'THIS IS A SIMPLE TEST: ÄÜÖẞ' , getline ( '.' )) 2407norm ! 010~ 2408call assert_equal ( 'this is a SIMPLE TEST: ÄÜÖẞ' , getline ( '.' )) 2409norm ! V~ 2410call assert_equal ( 'THIS IS A simple test: äüöß' , getline ( '.' )) 2411call assert_beeps ( 'norm! c~' ) 2412 %d 2413call assert_beeps ( 'norm! ~' ) 2414 2415" Test with multiple lines 2416call setline ( 1 , [ 'AA' , 'BBBB' , 'CCCCCC' , 'DDDDDDDD' ]) 2417norm ! ggguG 2418call assert_equal ([ 'aa' , 'bbbb' , 'cccccc' , 'dddddddd' ], getline ( 1 , '$' )) 2419norm ! GgUgg 2420call assert_equal ([ 'AA' , 'BBBB' , 'CCCCCC' , 'DDDDDDDD' ], getline ( 1 , '$' )) 2421 %d 2422 2423" Test for changing case across lines using 'whichwrap' 2424call setline ( 1 , [ 'aaaaaa' , 'aaaaaa' ]) 2425normal ! gg10~ 2426call assert_equal ([ 'AAAAAA' , 'aaaaaa' ], getline ( 1 , 2 )) 2427set whichwrap += ~ 2428normal ! gg10~ 2429call assert_equal ([ 'aaaaaa' , 'AAAAaa' ], getline ( 1 , 2 )) 2430set whichwrap & 2431 2432" try changing the case with a double byte encoding (DBCS) 2433 %bw ! 2434let enc = & enc 2435" set encoding=cp932 2436call setline ( 1 , "\u8470" ) 2437normal ~ 2438normal gU$gu$gUgUg~g~gugu 2439call assert_equal ( "\u8470" , getline ( 1 )) 2440let & encoding = enc 2441 2442" clean up 2443bw ! 2444endfunc 2445 2446" Turkish ASCII turns to multi-byte. On some systems Turkish locale 2447" is available but toupper()/tolower() don't do the right thing. 2448func Test_normal_changecase_turkish () 2449new 2450try 2451lang tr_TR.UTF-8 2452set casemap = 2453let iupper = toupper ( 'i' ) 2454if iupper == "\u0130" 2455call setline ( 1 , 'iI' ) 24561 normal gUU 2457call assert_equal ( "\u0130I" , getline ( 1 )) 2458call assert_equal ( "\u0130I" , toupper ( "iI" )) 2459 2460call setline ( 1 , 'iI' ) 24611 normal guu 2462call assert_equal ( "i\u0131" , getline ( 1 )) 2463call assert_equal ( "i\u0131" , tolower ( "iI" )) 2464elseif iupper == "I" 2465call setline ( 1 , 'iI' ) 24661 normal gUU 2467call assert_equal ( "II" , getline ( 1 )) 2468call assert_equal ( "II" , toupper ( "iI" )) 2469 2470call setline ( 1 , 'iI' ) 24711 normal guu 2472call assert_equal ( "ii" , getline ( 1 )) 2473call assert_equal ( "ii" , tolower ( "iI" )) 2474else 2475call assert_true ( false , "expected toupper('i') to be either 'I' or '\u0131'" ) 2476endif 2477set casemap & 2478call setline ( 1 , 'iI' ) 24791 normal gUU 2480call assert_equal ( "II" , getline ( 1 )) 2481call assert_equal ( "II" , toupper ( "iI" )) 2482 2483call setline ( 1 , 'iI' ) 24841 normal guu 2485call assert_equal ( "ii" , getline ( 1 )) 2486call assert_equal ( "ii" , tolower ( "iI" )) 2487 2488lang en_US.UTF-8 2489catch /E197:/ 2490" can't use Turkish locale 2491throw 'Skipped: Turkish locale not available' 2492endtry 2493 2494bwipe ! 2495endfunc 2496 2497" Test for r (replace) command 2498func Test_normal31_r_cmd () 2499new 2500call append ( 0 , 'This is a simple test: abcd' ) 2501exe "norm! 1gg$r\<cr>" 2502call assert_equal ([ 'This is a simple test: abc' , '' , '' ], getline ( 1 , '$' )) 2503exe "norm! 1gg2wlr\<cr>" 2504call assert_equal ([ 'This is a' , 'simple test: abc' , '' , '' ], getline ( 1 , '$' )) 2505exe "norm! 2gg0W5r\<cr>" 2506call assert_equal ([ 'This is a' , 'simple ' , ' abc' , '' , '' ], getline ( '1' , '$' )) 2507set autoindent 2508call setline ( 2 , [ 'simple test: abc' , '' ]) 2509exe "norm! 2gg0W5r\<cr>" 2510call assert_equal ([ 'This is a' , 'simple ' , 'abc' , '' , '' , '' ], getline ( '1' , '$' )) 2511exe "norm! 1ggVr\<cr>" 2512call assert_equal ( '^M^M^M^M^M^M^M^M^M' , strtrans ( getline ( 1 ))) 2513call setline ( 1 , 'This is a' ) 2514exe "norm! 1gg05rf" 2515call assert_equal ( 'fffffis a' , getline ( 1 )) 2516 2517" When replacing characters, copy characters from above and below lines 2518" using CTRL-Y and CTRL-E. 2519" Different code paths are used for utf-8 and latin1 encodings 2520set showmatch 2521" for enc in ['latin1', 'utf-8'] 2522for enc in [ 'utf-8' ] 2523enew ! 2524let & encoding = enc 2525call setline ( 1 , [ ' {a}' , 'xxxxxxxxxx' , ' [b]' ]) 2526exe "norm! 2gg5r\<C-Y>l5r\<C-E>" 2527call assert_equal ( ' {a}x [b]x' , getline ( 2 )) 2528endfor 2529set showmatch & 2530 2531" r command should fail in operator pending mode 2532call assert_beeps ( 'normal! cr' ) 2533 2534" replace a tab character in visual mode 2535 %d 2536call setline ( 1 , [ "a\tb" , "c\td" , "e\tf" ]) 2537normal gglvjjrx 2538call assert_equal ([ 'axx' , 'xxx' , 'xxf' ], getline ( 1 , '$' )) 2539 2540" replace with a multibyte character (with multiple composing characters) 2541 %d 2542new 2543call setline ( 1 , 'aaa' ) 2544exe "normal $ra\u0328\u0301" 2545call assert_equal ( "aaa\u0328\u0301" , getline ( 1 )) 2546 2547" clean up 2548set noautoindent 2549bw ! 2550endfunc 2551 2552" Test for g*, g# 2553func Test_normal32_g_cmd1 () 2554new 2555call append ( 0 , [ 'abc.x_foo' , 'x_foobar.abc' ]) 25561 2557norm ! $g* 2558call assert_equal ( 'x_foo' , @/) 2559call assert_equal ( 'x_foobar.abc' , getline ( '.' )) 2560norm ! $g# 2561call assert_equal ( 'abc' , @/) 2562call assert_equal ( 'abc.x_foo' , getline ( '.' )) 2563 2564" clean up 2565bw ! 2566endfunc 2567 2568" Test for g`, g;, g,, g&, gv, gk, gj, gJ, g0, g^, g_, gm, g$, gM, g CTRL-G, 2569" gi and gI commands 2570func Test_normal33_g_cmd2 () 2571call Setup_NewWindow () 2572" Test for g` 2573clearjumps 2574norm ! ma10j 2575let a = execute ( ':jumps' ) 2576" empty jumplist 2577call assert_equal ( '>' , a [ -1 :]) 2578norm ! g`a 2579call assert_equal ( '>' , a [ -1 :]) 2580call assert_equal ( 1 , line ( '.' )) 2581call assert_equal ( '1' , getline ( '.' )) 2582call cursor ( 10 , 1 ) 2583norm ! g'a 2584call assert_equal ( '>' , a [ -1 :]) 2585call assert_equal ( 1 , line ( '.' )) 2586let v: errmsg = '' 2587call assert_nobeep ( "normal! g`\<Esc>" ) 2588call assert_equal ( '' , v: errmsg ) 2589call assert_nobeep ( "normal! g'\<Esc>" ) 2590call assert_equal ( '' , v: errmsg ) 2591 2592" Test for g; and g, 2593norm ! g; 2594" there is only one change in the changelist 2595" currently, when we setup the window 2596call assert_equal ( 2 , line ( '.' )) 2597call assert_fails ( ':norm! g;' , 'E662' ) 2598call assert_fails ( ':norm! g,' , 'E663' ) 2599let & ul = & ul 2600call append ( '$' , [ 'a' , 'b' , 'c' , 'd' ]) 2601let & ul = & ul 2602call append ( '$' , [ 'Z' , 'Y' , 'X' , 'W' ]) 2603let a = execute ( ':changes' ) 2604call assert_match ( '2\s\+0\s\+2' , a ) 2605call assert_match ( '101\s\+0\s\+a' , a ) 2606call assert_match ( '105\s\+0\s\+Z' , a ) 2607norm ! 3g; 2608call assert_equal ( 2 , line ( '.' )) 2609norm ! 2g, 2610call assert_equal ( 105 , line ( '.' )) 2611 2612" Test for g& - global substitute 2613 %d 2614call setline ( 1 , range ( 1 , 10 )) 2615call append ( '$' , [ 'a' , 'b' , 'c' , 'd' ]) 2616$ s /\w/&&/g 2617exe "norm! /[1-8]\<cr>" 2618norm ! g& 2619call assert_equal ([ '11' , '22' , '33' , '44' , '55' , '66' , '77' , '88' , '9' , '110' , 'a' , 'b' , 'c' , 'dd' ], getline ( 1 , '$' )) 2620 2621" Jumping to a fold using gg should open the fold 2622set foldenable 2623set foldopen += jump 26245 , 8 fold 2625call feedkeys ( '6gg' , 'xt' ) 2626call assert_equal ( 1 , foldlevel ( '.' )) 2627call assert_equal ( -1 , foldclosed ( '.' )) 2628set foldopen -= jump 2629set foldenable & 2630 2631" Test for gv 2632 %d 2633call append ( '$' , repeat ([ 'abcdefgh' ], 8 )) 2634exe "norm! 2gg02l\<c-v>2j2ly" 2635call assert_equal ([ 'cde' , 'cde' , 'cde' ], getreg ( 0 , 1 , 1 )) 2636" in visual mode, gv swaps current and last selected region 2637exe "norm! G0\<c-v>4k4lgvd" 2638call assert_equal ([ '' , 'abfgh' , 'abfgh' , 'abfgh' , 'abcdefgh' , 'abcdefgh' , 'abcdefgh' , 'abcdefgh' , 'abcdefgh' ], getline ( 1 , '$' )) 2639exe "norm! G0\<c-v>4k4ly" 2640exe "norm! gvood" 2641call assert_equal ([ '' , 'abfgh' , 'abfgh' , 'abfgh' , 'fgh' , 'fgh' , 'fgh' , 'fgh' , 'fgh' ], getline ( 1 , '$' )) 2642" gv works in operator pending mode 2643call assert_nobeep ( 'normal! cgvxyza' ) 2644call assert_equal ([ '' , 'abfgh' , 'abfgh' , 'abfgh' , 'xyza' , 'xyza' , 'xyza' , 'xyza' , 'xyza' ], getline ( 1 , '$' )) 2645exe "norm! ^\<c-v>Gydgv..cgvbc" 2646call assert_equal ([ '' , 'abfgh' , 'abfgh' , 'abfgh' , 'bc' , 'bc' , 'bc' , 'bc' , 'bc' ], getline ( 1 , '$' )) 2647exe "norm! v^GragggUgv" 2648call assert_equal ([ '' , 'abfgh' , 'abfgh' , 'abfgh' , 'bA' , 'AA' , 'AA' , 'AA' , 'Ac' ], getline ( 1 , '$' )) 2649 2650" gv should beep without a previously selected visual area 2651new 2652call assert_beeps ( 'normal! gv' ) 2653close 2654 2655" Test for gk/gj 2656 %d 265715 vsp 2658set wrap listchars = sbr = 2659let lineA = 'abcdefghijklmnopqrstuvwxyz' 2660let lineB = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' 2661let lineC = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' 2662$ put =lineA 2663$ put =lineB 2664 2665norm ! 3gg0dgk 2666call assert_equal ([ '' , 'abcdefghijklmno' , '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' ], getline ( 1 , '$' )) 2667set nu 2668norm ! 3gg0gjdgj 2669call assert_equal ([ '' , 'abcdefghijklmno' , '0123456789AMNOPQRSTUVWXYZ' ], getline ( 1 , '$' )) 2670 2671" Test for gJ 2672norm ! 2gggJ 2673call assert_equal ([ '' , 'abcdefghijklmno0123456789AMNOPQRSTUVWXYZ' ], getline ( 1 , '$' )) 2674call assert_equal ( 16 , col ( '.' )) 2675" shouldn't do anything 2676norm ! 10gJ 2677call assert_equal ( 1 , col ( '.' )) 2678 2679" Test for g0 g^ gm g$ 2680exe "norm! 2gg0gji " 2681call assert_equal ([ '' , 'abcdefghijk lmno0123456789AMNOPQRSTUVWXYZ' ], getline ( 1 , '$' )) 2682norm ! g0yl 2683call assert_equal ( 12 , col ( '.' )) 2684call assert_equal ( ' ' , getreg ( 0 )) 2685norm ! g$yl 2686call assert_equal ( 22 , col ( '.' )) 2687call assert_equal ( '3' , getreg ( 0 )) 2688norm ! gmyl 2689call assert_equal ( 17 , col ( '.' )) 2690call assert_equal ( 'n' , getreg ( 0 )) 2691norm ! g^yl 2692call assert_equal ( 15 , col ( '.' )) 2693call assert_equal ( 'l' , getreg ( 0 )) 2694call assert_beeps ( 'normal 5g$' ) 2695 2696" Test for g$ with double-width character half displayed 2697vsplit 26989 wincmd | 2699setlocal nowrap nonumber 2700call setline ( 2 , 'asdfasdfヨ' ) 27012 2702normal 0g$ 2703call assert_equal ( 8 , col ( '.' )) 270410 wincmd | 2705normal 0g$ 2706call assert_equal ( 9 , col ( '.' )) 2707 2708setlocal signcolumn = yes 270911 wincmd | 2710normal 0g$ 2711call assert_equal ( 8 , col ( '.' )) 271212 wincmd | 2713normal 0g$ 2714call assert_equal ( 9 , col ( '.' )) 2715 2716close 2717 2718" Test for g_ 2719call assert_beeps ( 'normal! 100g_' ) 2720call setline ( 2 , [ ' foo ' , ' foobar ' ]) 2721normal ! 2ggg_ 2722call assert_equal ( 5 , col ( '.' )) 2723normal ! 2g_ 2724call assert_equal ( 8 , col ( '.' )) 2725 2726norm ! 2ggdG 2727$ put =lineC 2728 2729" Test for gM 2730norm ! gMyl 2731call assert_equal ( 73 , col ( '.' )) 2732call assert_equal ( '0' , getreg ( 0 )) 2733" Test for 20gM 2734norm ! 20gMyl 2735call assert_equal ( 29 , col ( '.' )) 2736call assert_equal ( 'S' , getreg ( 0 )) 2737" Test for 60gM 2738norm ! 60gMyl 2739call assert_equal ( 87 , col ( '.' )) 2740call assert_equal ( 'E' , getreg ( 0 )) 2741 2742" Have an odd number of chars in the line 2743norm ! A. 2744call assert_equal ( 145 , col ( '.' )) 2745norm ! gMyl 2746call assert_equal ( 73 , col ( '.' )) 2747call assert_equal ( '0' , getreg ( 0 )) 2748 2749" 'listchars' "eol" should not affect gM behavior 2750setlocal list listchars = eol:$ 2751norm ! $ 2752call assert_equal ( 145 , col ( '.' )) 2753norm ! gMyl 2754call assert_equal ( 73 , col ( '.' )) 2755call assert_equal ( '0' , getreg ( 0 )) 2756setlocal nolist 2757 2758" Test for gM with Tab characters 2759call setline ( '.' , "\ta\tb\tc\td\te\tf" ) 2760norm ! gMyl 2761call assert_equal ( 6 , col ( '.' )) 2762call assert_equal ( "c" , getreg ( 0 )) 2763 2764" Test for g Ctrl-G 2765call setline ( '.' , lineC ) 2766norm ! 60gMyl 2767set ff = unix 2768let a = execute ( ":norm! g\<c-g>" ) 2769call assert_match ( 'Col 87 of 144; Line 2 of 2; Word 1 of 1; Byte 88 of 146' , a ) 2770 2771" Test for gI 2772norm ! gIfoo 2773call assert_equal ([ '' , 'foo0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' ], getline ( 1 , '$' )) 2774 2775" Test for gi 2776wincmd c 2777 %d 2778set tw = 0 2779call setline ( 1 , [ 'foobar' , 'new line' ]) 2780norm ! A next word 2781$ put ='third line' 2782norm ! gi another word 2783call assert_equal ([ 'foobar next word another word' , 'new line' , 'third line' ], getline ( 1 , '$' )) 2784call setline ( 1 , 'foobar' ) 2785normal ! Ggifirst line 2786call assert_equal ( 'foobarfirst line' , getline ( 1 )) 2787" Test gi in 'virtualedit' mode with cursor after the end of the line 2788set virtualedit = all 2789call setline ( 1 , 'foo' ) 2790exe "normal! Abar\<Right>\<Right>\<Right>\<Right>" 2791call setline ( 1 , 'foo' ) 2792normal ! Ggifirst line 2793call assert_equal ( 'foo first line' , getline ( 1 )) 2794set virtualedit & 2795 2796" Test for aborting a g command using CTRL-\ CTRL-G 2797exe "normal! g\<C-\>\<C-G>" 2798call assert_equal ( 'foo first line' , getline ( '.' )) 2799 2800" clean up 2801bw ! 2802endfunc 2803 2804func Test_normal_ex_substitute () 2805throw 'Skipped: Nvim "gQ" restores multicursors (not Ex-mode)' 2806" This was hanging on the substitute prompt. 2807new 2808call setline ( 1 , 'a' ) 2809exe "normal! gggQs/a/b/c\<CR>" 2810call assert_equal ( 'a' , getline ( 1 )) 2811bwipe ! 2812endfunc 2813 2814" Test for g CTRL-G 2815func Test_g_ctrl_g () 2816new 2817 2818let a = execute ( ":norm! g\<c-g>" ) 2819call assert_equal ( "\n--No lines in buffer--" , a ) 2820 2821" Test for CTRL-G (same as :file) 2822let a = execute ( ":norm! \<c-g>" ) 2823call assert_equal ( "\n\n\"[No Name]\" --No lines in buffer--" , a ) 2824 2825call setline ( 1 , [ 'first line' , 'second line' ]) 2826 2827" Test g CTRL-g with dos, mac and unix file type. 2828norm ! gojll 2829set ff = dos 2830let a = execute ( ":norm! g\<c-g>" ) 2831call assert_equal ( "\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 15 of 25" , a ) 2832 2833set ff = mac 2834let a = execute ( ":norm! g\<c-g>" ) 2835call assert_equal ( "\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 14 of 23" , a ) 2836 2837set ff = unix 2838let a = execute ( ":norm! g\<c-g>" ) 2839call assert_equal ( "\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 14 of 23" , a ) 2840 2841" Test g CTRL-g in visual mode (v) 2842let a = execute ( ":norm! gojllvlg\<c-g>" ) 2843call assert_equal ( "\nSelected 1 of 2 Lines; 1 of 4 Words; 2 of 23 Bytes" , a ) 2844 2845" Test g CTRL-g in visual mode (CTRL-V) with end col > start col 2846let a = execute ( ":norm! \<Esc>gojll\<C-V>kllg\<c-g>" ) 2847call assert_equal ( "\nSelected 3 Cols; 2 of 2 Lines; 2 of 4 Words; 6 of 23 Bytes" , a ) 2848 2849" Test g_CTRL-g in visual mode (CTRL-V) with end col < start col 2850let a = execute ( ":norm! \<Esc>goll\<C-V>jhhg\<c-g>" ) 2851call assert_equal ( "\nSelected 3 Cols; 2 of 2 Lines; 2 of 4 Words; 6 of 23 Bytes" , a ) 2852 2853" Test g CTRL-g in visual mode (CTRL-V) with end_vcol being MAXCOL 2854let a = execute ( ":norm! \<Esc>gojll\<C-V>k$g\<c-g>" ) 2855call assert_equal ( "\nSelected 2 of 2 Lines; 4 of 4 Words; 17 of 23 Bytes" , a ) 2856 2857" There should be one byte less with noeol 2858set bin noeol 2859let a = execute ( ":norm! \<Esc>gog\<c-g>" ) 2860call assert_equal ( "\nCol 1 of 10; Line 1 of 2; Word 1 of 4; Char 1 of 23; Byte 1 of 22" , a ) 2861set bin & eol& 2862 2863call setline ( 1 , [ 'Français' , '日本語' ]) 2864 2865let a = execute ( ":norm! \<Esc>gojlg\<c-g>" ) 2866call assert_equal ( "\nCol 4-3 of 9-6; Line 2 of 2; Word 2 of 2; Char 11 of 13; Byte 16 of 20" , a ) 2867 2868let a = execute ( ":norm! \<Esc>gojvlg\<c-g>" ) 2869call assert_equal ( "\nSelected 1 of 2 Lines; 1 of 2 Words; 2 of 13 Chars; 6 of 20 Bytes" , a ) 2870 2871let a = execute ( ":norm! \<Esc>goll\<c-v>jlg\<c-g>" ) 2872call assert_equal ( "\nSelected 4 Cols; 2 of 2 Lines; 2 of 2 Words; 6 of 13 Chars; 11 of 20 Bytes" , a ) 2873 2874set fenc = utf8bomb 2875let a = execute ( ":norm! \<Esc>gojlg\<c-g>" ) 2876call assert_equal ( "\nCol 4-3 of 9-6; Line 2 of 2; Word 2 of 2; Char 11 of 13; Byte 16 of 20(+3 for BOM)" , a ) 2877 2878set fenc = utf16bomb 2879let a = execute ( ":norm! g\<c-g>" ) 2880call assert_equal ( "\nCol 4-3 of 9-6; Line 2 of 2; Word 2 of 2; Char 11 of 13; Byte 16 of 20(+2 for BOM)" , a ) 2881 2882set fenc = utf32bomb 2883let a = execute ( ":norm! g\<c-g>" ) 2884call assert_equal ( "\nCol 4-3 of 9-6; Line 2 of 2; Word 2 of 2; Char 11 of 13; Byte 16 of 20(+4 for BOM)" , a ) 2885 2886set fenc & bomb & 2887 2888set ff & 2889bwipe ! 2890endfunc 2891 2892" Test for g8 2893func Test_normal34_g_cmd3 () 2894new 2895let a = execute ( ':norm! 1G0g8' ) 2896call assert_equal ( "\nNUL" , a ) 2897 2898call setline ( 1 , 'abcdefghijklmnopqrstuvwxyzäüö' ) 2899let a = execute ( ':norm! 1G$g8' ) 2900call assert_equal ( "\nc3 b6 " , a ) 2901 2902call setline ( 1 , "a\u0302" ) 2903let a = execute ( ':norm! 1G0g8' ) 2904call assert_equal ( "\n61 + cc 82 " , a ) 2905 2906" clean up 2907bw ! 2908endfunc 2909 2910" Test 8g8 which finds invalid utf8 at or after the cursor. 2911func Test_normal_8g8 () 2912new 2913 2914" With invalid byte. 2915call setline ( 1 , "___\xff___" ) 2916norm ! 1G08g8g 2917call assert_equal ([ 0 , 1 , 4 , 0 , 4 ], getcurpos ()) 2918 2919" With invalid byte before the cursor. 2920call setline ( 1 , "___\xff___" ) 2921norm ! 1G$h8g8g 2922call assert_equal ([ 0 , 1 , 6 , 0 , 9 ], getcurpos ()) 2923 2924" With truncated sequence. 2925call setline ( 1 , "___\xE2\x82___" ) 2926norm ! 1G08g8g 2927call assert_equal ([ 0 , 1 , 4 , 0 , 4 ], getcurpos ()) 2928 2929" With overlong sequence. 2930call setline ( 1 , "___\xF0\x82\x82\xAC___" ) 2931norm ! 1G08g8g 2932call assert_equal ([ 0 , 1 , 4 , 0 , 4 ], getcurpos ()) 2933 2934" With valid utf8. 2935call setline ( 1 , "café" ) 2936norm ! 1G08g8 2937call assert_equal ([ 0 , 1 , 1 , 0 , 1 ], getcurpos ()) 2938 2939bw ! 2940endfunc 2941 2942" Test for g< 2943func Test_normal35_g_cmd4 () 2944" Cannot capture its output, 2945" probably a bug, therefore, test disabled: 2946throw "Skipped: output of g< can't be tested currently" 2947echo "a\nb\nc\nd" 2948let b = execute ( ':norm! g<' ) 2949call assert_true ( ! empty ( b ), 'failed `execute(g<)`' ) 2950endfunc 2951 2952" Test for gp gP go 2953func Test_normal36_g_cmd5 () 2954new 2955call append ( 0 , 'abcdefghijklmnopqrstuvwxyz' ) 2956set ff = unix 2957" Test for gp gP 2958call append ( 1 , range ( 1 , 10 )) 29591 2960norm ! 1yy 29613 2962norm ! gp 2963call assert_equal ([ 0 , 5 , 1 , 0 , 1 ], getcurpos ()) 2964$ 2965norm ! gP 2966call assert_equal ([ 0 , 14 , 1 , 0 , 1 ], getcurpos ()) 2967 2968" Test for go 2969norm ! 26go 2970call assert_equal ([ 0 , 1 , 26 , 0 , 26 ], getcurpos ()) 2971norm ! 27go 2972call assert_equal ([ 0 , 1 , 26 , 0 , 26 ], getcurpos ()) 2973norm ! 28go 2974call assert_equal ([ 0 , 2 , 1 , 0 , 1 ], getcurpos ()) 2975set ff = dos 2976norm ! 29go 2977call assert_equal ([ 0 , 2 , 1 , 0 , 1 ], getcurpos ()) 2978set ff = unix 2979norm ! gg0 2980norm ! 101go 2981call assert_equal ([ 0 , 13 , 26 , 0 , 26 ], getcurpos ()) 2982norm ! 103go 2983call assert_equal ([ 0 , 14 , 1 , 0 , 1 ], getcurpos ()) 2984" count > buffer content 2985norm ! 120go 2986call assert_equal ([ 0 , 14 , 1 , 0 , v: maxcol ], getcurpos ()) 2987" clean up 2988bw ! 2989endfunc 2990 2991" Test for gt and gT 2992func Test_normal37_g_cmd6 () 2993tabnew 1.txt 2994tabnew 2.txt 2995tabnew 3.txt 2996norm ! 1gt 2997call assert_equal ( 1 , tabpagenr ()) 2998norm ! 3gt 2999call assert_equal ( 3 , tabpagenr ()) 3000norm ! 1gT 3001" count gT goes not to the absolute tabpagenumber 3002" but, but goes to the count previous tabpagenumber 3003call assert_equal ( 2 , tabpagenr ()) 3004" wrap around 3005norm ! 3gT 3006call assert_equal ( 3 , tabpagenr ()) 3007" gt does not wrap around 3008norm ! 5gt 3009call assert_equal ( 3 , tabpagenr ()) 3010 3011for i in range ( 3 ) 3012tabclose 3013endfor 3014" clean up 3015call assert_fails ( ':tabclose' , 'E784:' ) 3016endfunc 3017 3018" Test for <Home> and <C-Home> key 3019func Test_normal38_nvhome () 3020new 3021call setline ( 1 , range ( 10 )) 3022$ 3023setl et sw = 2 3024norm ! V10>$ 3025" count is ignored 3026exe "norm! 10\<home>" 3027call assert_equal ( 1 , col ( '.' )) 3028exe "norm! \<home>" 3029call assert_equal ([ 0 , 10 , 1 , 0 , 1 ], getcurpos ()) 3030exe "norm! 5\<c-home>" 3031call assert_equal ([ 0 , 5 , 1 , 0 , 1 ], getcurpos ()) 3032exe "norm! \<c-home>" 3033call assert_equal ([ 0 , 1 , 1 , 0 , 1 ], getcurpos ()) 3034exe "norm! G\<c-kHome>" 3035call assert_equal ([ 0 , 1 , 1 , 0 , 1 ], getcurpos ()) 3036 3037" clean up 3038bw ! 3039endfunc 3040 3041" Test for <End> and <C-End> keys 3042func Test_normal_nvend () 3043new 3044call setline ( 1 , map ( range ( 1 , 10 ), '"line" .. v:val' )) 3045exe "normal! \<End>" 3046call assert_equal ( 5 , col ( '.' )) 3047exe "normal! 4\<End>" 3048call assert_equal ([ 4 , 5 ], [ line ( '.' ), col ( '.' )]) 3049exe "normal! \<C-End>" 3050call assert_equal ([ 10 , 6 ], [ line ( '.' ), col ( '.' )]) 3051 3052bwipe ! 3053endfunc 3054 3055" Test for cw cW ce 3056func Test_normal39_cw () 3057" Test for cw and cW on whitespace 3058new 3059set tw = 0 3060call append ( 0 , 'here are some words' ) 3061norm ! 1gg0elcwZZZ 3062call assert_equal ( 'hereZZZare some words' , getline ( '.' )) 3063norm ! 1gg0elcWYYY 3064call assert_equal ( 'hereZZZareYYYsome words' , getline ( '.' )) 3065norm ! 2gg0cwfoo 3066call assert_equal ( 'foo' , getline ( '.' )) 3067 3068call setline ( 1 , 'one; two' ) 3069call cursor ( 1 , 1 ) 3070call feedkeys ( 'cwvim' , 'xt' ) 3071call assert_equal ( 'vim; two' , getline ( 1 )) 3072call feedkeys ( '0cWone' , 'xt' ) 3073call assert_equal ( 'one two' , getline ( 1 )) 3074"When cursor is at the end of a word 'ce' will change until the end of the 3075"next word, but 'cw' will change only one character 3076call setline ( 1 , 'one two' ) 3077call feedkeys ( '0ecwce' , 'xt' ) 3078call assert_equal ( 'once two' , getline ( 1 )) 3079call setline ( 1 , 'one two' ) 3080call feedkeys ( '0ecely' , 'xt' ) 3081call assert_equal ( 'only' , getline ( 1 )) 3082 3083" clean up 3084bw ! 3085endfunc 3086 3087" Test for CTRL-\ commands 3088func Test_normal40_ctrl_bsl () 3089" Nvim #40312: includes a cmdwin assertion that doesn't translate 3090" (cmdwin is now a normal window so CTRL-\ CTRL-N is a no-op there). 3091throw 'Skipped: Nvim supports cmdwin freedom #40312' 3092new 3093call append ( 0 , 'here are some words' ) 3094exe "norm! 1gg0a\<C-\>\<C-N>" 3095call assert_equal ( 'n' , mode ()) 3096call assert_equal ( 1 , col ( '.' )) 3097call assert_equal ( '' , visualmode ()) 3098exe "norm! 1gg0viw\<C-\>\<C-N>" 3099call assert_equal ( 'n' , mode ()) 3100call assert_equal ( 4 , col ( '.' )) 3101exe "norm! 1gg0a\<C-\>\<C-G>" 3102call assert_equal ( 'n' , mode ()) 3103call assert_equal ( 1 , col ( '.' )) 3104"imap <buffer> , <c-\><c-n> 3105" set im 3106exe ":norm! \<c-\>\<c-n>dw" 3107" set noim 3108call assert_equal ( 'are some words' , getline ( 1 )) 3109call assert_false ( & insertmode ) 3110call assert_beeps ( "normal! \<C-\>\<C-A>" ) 3111 3112" Using CTRL-\ CTRL-N in cmd window should close the window 3113call feedkeys ( "q:\<C-\>\<C-N>" , 'xt' ) 3114call assert_equal ( '' , getcmdwintype ()) 3115 3116" clean up 3117bw ! 3118endfunc 3119 3120" Test for <c-r>=, <c-r><c-r>= and <c-r><c-o>= in insert mode 3121func Test_normal41_insert_reg () 3122new 3123set sts = 2 sw = 2 ts = 8 tw = 0 3124call append ( 0 , [ "aaa\tbbb\tccc" , '' , '' , '' ]) 3125let a = getline ( 1 ) 3126norm ! 2gg0 3127exe "norm! a\<c-r>=a\<cr>" 3128norm ! 3gg0 3129exe "norm! a\<c-r>\<c-r>=a\<cr>" 3130norm ! 4gg0 3131exe "norm! a\<c-r>\<c-o>=a\<cr>" 3132call assert_equal ([ 'aaa bbb ccc' , 'aaa bbb ccc' , 'aaa bbb ccc' , 'aaa bbb ccc' , '' ], getline ( 1 , '$' )) 3133 3134" clean up 3135set sts = 0 sw = 8 ts = 8 3136bw ! 3137endfunc 3138 3139" Test for Ctrl-D and Ctrl-U 3140func Test_normal42_halfpage () 3141call Setup_NewWindow () 3142call assert_equal ( 5 , & scroll ) 3143exe "norm! \<c-d>" 3144call assert_equal ( '6' , getline ( '.' )) 3145exe "norm! 2\<c-d>" 3146call assert_equal ( '8' , getline ( '.' )) 3147call assert_equal ( 2 , & scroll ) 3148set scroll = 5 3149exe "norm! \<c-u>" 3150call assert_equal ( '3' , getline ( '.' )) 31511 3152set scrolloff = 5 3153exe "norm! \<c-d>" 3154call assert_equal ( '10' , getline ( '.' )) 3155exe "norm! \<c-u>" 3156call assert_equal ( '5' , getline ( '.' )) 31571 3158set scrolloff = 99 3159exe "norm! \<c-d>" 3160call assert_equal ( '10' , getline ( '.' )) 3161set scrolloff = 0 3162100 3163exe "norm! $\<c-u>" 3164call assert_equal ( '95' , getline ( '.' )) 3165call assert_equal ([ 0 , 95 , 1 , 0 , 1 ], getcurpos ()) 3166100 3167set nostartofline 3168exe "norm! $\<c-u>" 3169call assert_equal ( '95' , getline ( '.' )) 3170call assert_equal ([ 0 , 95 , 2 , 0 , v: maxcol ], getcurpos ()) 3171" cleanup 3172set startofline 3173bw ! 3174endfunc 3175 3176func Test_normal45_drop () 3177if ! has ( 'dnd' ) 3178" The ~ register does not exist 3179call assert_beeps ( 'norm! "~' ) 3180return 3181endif 3182 3183" basic test for drag-n-drop 3184" unfortunately, without a gui, we can't really test much here, 3185" so simply test that ~p fails (which uses the drop register) 3186new 3187call assert_fails ( ':norm! "~p' , 'E353' ) 3188call assert_equal ([], getreg ( '~' , 1 , 1 )) 3189" the ~ register is read only 3190call assert_fails ( ':let @~="1"' , 'E354' ) 3191bw ! 3192endfunc 3193 3194func Test_normal46_ignore () 3195new 3196" How to test this? 3197" let's just for now test, that the buffer 3198" does not change 3199call feedkeys ( "\<c-s>" , 't' ) 3200call assert_equal ([ '' ], getline ( 1 , '$' )) 3201 3202" no valid commands 3203exe "norm! \<char-0x100>" 3204call assert_equal ([ '' ], getline ( 1 , '$' )) 3205 3206exe "norm! ä" 3207call assert_equal ([ '' ], getline ( 1 , '$' )) 3208 3209" clean up 3210bw ! 3211endfunc 3212 3213func Test_normal47_visual_buf_wipe () 3214" This was causing a crash or ml_get error. 3215enew ! 3216call setline ( 1 , 'xxx' ) 3217normal $ 3218new 3219call setline ( 1 , range ( 1 , 2 )) 32202 3221exe "norm \<C-V>$" 3222bw ! 3223norm yp 3224set nomodified 3225endfunc 3226 3227func Test_normal48_wincmd () 3228new 3229exe "norm! \<c-w>c" 3230call assert_equal ( 1 , winnr ( '$' )) 3231call assert_fails ( ":norm! \<c-w>c" , "E444" ) 3232endfunc 3233 3234func Test_normal49_counts () 3235new 3236call setline ( 1 , 'one two three four five six seven eight nine ten' ) 32371 3238norm ! 3d2w 3239call assert_equal ( 'seven eight nine ten' , getline ( 1 )) 3240bw ! 3241endfunc 3242 3243func Test_normal50_commandline () 3244CheckFeature timers 3245CheckFeature cmdline_hist 3246 3247func ! DoTimerWork ( id ) 3248call assert_equal ( 1 , getbufinfo ( '' )[ 0 ]. command ) 3249 3250" Nvim removed the E11 "Invalid in command-line window" restriction (#40312, #40484). 3251"call assert_fails(":wincmd p", 'E11') 3252 3253" Return from commandline window. 3254call feedkeys ( "\<CR>" , 't' ) 3255endfunc 3256 3257let oldlang = v: lang 3258lang C 3259set updatetime = 20 3260call timer_start ( 100 , 'DoTimerWork' ) 3261try 3262" throws E23, for whatever reason... 3263call feedkeys ( 'q:' , 'x!' ) 3264catch /E23/ 3265" no-op 3266endtry 3267 3268" clean up 3269delfunc DoTimerWork 3270set updatetime = 4000 3271exe "lang" oldlang 3272bw ! 3273endfunc 3274 3275func Test_normal51_FileChangedRO () 3276CheckFeature autocmd 3277call writefile ([ 'foo' ], 'Xreadonly.log' ) 3278new Xreadonly.log 3279setl ro 3280au FileChangedRO <buffer> : call feedkeys ( "\<c-^>" , 'tix' ) 3281call assert_fails ( ":norm! Af" , 'E788' ) 3282call assert_equal ([ 'foo' ], getline ( 1 , '$' )) 3283call assert_equal ( 'Xreadonly.log' , bufname ( '' )) 3284 3285" cleanup 3286bw ! 3287call delete ( "Xreadonly.log" ) 3288endfunc 3289 3290func Test_normal52_rl () 3291CheckFeature rightleft 3292new 3293call setline ( 1 , 'abcde fghij klmnopq' ) 3294norm ! 1gg$ 3295set rl 3296call assert_equal ( 19 , col ( '.' )) 3297call feedkeys ( 'l' , 'tx' ) 3298call assert_equal ( 18 , col ( '.' )) 3299call feedkeys ( 'h' , 'tx' ) 3300call assert_equal ( 19 , col ( '.' )) 3301call feedkeys ( "\<right>" , 'tx' ) 3302call assert_equal ( 18 , col ( '.' )) 3303call feedkeys ( "\<left>" , 'tx' ) 3304call assert_equal ( 19 , col ( '.' )) 3305call feedkeys ( "\<s-right>" , 'tx' ) 3306call assert_equal ( 13 , col ( '.' )) 3307call feedkeys ( "\<c-right>" , 'tx' ) 3308call assert_equal ( 7 , col ( '.' )) 3309call feedkeys ( "\<c-left>" , 'tx' ) 3310call assert_equal ( 13 , col ( '.' )) 3311call feedkeys ( "\<s-left>" , 'tx' ) 3312call assert_equal ( 19 , col ( '.' )) 3313call feedkeys ( "<<" , 'tx' ) 3314call assert_equal ( ' abcde fghij klmnopq' , getline ( 1 )) 3315call feedkeys ( ">>" , 'tx' ) 3316call assert_equal ( 'abcde fghij klmnopq' , getline ( 1 )) 3317 3318" cleanup 3319set norl 3320bw ! 3321endfunc 3322 3323func Test_normal54_Ctrl_bsl () 3324new 3325call setline ( 1 , 'abcdefghijklmn' ) 3326exe "norm! df\<c-\>\<c-n>" 3327call assert_equal ([ 'abcdefghijklmn' ], getline ( 1 , '$' )) 3328exe "norm! df\<c-\>\<c-g>" 3329call assert_equal ([ 'abcdefghijklmn' ], getline ( 1 , '$' )) 3330exe "norm! df\<c-\>m" 3331call assert_equal ([ 'abcdefghijklmn' ], getline ( 1 , '$' )) 3332 3333call setline ( 2 , 'abcdefghijklmnāf' ) 3334norm ! 2gg0 3335exe "norm! df\<Char-0x101>" 3336call assert_equal ([ 'abcdefghijklmn' , 'f' ], getline ( 1 , '$' )) 3337norm ! 1gg0 3338exe "norm! df\<esc>" 3339call assert_equal ([ 'abcdefghijklmn' , 'f' ], getline ( 1 , '$' )) 3340 3341" clean up 3342bw ! 3343endfunc 3344 3345func Test_normal_large_count () 3346" This may fail with 32bit long, how do we detect that? 3347new 3348normal o 3349normal 6666666666dL 3350bwipe ! 3351endfunc 3352 3353func Test_delete_until_paragraph () 3354new 3355normal grádv} 3356call assert_equal ( 'á' , getline ( 1 )) 3357normal grád} 3358call assert_equal ( '' , getline ( 1 )) 3359bwipe ! 3360endfunc 3361 3362" Test for the gr (virtual replace) command 3363func Test_gr_command () 3364enew ! 3365" Test for the bug fixed by 7.4.387 3366let save_cpo = & cpo 3367call append ( 0 , [ 'First line' , 'Second line' , 'Third line' ]) 3368exe "normal i\<C-G>u" 3369call cursor ( 2 , 1 ) 3370set cpo -= X 3371normal 4gro 3372call assert_equal ( 'oooond line' , getline ( 2 )) 3373undo 3374set cpo += X 3375normal 4gro 3376call assert_equal ( 'ooooecond line' , getline ( 2 )) 3377let & cpo = save_cpo 3378 3379normal ! ggvegrx 3380call assert_equal ( 'xxxxx line' , getline ( 1 )) 3381exe "normal! gggr\<C-V>122" 3382call assert_equal ( 'zxxxx line' , getline ( 1 )) 3383 3384set virtualedit = all 3385normal ! 15|grl 3386call assert_equal ( 'zxxxx line l' , getline ( 1 )) 3387set virtualedit & 3388set nomodifiable 3389call assert_fails ( 'normal! grx' , 'E21:' ) 3390call assert_fails ( 'normal! gRx' , 'E21:' ) 3391call assert_nobeep ( "normal! gr\<Esc>" ) 3392set modifiable & 3393 3394call assert_nobeep ( "normal! gr\<Esc>" ) 3395call assert_nobeep ( "normal! cgr\<Esc>" ) 3396call assert_beeps ( "normal! cgrx" ) 3397 3398call assert_equal ( 'zxxxx line l' , getline ( 1 )) 3399exe "normal! 2|gr\<C-V>\<Esc>" 3400call assert_equal ( "z\<Esc>xx line l" , getline ( 1 )) 3401 3402call setline ( 1 , 'abcdef' ) 3403exe "normal! 0gr\<C-O>lx" 3404call assert_equal ( "\<C-O>def" , getline ( 1 )) 3405 3406call setline ( 1 , 'abcdef' ) 3407exe "normal! 0gr\<C-G>lx" 3408call assert_equal ( "\<C-G>def" , getline ( 1 )) 3409 3410bwipe ! 3411endfunc 3412 3413func Test_nv_hat_count () 3414 %bwipeout ! 3415let l: nr = bufnr ( '%' ) + 1 3416call assert_fails ( ':execute "normal! ' . l: nr . '\<C-^>"' , 'E92:' ) 3417 3418edit Xfoo 3419let l: foo_nr = bufnr ( 'Xfoo' ) 3420 3421edit Xbar 3422let l: bar_nr = bufnr ( 'Xbar' ) 3423 3424" Make sure we are not just using the alternate file. 3425edit Xbaz 3426 3427call feedkeys ( l: foo_nr . "\<C-^>" , 'tx' ) 3428call assert_equal ( 'Xfoo' , fnamemodify ( bufname ( '%' ), ':t' )) 3429 3430call feedkeys ( l: bar_nr . "\<C-^>" , 'tx' ) 3431call assert_equal ( 'Xbar' , fnamemodify ( bufname ( '%' ), ':t' )) 3432 3433 %bwipeout ! 3434endfunc 3435 3436func Test_message_when_using_ctrl_c () 3437" Make sure no buffers are changed. 3438 %bwipe ! 3439 3440exe "normal \<C-C>" 3441call assert_match ( "Type :qa and press <Enter> to exit Nvim" , Screenline ( & lines )) 3442 3443new 3444cal setline ( 1 , 'hi!' ) 3445exe "normal \<C-C>" 3446call assert_match ( "Type :qa! and press <Enter> to abandon all changes and exit Nvim" , Screenline ( & lines )) 3447 3448bwipe ! 3449endfunc 3450 3451func Test_mode_updated_after_ctrl_c () 3452CheckScreendump 3453 3454let buf = RunVimInTerminal ( '' , { 'rows' : 5 }) 3455call term_sendkeys ( buf , "i" ) 3456call term_sendkeys ( buf , "\<C-O>" ) 3457" wait a moment so that the "-- (insert) --" message is displayed 3458call TermWait ( buf , 50 ) 3459call term_sendkeys ( buf , "\<C-C>" ) 3460call VerifyScreenDump ( buf , 'Test_mode_updated_1' , {}) 3461 3462call StopVimInTerminal ( buf ) 3463endfunc 3464 3465" Test for '[m', ']m', '[M' and ']M' 3466" Jumping to beginning and end of methods in Java-like languages 3467func Test_java_motion () 3468new 3469call assert_beeps ( 'normal! [m' ) 3470call assert_beeps ( 'normal! ]m' ) 3471call assert_beeps ( 'normal! [M' ) 3472call assert_beeps ( 'normal! ]M' ) 3473let lines =<< trim [CODE] 3474Piece of Java 3475{ 3476tt m1 { 3477t1; 3478} e1 3479 3480tt m2 { 3481t2; 3482} e2 3483 3484tt m3 { 3485if (x) 3486{ 3487t3; 3488} 3489} e3 3490} 3491[CODE] 3492call setline ( 1 , lines ) 3493 3494normal gg 3495 3496normal 2]maA 3497call assert_equal ( "\ttt m1 {A" , getline ( '.' )) 3498call assert_equal ([ 3 , 9 , 16 ], [ line ( '.' ), col ( '.' ), virtcol ( '.' )]) 3499 3500normal j]maB 3501call assert_equal ( "\ttt m2 {B" , getline ( '.' )) 3502call assert_equal ([ 7 , 9 , 16 ], [ line ( '.' ), col ( '.' ), virtcol ( '.' )]) 3503 3504normal ]maC 3505call assert_equal ( "\ttt m3 {C" , getline ( '.' )) 3506call assert_equal ([ 11 , 9 , 16 ], [ line ( '.' ), col ( '.' ), virtcol ( '.' )]) 3507 3508normal [maD 3509call assert_equal ( "\ttt m3 {DC" , getline ( '.' )) 3510call assert_equal ([ 11 , 9 , 16 ], [ line ( '.' ), col ( '.' ), virtcol ( '.' )]) 3511 3512normal k2[maE 3513call assert_equal ( "\ttt m1 {EA" , getline ( '.' )) 3514call assert_equal ([ 3 , 9 , 16 ], [ line ( '.' ), col ( '.' ), virtcol ( '.' )]) 3515 3516normal 3[maF 3517call assert_equal ( "{F" , getline ( '.' )) 3518call assert_equal ([ 2 , 2 , 2 ], [ line ( '.' ), col ( '.' ), virtcol ( '.' )]) 3519 3520normal ]MaG 3521call assert_equal ( "\t}G e1" , getline ( '.' )) 3522call assert_equal ([ 5 , 3 , 10 ], [ line ( '.' ), col ( '.' ), virtcol ( '.' )]) 3523 3524normal j2]MaH 3525call assert_equal ( "\t}H e3" , getline ( '.' )) 3526call assert_equal ([ 16 , 3 , 10 ], [ line ( '.' ), col ( '.' ), virtcol ( '.' )]) 3527 3528normal ]M]M 3529normal aI 3530call assert_equal ( "}I" , getline ( '.' )) 3531call assert_equal ([ 17 , 2 , 2 ], [ line ( '.' ), col ( '.' ), virtcol ( '.' )]) 3532 3533normal 2[MaJ 3534call assert_equal ( "\t}JH e3" , getline ( '.' )) 3535call assert_equal ([ 16 , 3 , 10 ], [ line ( '.' ), col ( '.' ), virtcol ( '.' )]) 3536 3537normal k[MaK 3538call assert_equal ( "\t}K e2" , getline ( '.' )) 3539call assert_equal ([ 9 , 3 , 10 ], [ line ( '.' ), col ( '.' ), virtcol ( '.' )]) 3540 3541normal 3[MaL 3542call assert_equal ( "{LF" , getline ( '.' )) 3543call assert_equal ([ 2 , 2 , 2 ], [ line ( '.' ), col ( '.' ), virtcol ( '.' )]) 3544 3545call cursor ( 2 , 1 ) 3546call assert_beeps ( 'norm! 5]m' ) 3547 3548" jumping to a method in a fold should open the fold 35496 , 10 fold 3550call feedkeys ( "gg3]m" , 'xt' ) 3551call assert_equal ([ 7 , 8 , 15 ], [ line ( '.' ), col ( '.' ), virtcol ( '.' )]) 3552call assert_equal ( -1 , foldclosedend ( 7 )) 3553 3554bwipe ! 3555endfunc 3556 3557" Tests for g cmds 3558func Test_normal_gdollar_cmd () 3559call Setup_NewWindow () 3560" Make long lines that will wrap 3561 %s /$/\=repeat(' foobar', 10)/ 356220 vsp 3563set wrap 3564" Test for g$ with count 3565norm ! gg 3566norm ! 0vg$y 3567call assert_equal ( 20 , col ( "'>" )) 3568call assert_equal ( '1 foobar foobar foob' , getreg ( 0 )) 3569norm ! gg 3570norm ! 0v4g$y 3571call assert_equal ( 72 , col ( "'>" )) 3572call assert_equal ( '1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar' .. "\n" , getreg ( 0 )) 3573norm ! gg 3574norm ! 0v6g$y 3575call assert_equal ( 40 , col ( "'>" )) 3576call assert_equal ( '1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar' .. "\n" .. 3577 \'2 foobar foobar foobar foobar foobar foo' , getreg ( 0 )) 3578set nowrap 3579" clean up 3580norm ! gg 3581norm ! 0vg$y 3582call assert_equal ( 20 , col ( "'>" )) 3583call assert_equal ( '1 foobar foobar foob' , getreg ( 0 )) 3584norm ! gg 3585norm ! 0v4g$y 3586call assert_equal ( 20 , col ( "'>" )) 3587call assert_equal ( '1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar' .. "\n" .. 3588 \'2 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar' .. "\n" .. 3589 \'3 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar' .. "\n" .. 3590 \'4 foobar foobar foob' , getreg ( 0 )) 3591norm ! gg 3592norm ! 0v6g$y 3593call assert_equal ( 20 , col ( "'>" )) 3594call assert_equal ( '1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar' .. "\n" .. 3595 \'2 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar' .. "\n" .. 3596 \'3 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar' .. "\n" .. 3597 \'4 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar' .. "\n" .. 3598 \'5 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar' .. "\n" .. 3599 \'6 foobar foobar foob' , getreg ( 0 )) 3600" Move to last line, also down movement is not possible, should still move 3601" the cursor to the last visible char 3602norm ! G 3603norm ! 0v6g$y 3604call assert_equal ( 20 , col ( "'>" )) 3605call assert_equal ( '100 foobar foobar fo' , getreg ( 0 )) 3606bw ! 3607endfunc 3608 3609func Test_normal_gk_gj () 3610" needs 80 column new window 3611new 3612vert 80 new 3613call assert_beeps ( 'normal gk' ) 3614put =[repeat('x',90)..' {{{1','x {{{1' ] 3615norm ! gk 3616" In a 80 column wide terminal the window will be only 78 char 3617" (because Vim will leave space for the other window), 3618" but if the terminal is larger, it will be 80 chars, so verify the 3619" cursor column correctly. 3620call assert_equal ( winwidth ( 0 ) + 1 , col ( '.' )) 3621call assert_equal ( winwidth ( 0 ) + 1 , virtcol ( '.' )) 3622norm ! j 3623call assert_equal ( 6 , col ( '.' )) 3624call assert_equal ( 6 , virtcol ( '.' )) 3625norm ! gk 3626call assert_equal ( 95 , col ( '.' )) 3627call assert_equal ( 95 , virtcol ( '.' )) 3628 %bw ! 3629 3630" needs 80 column new window 3631new 3632vert 80 new 3633call assert_beeps ( 'normal gj' ) 3634set number 3635set numberwidth = 10 3636set cpoptions += n 3637put =[repeat('0',90), repeat('1',90)] 3638norm ! 075l 3639call assert_equal ( 76 , col ( '.' )) 3640norm ! gk 3641call assert_equal ( 1 , col ( '.' )) 3642norm ! gk 3643call assert_equal ( 76 , col ( '.' )) 3644norm ! gk 3645call assert_equal ( 1 , col ( '.' )) 3646norm ! gj 3647call assert_equal ( 76 , col ( '.' )) 3648norm ! gj 3649call assert_equal ( 1 , col ( '.' )) 3650norm ! gj 3651call assert_equal ( 76 , col ( '.' )) 3652" When 'nowrap' is set, gk and gj behave like k and j 3653set nowrap 3654normal ! gk 3655call assert_equal ([ 2 , 76 ], [ line ( '.' ), col ( '.' )]) 3656normal ! gj 3657call assert_equal ([ 3 , 76 ], [ line ( '.' ), col ( '.' )]) 3658 %bw ! 3659set cpoptions & number & numberwidth & wrap & 3660endfunc 3661 3662" Test for using : to run a multi-line Ex command in operator pending mode 3663func Test_normal_yank_with_excmd () 3664new 3665call setline ( 1 , [ 'foo' , 'bar' , 'baz' ]) 3666let @a= '' 3667call feedkeys ( "\"ay:if v:true\<CR>normal l\<CR>endif\<CR>" , 'xt' ) 3668call assert_equal ( 'f' , @a) 3669 3670bwipe ! 3671endfunc 3672 3673" Test for supplying a count to a normal-mode command across a cursorhold call 3674func Test_normal_cursorhold_with_count () 3675throw 'Skipped: Nvim removed <CursorHold> key' 3676func s: cHold () 3677let g: cHold_Called += 1 3678endfunc 3679new 3680augroup normalcHoldTest 3681au ! 3682au CursorHold <buffer> call s: cHold () 3683augroup END 3684let g: cHold_Called = 0 3685call feedkeys ( "3\<CursorHold>2ix" , 'xt' ) 3686call assert_equal ( 1 , g: cHold_Called ) 3687call assert_equal ( repeat ( 'x' , 32 ), getline ( 1 )) 3688augroup normalcHoldTest 3689au ! 3690augroup END 3691au ! normalcHoldTest 3692 3693bwipe ! 3694delfunc s:cHold 3695endfunc 3696 3697" Test for using a count and a command with CTRL-W 3698func Test_wincmd_with_count () 3699call feedkeys ( "\<C-W>12n" , 'xt' ) 3700call assert_equal ( 12 , winheight ( 0 )) 3701endfunc 3702 3703" Test for 'b', 'B' 'ge' and 'gE' commands 3704func Test_horiz_motion () 3705new 3706normal ! gg 3707call assert_beeps ( 'normal! b' ) 3708call assert_beeps ( 'normal! B' ) 3709call assert_beeps ( 'normal! gE' ) 3710call assert_beeps ( 'normal! ge' ) 3711" <S-Backspace> moves one word left and <C-Backspace> moves one WORD left 3712call setline ( 1 , 'one ,two ,three' ) 3713exe "normal! $\<S-BS>" 3714call assert_equal ( 11 , col ( '.' )) 3715exe "normal! $\<C-BS>" 3716call assert_equal ( 10 , col ( '.' )) 3717 3718bwipe ! 3719endfunc 3720 3721" Test for using a ":" command in operator pending mode 3722func Test_normal_colon_op () 3723new 3724call setline ( 1 , [ 'one' , 'two' ]) 3725call assert_beeps ( "normal! Gc:d\<CR>" ) 3726call assert_equal ([ 'one' ], getline ( 1 , '$' )) 3727 3728call setline ( 1 , [ 'one…two…three!' ]) 3729normal ! $ 3730" Using ":" as a movement is characterwise exclusive 3731call feedkeys ( "d:normal! F…\<CR>" , 'xt' ) 3732call assert_equal ([ 'one…two!' ], getline ( 1 , '$' )) 3733" Check that redoing a command with 0x80 bytes works 3734call feedkeys ( '.' , 'xt' ) 3735call assert_equal ([ 'one!' ], getline ( 1 , '$' )) 3736 3737call setline ( 1 , [ 'one' , 'two' , 'three' , 'four' , 'five' ]) 3738" Add this to the command history 3739call feedkeys ( ":normal! G0\<CR>" , 'xt' ) 3740" Use :normal! with control characters in operator pending mode 3741call feedkeys ( "d:normal! \<C-V>\<C-P>\<C-V>\<C-P>\<CR>" , 'xt' ) 3742call assert_equal ([ 'one' , 'two' , 'five' ], getline ( 1 , '$' )) 3743" Check that redoing a command with control characters works 3744call feedkeys ( '.' , 'xt' ) 3745call assert_equal ([ 'five' ], getline ( 1 , '$' )) 3746 3747bwipe ! 3748endfunc 3749 3750" Test for d and D commands 3751func Test_normal_delete_cmd () 3752new 3753" D in an empty line 3754call setline ( 1 , '' ) 3755normal D 3756call assert_equal ( '' , getline ( 1 )) 3757" D in an empty line in virtualedit mode 3758set virtualedit = all 3759normal D 3760call assert_equal ( '' , getline ( 1 )) 3761set virtualedit & 3762" delete to a readonly register 3763call setline ( 1 , [ 'abcd' ]) 3764call assert_beeps ( 'normal ":d2l' ) 3765 3766" D and d with 'nomodifiable' 3767call setline ( 1 , [ 'abcd' ]) 3768setlocal nomodifiable 3769call assert_fails ( 'normal D' , 'E21:' ) 3770call assert_fails ( 'normal d$' , 'E21:' ) 3771 3772bwipe ! 3773endfunc 3774 3775" Test for deleting or changing characters across lines with 'whichwrap' 3776" containing 's'. Should count <EOL> as one character. 3777func Test_normal_op_across_lines () 3778new 3779set whichwrap & 3780call setline ( 1 , [ 'one two' , 'three four' ]) 3781exe "norm! $3d\<Space>" 3782call assert_equal ([ 'one twhree four' ], getline ( 1 , '$' )) 3783 3784call setline ( 1 , [ 'one two' , 'three four' ]) 3785exe "norm! $3c\<Space>x" 3786call assert_equal ([ 'one twxhree four' ], getline ( 1 , '$' )) 3787 3788set whichwrap += l 3789call setline ( 1 , [ 'one two' , 'three four' ]) 3790exe "norm! $3x" 3791call assert_equal ([ 'one twhree four' ], getline ( 1 , '$' )) 3792 3793bwipe ! 3794set whichwrap & 3795endfunc 3796 3797" Test for 'w' and 'b' commands 3798func Test_normal_word_move () 3799new 3800call setline ( 1 , [ 'foo bar a' , '' , 'foo bar b' ]) 3801" copy a single character word at the end of a line 3802normal 1G$yw 3803call assert_equal ( 'a' , @") 3804" copy a single character word at the end of a file 3805normal G$yw 3806call assert_equal ( 'b' , @") 3807" check for a word movement handling an empty line properly 3808normal 1G$vwy 3809call assert_equal ( "a\n\n" , @") 3810 3811" copy using 'b' command 3812 %d 3813" non-empty blank line at the start of file 3814call setline ( 1 , [ ' ' , 'foo bar' ]) 3815normal 2Gyb 3816call assert_equal ( " \n" , @") 3817" try to copy backwards from the start of the file 3818call setline ( 1 , [ 'one two' , 'foo bar' ]) 3819call assert_beeps ( 'normal ggyb' ) 3820" 'b' command should stop at an empty line 3821call setline ( 1 , [ 'one two' , '' , 'foo bar' ]) 3822normal 3Gyb 3823call assert_equal ( "\n" , @") 3824normal 3Gy2b 3825call assert_equal ( "two\n" , @") 3826" 'b' command should not stop at a non-empty blank line 3827call setline ( 1 , [ 'one two' , ' ' , 'foo bar' ]) 3828normal 3Gyb 3829call assert_equal ( "two\n " , @") 3830 3831bwipe ! 3832endfunc 3833 3834" Test for 'scrolloff' with a long line that doesn't fit in the screen 3835func Test_normal_scrolloff () 383610 new 383760 vnew 3838call setline ( 1 , ' 1 ' .. repeat ( 'a' , 57 ) 3839 \.. ' 2 ' .. repeat ( 'b' , 57 ) 3840 \.. ' 3 ' .. repeat ( 'c' , 57 ) 3841 \.. ' 4 ' .. repeat ( 'd' , 57 ) 3842 \.. ' 5 ' .. repeat ( 'e' , 57 ) 3843 \.. ' 6 ' .. repeat ( 'f' , 57 ) 3844 \.. ' 7 ' .. repeat ( 'g' , 57 ) 3845 \.. ' 8 ' .. repeat ( 'h' , 57 ) 3846 \.. ' 9 ' .. repeat ( 'i' , 57 ) 3847 \.. '10 ' .. repeat ( 'j' , 57 ) 3848 \.. '11 ' .. repeat ( 'k' , 57 ) 3849 \.. '12 ' .. repeat ( 'l' , 57 ) 3850 \.. '13 ' .. repeat ( 'm' , 57 ) 3851 \.. '14 ' .. repeat ( 'n' , 57 ) 3852 \.. '15 ' .. repeat ( 'o' , 57 ) 3853 \.. '16 ' .. repeat ( 'p' , 57 ) 3854 \.. '17 ' .. repeat ( 'q' , 57 ) 3855 \.. '18 ' .. repeat ( 'r' , 57 ) 3856 \.. '19 ' .. repeat ( 's' , 57 ) 3857 \.. '20 ' .. repeat ( 't' , 57 ) 3858 \.. '21 ' .. repeat ( 'u' , 57 ) 3859 \.. '22 ' .. repeat ( 'v' , 57 ) 3860 \.. '23 ' .. repeat ( 'w' , 57 ) 3861 \.. '24 ' .. repeat ( 'x' , 57 ) 3862 \.. '25 ' .. repeat ( 'y' , 57 ) 3863 \.. '26 ' .. repeat ( 'z' , 57 ) 3864 \) 3865set scrolloff = 10 3866normal gg10gj 3867call assert_equal ( 6 , winline ()) 3868normal 10gj 3869call assert_equal ( 6 , winline ()) 3870normal 10gk 3871call assert_equal ( 6 , winline ()) 3872normal 0 3873call assert_equal ( 1 , winline ()) 3874normal $ 3875call assert_equal ( 10 , winline ()) 3876 3877set scrolloff & 3878bwipe ! 3879endfunc 3880 3881" Test for vertical scrolling with CTRL-F and CTRL-B with a long line 3882func Test_normal_vert_scroll_longline () 388310 new 388480 vnew 3885call setline ( 1 , range ( 1 , 10 )) 3886call append ( 5 , repeat ( 'a' , 1000 )) 3887exe "normal gg\<C-F>" 3888call assert_equal ( 6 , line ( '.' )) 3889exe "normal \<C-F>\<C-F>" 3890call assert_equal ( 11 , line ( '.' )) 3891call assert_equal ( 1 , winline ()) 3892exe "normal \<C-B>" 3893call assert_equal ( 11 , line ( '.' )) 3894call assert_equal ( 5 , winline ()) 3895exe "normal \<C-B>\<C-B>" 3896call assert_equal ( 5 , line ( '.' )) 3897call assert_equal ( 5 , winline ()) 3898 3899bwipe ! 3900endfunc 3901 3902" Test for jumping in a file using % 3903func Test_normal_percent_jump () 3904new 3905call setline ( 1 , range ( 1 , 100 )) 3906 3907" jumping to a folded line should open the fold 390825 , 75 fold 3909call feedkeys ( '50%' , 'xt' ) 3910call assert_equal ( 50 , line ( '.' )) 3911call assert_equal ( -1 , foldclosedend ( 50 )) 3912 3913bwipe ! 3914endfunc 3915 3916" Test that "%" skips parens inside comments when 'comments' defines C-style 3917" "//" or "/*" comments. 3918func Test_normal_percent_skip_comment () 3919new 3920setlocal comments = s1:/*,mb:*,ex:*/,:// 3921 3922" Forward: skip a ")" inside a // comment, match the real one. 3923silent ! %delete _ 3924call setline ( 1 , [ 'foo( // )' , ');' ]) 3925call cursor ( 1 , 4 ) 3926normal % 3927call assert_equal ([ 2 , 1 ], [ line ( '.' ), col ( '.' )]) 3928 3929" Forward: skip a ")" inside a /* */ comment, match the real one. 3930silent ! %delete _ 3931call setline ( 1 , [ 'bar( /* ) */ x)' ]) 3932call cursor ( 1 , 4 ) 3933normal % 3934call assert_equal ([ 1 , 15 ], [ line ( '.' ), col ( '.' )]) 3935 3936" Backward: skip a "(" inside a // comment, match the real one. 3937silent ! %delete _ 3938call setline ( 1 , [ '( // (' , ')' ]) 3939call cursor ( 2 , 1 ) 3940normal % 3941call assert_equal ([ 1 , 1 ], [ line ( '.' ), col ( '.' )]) 3942 3943" Cursor inside a // comment: a match inside that comment is still found. 3944silent ! %delete _ 3945call setline ( 1 , [ 'x // ( y )' ]) 3946call cursor ( 1 , 6 ) 3947normal % 3948call assert_equal ([ 1 , 10 ], [ line ( '.' ), col ( '.' )]) 3949 3950" Cursor inside a /* */ comment: a match inside that comment is still found. 3951silent ! %delete _ 3952call setline ( 1 , [ '/* a ( b ) c */' ]) 3953call cursor ( 1 , 6 ) 3954normal % 3955call assert_equal ([ 1 , 10 ], [ line ( '.' ), col ( '.' )]) 3956 3957" When 'comments' has no C-style comments the parens are not skipped. 3958setlocal comments = b:# 3959silent ! %delete _ 3960call setline ( 1 , [ 'foo( // )' , ');' ]) 3961call cursor ( 1 , 4 ) 3962normal % 3963call assert_equal ([ 1 , 10 ], [ line ( '.' ), col ( '.' )]) 3964 3965" With "%" in 'cpoptions' Vi-compatible matching is used and the parens 3966" inside comments are not skipped. 3967let save_cpo = & cpoptions 3968setlocal comments = s1:/*,mb:*,ex:*/,:// 3969set cpoptions += % 3970silent ! %delete _ 3971call setline ( 1 , [ 'foo( // )' , ');' ]) 3972call cursor ( 1 , 4 ) 3973normal % 3974call assert_equal ([ 1 , 10 ], [ line ( '.' ), col ( '.' )]) 3975let & cpoptions = save_cpo 3976 3977bwipe ! 3978endfunc 3979 3980" A "//" inside a string must not be treated as a line comment by "%". The 3981" line is scanned in a single pass, so this stays fast even on lines with many 3982" slashes (e.g. base64 data). 3983func Test_normal_percent_skip_comment_string () 3984new 3985setlocal comments = s1:/*,mb:*,ex:*/,:// 3986 3987" The "//" inside the string is not a comment, so "(" matches the real ")". 3988call setline ( 1 , [ '("a // b")' ]) 3989call cursor ( 1 , 1 ) 3990normal % 3991call assert_equal ([ 1 , 10 ], [ line ( '.' ), col ( '.' )]) 3992 3993" JSON-like: "{" matches the closing "}" although the string has slashes. 3994silent ! %delete _ 3995call setline ( 1 , [ '{' , ' "k": "x//y",' , '}' ]) 3996call cursor ( 1 , 1 ) 3997normal % 3998call assert_equal ([ 3 , 1 ], [ line ( '.' ), col ( '.' )]) 3999 4000" A "/*" inside a string must not start a block comment, so "(" still 4001" matches the real ")" after the string. 4002silent ! %delete _ 4003call setline ( 1 , [ '( "a /* b" )' ]) 4004call cursor ( 1 , 1 ) 4005normal % 4006call assert_equal ([ 1 , 12 ], [ line ( '.' ), col ( '.' )]) 4007 4008" A real /* */ block comment is still skipped: "(" matches the last ")". 4009silent ! %delete _ 4010call setline ( 1 , [ '( /* ) */ x )' ]) 4011call cursor ( 1 , 1 ) 4012normal % 4013call assert_equal ([ 1 , 13 ], [ line ( '.' ), col ( '.' )]) 4014 4015bwipe ! 4016endfunc 4017 4018" Test for << and >> commands to shift text by 'shiftwidth' 4019func Test_normal_shift_rightleft () 4020new 4021call setline ( 1 , [ 'one' , '' , "\t" , ' two' , "\tthree" , ' four' ]) 4022set shiftwidth = 2 tabstop = 8 4023normal gg6>> 4024call assert_equal ([ ' one' , '' , "\t " , ' two' , "\t three" , "\tfour" ], 4025 \getline ( 1 , '$' )) 4026normal ggVG2>> 4027call assert_equal ([ ' one' , '' , "\t " , "\ttwo" , 4028 \"\t three" , "\t four" ], getline ( 1 , '$' )) 4029normal gg6<< 4030call assert_equal ([ ' one' , '' , "\t " , ' two' , "\t three" , 4031 \"\t four" ], getline ( 1 , '$' )) 4032normal ggVG2<< 4033call assert_equal ([ 'one' , '' , "\t" , ' two' , "\tthree" , ' four' ], 4034 \getline ( 1 , '$' )) 4035set shiftwidth & tabstop & 4036bw ! 4037endfunc 4038 4039" Some commands like yy, cc, dd, >>, << and !! accept a count after 4040" typing the first letter of the command. 4041func Test_normal_count_after_operator () 4042new 4043setlocal shiftwidth = 4 tabstop = 8 autoindent 4044call setline ( 1 , [ 'one' , 'two' , 'three' , 'four' , 'five' ]) 4045let @a= '' 4046normal ! j"ay4y 4047call assert_equal ( "two\nthree\nfour\nfive\n" , @a) 4048normal ! 3G>2> 4049call assert_equal ([ 'one' , 'two' , ' three' , ' four' , 'five' ], 4050 \getline ( 1 , '$' )) 4051exe "normal! 3G0c2cred\nblue" 4052call assert_equal ([ 'one' , 'two' , ' red' , ' blue' , 'five' ], 4053 \getline ( 1 , '$' )) 4054exe "normal! gg<8<" 4055call assert_equal ([ 'one' , 'two' , 'red' , 'blue' , 'five' ], 4056 \getline ( 1 , '$' )) 4057exe "normal! ggd3d" 4058call assert_equal ([ 'blue' , 'five' ], getline ( 1 , '$' )) 4059call setline ( 1 , range ( 1 , 4 )) 4060call feedkeys ( "gg!3!\<C-B>\"\<CR>" , 'xt' ) 4061call assert_equal ( '".,.+2!' , @:) 4062call feedkeys ( "gg!1!\<C-B>\"\<CR>" , 'xt' ) 4063call assert_equal ( '".!' , @:) 4064call feedkeys ( "gg!9!\<C-B>\"\<CR>" , 'xt' ) 4065call assert_equal ( '".,$!' , @:) 4066bw ! 4067endfunc 4068 4069func Test_normal_gj_on_6_cell_wide_unprintable_char () 4070new |25 vsp 4071let text = '1 foooooooo ar e inszwe1 foooooooo inszwei' . 4072 \' i drei vier fünf sechs sieben acht un zehn elf zwöfl' . 4073 \' dreizehn v ierzehn fünfzehn' 4074put =text 4075call cursor ( 2 , 1 ) 4076norm ! gj 4077call assert_equal ([ 0 , 2 , 25 , 0 ], getpos ( '.' )) 4078bw ! 4079endfunc 4080 4081func Test_normal_count_out_of_range () 4082new 4083call setline ( 1 , 'text' ) 4084normal 44444444444| 4085call assert_equal ( 999999999 , v: count ) 4086normal 444444444444| 4087call assert_equal ( 999999999 , v: count ) 4088normal 4444444444444| 4089call assert_equal ( 999999999 , v: count ) 4090normal 4444444444444444444| 4091call assert_equal ( 999999999 , v: count ) 4092 4093normal 9y99999999| 4094call assert_equal ( 899999991 , v: count ) 4095normal 10y99999999| 4096call assert_equal ( 999999999 , v: count ) 4097normal 44444444444y44444444444| 4098call assert_equal ( 999999999 , v: count ) 4099bwipe ! 4100endfunc 4101 4102" Test that mouse shape is restored to Normal mode after failed "c" operation. 4103func Test_mouse_shape_after_failed_change () 4104CheckFeature mouseshape 4105CheckCanRunGui 4106 4107let lines =<< trim END 4108vim9script 4109set mouseshape+=o:busy 4110setlocal nomodifiable 4111var mouse_shapes = [] 4112 4113feedkeys('c') 4114timer_start(50, (_) => { 4115mouse_shapes += [getmouseshape()] 4116timer_start(50, (_) => { 4117feedkeys('c') 4118timer_start(50, (_) => { 4119mouse_shapes += [getmouseshape()] 4120timer_start(50, (_) => { 4121writefile(mouse_shapes, 'Xmouseshapes') 4122quit 4123}) 4124}) 4125}) 4126}) 4127END 4128call writefile ( lines , 'Xmouseshape.vim' , 'D' ) 4129call RunVim ([], [], "-g -S Xmouseshape.vim" ) 4130call WaitForAssert ({ ->assert_equal ([ 'busy' , 'arrow' ], readfile ( 'Xmouseshapes' ))}, 300 ) 4131 4132call delete ( 'Xmouseshapes' ) 4133endfunc 4134 4135" Test that mouse shape is restored to Normal mode after cancelling "gr". 4136func Test_mouse_shape_after_cancelling_gr () 4137CheckFeature mouseshape 4138CheckCanRunGui 4139 4140let lines =<< trim END 4141vim9script 4142var mouse_shapes = [] 4143 4144feedkeys('gr') 4145timer_start(50, (_) => { 4146mouse_shapes += [getmouseshape()] 4147timer_start(50, (_) => { 4148feedkeys("\<Esc>") 4149timer_start(50, (_) => { 4150mouse_shapes += [getmouseshape()] 4151timer_start(50, (_) => { 4152writefile(mouse_shapes, 'Xmouseshapes') 4153quit 4154}) 4155}) 4156}) 4157}) 4158END 4159call writefile ( lines , 'Xmouseshape.vim' , 'D' ) 4160call RunVim ([], [], "-g -S Xmouseshape.vim" ) 4161call WaitForAssert ({ ->assert_equal ([ 'beam' , 'arrow' ], readfile ( 'Xmouseshapes' ))}, 300 ) 4162 4163call delete ( 'Xmouseshapes' ) 4164endfunc 4165 4166" Test that "j" does not skip lines when scrolling below botline and 4167" 'foldmethod' is not "manual". 4168func Test_normal_j_below_botline () 4169CheckScreendump 4170 4171let lines =<< trim END 4172set number foldmethod=diff scrolloff=0 4173call setline(1, map(range(1, 9), 'repeat(v:val, 200)')) 4174norm Lj 4175END 4176call writefile ( lines , 'XNormalJBelowBotline' , 'D' ) 4177let buf = RunVimInTerminal ( '-S XNormalJBelowBotline' , #{ rows : 19 , cols : 40 }) 4178 4179call VerifyScreenDump ( buf , 'Test_normal_j_below_botline' , {}) 4180 4181call StopVimInTerminal ( buf ) 4182endfunc 4183 4184" Test for r (replace) command with CTRL_V and CTRL_Q 4185func Test_normal_r_ctrl_v_cmd () 4186new 4187call append ( 0 , 'This is a simple test: abcd' ) 4188exe "norm! 1gg$r\<C-V>\<C-V>" 4189call assert_equal ([ 'This is a simple test: abc' , '' ], getline ( 1 , '$' )) 4190exe "norm! 1gg$hr\<C-Q>\<C-Q>" 4191call assert_equal ([ 'This is a simple test: ab' , '' ], getline ( 1 , '$' )) 4192exe "norm! 1gg$2hr\<C-V>x7e" 4193call assert_equal ([ 'This is a simple test: a~' , '' ], getline ( 1 , '$' )) 4194exe "norm! 1gg$3hr\<C-Q>x7e" 4195call assert_equal ([ 'This is a simple test: ~~' , '' ], getline ( 1 , '$' )) 4196 4197if & encoding == 'utf-8' 4198exe "norm! 1gg$4hr\<C-V>u20ac" 4199call assert_equal ([ 'This is a simple test:€~~' , '' ], getline ( 1 , '$' )) 4200exe "norm! 1gg$5hr\<C-Q>u20ac" 4201call assert_equal ([ 'This is a simple test€€~~' , '' ], getline ( 1 , '$' )) 4202exe "norm! 1gg0R\<C-V>xff WAS \<esc>" 4203call assert_equal ([ 'ÿ WAS a simple test€€~~' , '' ], getline ( 1 , '$' )) 4204exe "norm! 1gg0elR\<C-Q>xffNOT\<esc>" 4205call assert_equal ([ 'ÿ WASÿNOT simple test€€~~' , '' ], getline ( 1 , '$' )) 4206endif 4207 4208call setline ( 1 , 'This is a simple test: abcd' ) 4209exe "norm! 1gg$gr\<C-V>\<C-V>" 4210call assert_equal ([ 'This is a simple test: abc' , '' ], getline ( 1 , '$' )) 4211exe "norm! 1gg$hgr\<C-Q>\<C-Q>" 4212call assert_equal ([ 'This is a simple test: ab ' , '' ], getline ( 1 , '$' )) 4213exe "norm! 1gg$2hgr\<C-V>x7e" 4214call assert_equal ([ 'This is a simple test: a~ ' , '' ], getline ( 1 , '$' )) 4215exe "norm! 1gg$3hgr\<C-Q>x7e" 4216call assert_equal ([ 'This is a simple test: ~~ ' , '' ], getline ( 1 , '$' )) 4217 4218" clean up 4219bw ! 4220endfunc 4221 4222" Test clicking on a TAB or an unprintable character in Normal mode 4223func Test_normal_click_on_ctrl_char () 4224let save_mouse = & mouse 4225set mouse = a 4226new 4227 4228call setline ( 1 , "a\<Tab>b\<C-K>c" ) 4229redraw 4230call Ntest_setmouse ( 1 , 1 ) 4231call feedkeys ( "\<LeftMouse>" , 'xt' ) 4232call assert_equal ([ 0 , 1 , 1 , 0 , 1 ], getcurpos ()) 4233call Ntest_setmouse ( 1 , 2 ) 4234call feedkeys ( "\<LeftMouse>" , 'xt' ) 4235call assert_equal ([ 0 , 1 , 2 , 0 , 2 ], getcurpos ()) 4236call Ntest_setmouse ( 1 , 3 ) 4237call feedkeys ( "\<LeftMouse>" , 'xt' ) 4238call assert_equal ([ 0 , 1 , 2 , 0 , 3 ], getcurpos ()) 4239call Ntest_setmouse ( 1 , 7 ) 4240call feedkeys ( "\<LeftMouse>" , 'xt' ) 4241call assert_equal ([ 0 , 1 , 2 , 0 , 7 ], getcurpos ()) 4242call Ntest_setmouse ( 1 , 8 ) 4243call feedkeys ( "\<LeftMouse>" , 'xt' ) 4244call assert_equal ([ 0 , 1 , 2 , 0 , 8 ], getcurpos ()) 4245call Ntest_setmouse ( 1 , 9 ) 4246call feedkeys ( "\<LeftMouse>" , 'xt' ) 4247call assert_equal ([ 0 , 1 , 3 , 0 , 9 ], getcurpos ()) 4248call Ntest_setmouse ( 1 , 10 ) 4249call feedkeys ( "\<LeftMouse>" , 'xt' ) 4250call assert_equal ([ 0 , 1 , 4 , 0 , 10 ], getcurpos ()) 4251call Ntest_setmouse ( 1 , 11 ) 4252call feedkeys ( "\<LeftMouse>" , 'xt' ) 4253call assert_equal ([ 0 , 1 , 4 , 0 , 11 ], getcurpos ()) 4254call Ntest_setmouse ( 1 , 12 ) 4255call feedkeys ( "\<LeftMouse>" , 'xt' ) 4256call assert_equal ([ 0 , 1 , 5 , 0 , 12 ], getcurpos ()) 4257call Ntest_setmouse ( 1 , 13 ) 4258call feedkeys ( "\<LeftMouse>" , 'xt' ) 4259call assert_equal ([ 0 , 1 , 5 , 0 , 13 ], getcurpos ()) 4260 4261bwipe ! 4262let & mouse = save_mouse 4263endfunc 4264 4265" Test clicking on a double-width character in Normal mode 4266func Test_normal_click_on_double_width_char () 4267let save_mouse = & mouse 4268set mouse = a 4269new 4270 4271call setline ( 1 , "口口" ) 4272redraw 4273call Ntest_setmouse ( 1 , 1 ) 4274call feedkeys ( "\<LeftMouse>" , 'xt' ) 4275call assert_equal ([ 0 , 1 , 1 , 0 , 1 ], getcurpos ()) 4276call Ntest_setmouse ( 1 , 2 ) 4277call feedkeys ( "\<LeftMouse>" , 'xt' ) 4278call assert_equal ([ 0 , 1 , 1 , 0 , 2 ], getcurpos ()) 4279call Ntest_setmouse ( 1 , 3 ) 4280call feedkeys ( "\<LeftMouse>" , 'xt' ) 4281call assert_equal ([ 0 , 1 , 4 , 0 , 3 ], getcurpos ()) 4282call Ntest_setmouse ( 1 , 4 ) 4283call feedkeys ( "\<LeftMouse>" , 'xt' ) 4284call assert_equal ([ 0 , 1 , 4 , 0 , 4 ], getcurpos ()) 4285 4286bwipe ! 4287let & mouse = save_mouse 4288endfunc 4289 4290func Test_normal_click_on_empty_line () 4291let save_mouse = & mouse 4292set mouse = a 4293botright new 4294call setline ( 1 , [ '' , '' , '' ]) 4295let row = win_screenpos ( 0 )[ 0 ] + 2 429620 vsplit 4297redraw 4298 4299call Ntest_setmouse ( row , 1 ) 4300call feedkeys ( "\<LeftMouse>" , 'xt' ) 4301call assert_equal ([ 0 , 3 , 1 , 0 , 1 ], getcurpos ()) 4302call Ntest_setmouse ( row , 2 ) 4303call feedkeys ( "\<LeftMouse>" , 'xt' ) 4304call assert_equal ([ 0 , 3 , 1 , 0 , 2 ], getcurpos ()) 4305call Ntest_setmouse ( row , 10 ) 4306call feedkeys ( "\<LeftMouse>" , 'xt' ) 4307call assert_equal ([ 0 , 3 , 1 , 0 , 10 ], getcurpos ()) 4308 4309call Ntest_setmouse ( row , 21 + 1 ) 4310call feedkeys ( "\<LeftMouse>" , 'xt' ) 4311call assert_equal ([ 0 , 3 , 1 , 0 , 1 ], getcurpos ()) 4312call Ntest_setmouse ( row , 21 + 2 ) 4313call feedkeys ( "\<LeftMouse>" , 'xt' ) 4314call assert_equal ([ 0 , 3 , 1 , 0 , 2 ], getcurpos ()) 4315call Ntest_setmouse ( row , 21 + 10 ) 4316call feedkeys ( "\<LeftMouse>" , 'xt' ) 4317call assert_equal ([ 0 , 3 , 1 , 0 , 10 ], getcurpos ()) 4318 4319bwipe ! 4320let & mouse = save_mouse 4321endfunc 4322 4323func Test_normal33_g_cmd_nonblank () 4324" Test that g<End> goes to the last non-blank char and g$ to the last 4325" visible column 432620 vnew 4327setlocal nowrap nonumber signcolumn = no 4328call setline ( 1 , [ 'fooo fooo fooo fooo fooo fooo fooo fooo ' ]) 4329exe "normal 0g\<End>" 4330call assert_equal ( 11 , col ( '.' )) 4331normal 0g$ 4332call assert_equal ( 20 , col ( '.' )) 4333exe "normal 0g\<kEnd>" 4334call assert_equal ( 11 , col ( '.' )) 4335setlocal wrap 4336exe "normal 0g\<End>" 4337call assert_equal ( 11 , col ( '.' )) 4338normal 0g$ 4339call assert_equal ( 20 , col ( '.' )) 4340exe "normal 0g\<kEnd>" 4341call assert_equal ( 11 , col ( '.' )) 4342 4343" Test visual mode at end of line 4344normal 0$bvg$y 4345call assert_equal ( 80 , col ( "'>" )) 4346exe "normal 0$bvg\<End>y" 4347call assert_equal ( 71 , col ( "'>" )) 4348setlocal nowrap virtualedit = all 4349exe "normal 0$\<C-v>llg\<End>y" 4350call assert_equal ( 71 , col ( "'<" )) 4351exe "normal 0$llvg\<End>y" 4352call assert_equal ( 71 , col ( "'<" )) 4353bw ! 4354endfunc 4355 4356func Test_normal34_zet_large () 4357" shouldn't cause overflow 4358norm ! z9765405999999999999 4359endfunc 4360 4361" Test for { and } paragraph movements in a single line 4362func Test_brace_single_line () 4363new 4364call setline ( 1 , [ 'foobar one two three' ]) 43651 4366norm ! 0} 4367 4368call assert_equal ([ 0 , 1 , 20 , 0 ], getpos ( '.' )) 4369norm ! { 4370call assert_equal ([ 0 , 1 , 1 , 0 ], getpos ( '.' )) 4371bw ! 4372endfunc 4373 4374" Test for Ctrl-B/Ctrl-U in buffer with a single line 4375func Test_single_line_scroll () 4376CheckFeature textprop 4377 4378new 4379call setline ( 1 , [ 'foobar one two three' ]) 4380let vt = 'virt_above' 4381call prop_type_add ( vt , { 'highlight' : 'IncSearch' }) 4382call prop_add ( 1 , 0 , { 'type' : vt , 'text' : '---' , 'text_align' : 'above' }) 4383call cursor ( 1 , 1 ) 4384 4385" Ctrl-B/Ctrl-U scroll up with hidden "above" virtual text. 4386set smoothscroll 4387exe "normal \<C-E>" 4388call assert_notequal ( 0 , winsaveview (). skipcol ) 4389exe "normal \<C-B>" 4390call assert_equal ( 0 , winsaveview (). skipcol ) 4391exe "normal \<C-E>" 4392call assert_notequal ( 0 , winsaveview (). skipcol ) 4393exe "normal \<C-U>" 4394call assert_equal ( 0 , winsaveview (). skipcol ) 4395 4396set smoothscroll & 4397bw ! 4398call prop_type_delete ( vt ) 4399endfunc 4400 4401" Test for zb in buffer with a single line and filler lines 4402func Test_single_line_filler_zb () 4403call setline ( 1 , [ '' , 'foobar one two three' ]) 4404diffthis 4405new 4406call setline ( 1 , [ 'foobar one two three' ]) 4407diffthis 4408 4409" zb scrolls to reveal filler lines at the start of the buffer. 4410exe "normal \<C-E>zb" 4411call assert_equal ( 1 , winsaveview (). topfill ) 4412 4413bw ! 4414endfunc 4415 4416" Test for zb with fewer buffer lines than window height, non-zero 'scrolloff' 4417" and cursor on or just above a fold. 4418func Test_zb_with_cursor_on_or_just_above_fold () 441915 new 4420call setline ( 1 , range ( 1 , 5 ) + [ '' , 'foo{{{' , 'bar}}}' , '' , 'baz' ]) 4421setlocal foldmethod = markerscrolloff = 1 4422call assert_equal ( 8 , foldclosedend ( 7 )) 4423 4424call cursor ( 7 , 1 ) 4425normal ! zb 4426call assert_equal ( 1 , line ( 'w0' )) 4427 4428call cursor ( 6 , 1 ) 4429normal ! zb 4430call assert_equal ( 1 , line ( 'w0' )) 4431 4432bwipe ! 4433endfunc 4434 4435" Test for Ctrl-U not getting stuck at end of buffer with 'scrolloff'. 4436func Test_halfpage_scrolloff_eob () 4437set scrolloff = 5 4438 4439call setline ( 1 , range ( 1 , 100 )) 4440exe "norm! Gzz\<C-U>zz" 4441call assert_notequal ( 100 , line ( '.' )) 4442 4443set scrolloff & 4444bwipe ! 4445endfunc 4446 4447" Test for Ctrl-U/D moving the cursor at the buffer boundaries. 4448func Test_halfpage_cursor_startend () 4449call setline ( 1 , range ( 1 , 100 )) 4450exe "norm! jztj\<C-U>" 4451call assert_equal ( 1 , line ( '.' )) 4452exe "norm! G\<C-Y>k\<C-D>" 4453call assert_equal ( 100 , line ( '.' )) 4454bwipe ! 4455endfunc 4456 4457" Test for Ctrl-F/B moving the cursor to the window boundaries. 4458func Test_page_cursor_topbot () 445910 new 4460call setline ( 1 , range ( 1 , 100 )) 4461exe "norm! gg2\<C-F>" 4462call assert_equal ( 17 , line ( '.' )) 4463exe "norm! \<C-B>" 4464call assert_equal ( 18 , line ( '.' )) 4465exe "norm! \<C-B>\<C-F>" 4466call assert_equal ( 9 , line ( '.' )) 4467" Not when already at the start of the buffer. 4468exe "norm! ggj\<C-B>" 4469call assert_equal ( 2 , line ( '.' )) 4470bwipe ! 4471endfunc 4472 4473" Test for Ctrl-D with long line 4474func Test_halfpage_longline () 447510 new 447640 vsplit 4477call setline ( 1 , [ 'long' ->repeat ( 1000 ), 'short' ]) 4478exe "norm! \<C-D>" 4479call assert_equal ( 2 , line ( '.' )) 4480bwipe ! 4481endfunc 4482 4483" Test for Ctrl-E with long line and very narrow window, 4484" used to cause an infinite loop 4485func Test_scroll_longline_no_loop () 44864 vnew 4487setl smoothscroll number showbreak = >scrolloff = 2 4488call setline ( 1 , repeat ([ 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.' ], 3 )) 4489exe "normal! \<C-E>" 4490bwipe ! 4491endfunc 4492 4493" Test for go command 4494func Test_normal_go () 4495new 4496call setline ( 1 , [ 'one two three four' ]) 4497call cursor ( 1 , 5 ) 4498norm ! dvgo 4499call assert_equal ( 'wo three four' , getline ( 1 )) 4500norm ! ... 4501call assert_equal ( 'three four' , getline ( 1 )) 4502 4503bwipe ! 4504endfunc 4505 4506" Test for Ctrl-D with 'scrolloff' and narrow window does not get stuck. 4507func Test_scroll_longline_scrolloff () 450811 new 450936 vsplit 4510set scrolloff = 5 4511 4512call setline ( 1 , [ '' ] ->repeat ( 5 )) 4513call setline ( 6 , [ 'foo' ->repeat ( 20 )] ->repeat ( 2 )) 4514call setline ( 8 , [ 'bar' ->repeat ( 30 )]) 4515call setline ( 9 , [ '' ] ->repeat ( 5 )) 4516exe "normal! \<C-D>" 4517call assert_equal ( 6 , line ( 'w0' )) 4518exe "normal! \<C-D>" 4519call assert_equal ( 7 , line ( 'w0' )) 4520 4521set scrolloff & 4522bwipe ! 4523endfunc 4524 4525" Benchmark test for Ctrl-F with 'nosmoothscroll' 4526func Test_scroll_longline_benchmark () 4527call setline ( 1 , [ 'foo' ->repeat ( 20000 )] + [ '' ]) 4528let start = reltime () 4529exe "normal! \<C-F>" 4530call assert_inrange ( 0 , 0.1 , reltimefloat ( reltime ( start ))) 4531bwipe ! 4532endfunc 4533 4534" Test Ctrl-B with 'nosmoothscroll' not stuck with line exactly window width. 4535func Test_scroll_longline_winwidth () 453610 new 4537call setline ( 1 , [ '' ] ->repeat ( 20 ) + [ 'A' ->repeat ( 20 * winwidth ( 0 ))] + [ '' ] ->repeat ( 20 )) 4538exe "normal! G3\<C-B>" 4539call assert_equal ( 22 , line ( 'w0' )) 4540exe "normal! \<C-B>" 4541call assert_equal ( 21 , line ( 'w0' )) 4542exe "normal! \<C-B>" 4543call assert_equal ( 11 , line ( 'w0' )) 4544exe "normal! \<C-B>" 4545call assert_equal ( 3 , line ( 'w0' )) 4546exe "normal! \<C-B>" 4547call assert_equal ( 1 , line ( 'w0' )) 4548bwipe ! 4549endfunc 4550 4551func Test_pos_percentage_in_turkish_locale () 4552CheckRunVimInTerminal 4553CheckNotMac 4554defer execute(':lang C') 4555if ! filereadable ( '../po/tr.mo' ) 4556throw 'Skipped: tr.mo not built, run make in src/po first' 4557endif 4558 4559try 4560let dir = expand ( '$VIMRUNTIME/lang/tr/' ) 4561let target = expand ( '$VIMRUNTIME/lang/tr/LC_MESSAGES/' ) 4562let tr = '../po/tr.mo' 4563call mkdir ( dir , 'R' ) 4564call mkdir ( target , '' ) 4565call filecopy ( tr , target .. 'vim.mo' ) 4566lang tr_TR.UTF-8 4567let buf = RunVimInTerminal ( '' , { 'rows' : 5 , 'cols' : 40 }) 4568call term_sendkeys ( buf , ":lang tr_TR.UTF-8\<cr>" ) 4569call term_sendkeys ( buf , ":put =range(1,40)\<cr>" ) 4570call term_sendkeys ( buf , ":5\<cr>" ) 4571call WaitForAssert ({ ->assert_match ( '%8$' , term_getline ( buf , 5 ))}) 4572 4573call StopVimInTerminal ( buf ) 4574catch /E197:/ 4575" can't use Turkish locale 4576throw 'Skipped: Turkish locale not available' 4577endtry 4578endfunc 4579 4580" This test simulates the problem with gvim on Windows, observed when 4581" Test_normal11_showcmd in test_normal.vim is executed consecutively after 4582" Test_mouse_shape_after_failed_change. 4583" 4584" The problem occurred because WM_SETFOCUS was processed slowly, and typebuf 4585" was not empty when it should have been. 4586" TODO: Is this test flaky? 4587func Test_win32_gui_setfocus_prevent_showcmd () 4588if ! has ( 'win32' ) || ! has ( 'gui_running' ) 4589throw 'Skipped: Windows GUI regression test' 4590endif 4591 4592" WM_SETFOCUS event occurs when finish to execute filter command in gvim 4593exe 'silent !echo foo' 4594 4595set showcmd 459610 new 4597call setline ( 1 , [ 'aaaaa' , 'bbbbb' , 'ccccc' ]) 4598call feedkeys ( "ggl\<C-V>lljj" , 'xt' ) 4599 4600" showcmd could not be updated because events originating from WM_SETFOCUS 4601" were stored in typebuf at here. clear_showcmd() executed from redraw, 4602" will not draw the selection information unless you are in visual mode and 4603" typebuf is empty. 4604redraw ! 4605 4606call assert_match ( '3x3$' , Screenline ( & lines )) 4607call feedkeys ( "\<C-V>" , 'xt' ) 4608endfunc 4609 4610" vim: shiftwidth=2 sts=2 expandtab nofoldenable