neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

test_normal.vim (118728B)


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