neovim

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

test_cpoptions.vim (22281B)


      1 " Test for the various 'cpoptions' (cpo) flags
      2 
      3 source check.vim
      4 source shared.vim
      5 source view_util.vim
      6 
      7 " Test for the 'a' flag in 'cpo'. Reading a file should set the alternate
      8 " file name.
      9 func Test_cpo_a()
     10  let save_cpo = &cpo
     11  call writefile(['one'], 'XfileCpoA', 'D')
     12  " Wipe out all the buffers, so that the alternate file is empty
     13  edit Xfoo | %bw
     14  set cpo-=a
     15  new
     16  read XfileCpoA
     17  call assert_equal('', @#)
     18  %d
     19  set cpo+=a
     20  read XfileCpoA
     21  call assert_equal('XfileCpoA', @#)
     22  bw!
     23  let &cpo = save_cpo
     24 endfunc
     25 
     26 " Test for the 'A' flag in 'cpo'. Writing a file should set the alternate
     27 " file name.
     28 func Test_cpo_A()
     29  let save_cpo = &cpo
     30  " Wipe out all the buffers, so that the alternate file is empty
     31  edit Xfoo | %bw
     32  set cpo-=A
     33  new XcpoAfile1
     34  write XcpoAfile2
     35  call assert_equal('', @#)
     36  %bw
     37  call delete('XcpoAfile2')
     38  new XcpoAfile1
     39  set cpo+=A
     40  write XcpoAfile2
     41  call assert_equal('XcpoAfile2', @#)
     42  bw!
     43  call delete('XcpoAfile2')
     44  let &cpo = save_cpo
     45 endfunc
     46 
     47 " Test for the 'b' flag in 'cpo'. "\|" at the end of a map command is
     48 " recognized as the end of the map.
     49 func Test_cpo_b()
     50  let save_cpo = &cpo
     51  set cpo+=b
     52  nnoremap <F5> :pwd\<CR>\|let i = 1
     53  call assert_equal(':pwd\<CR>\', maparg('<F5>'))
     54  nunmap <F5>
     55  exe "nnoremap <F5> :pwd\<C-V>|let i = 1"
     56  call assert_equal(':pwd|let i = 1', maparg('<F5>'))
     57  nunmap <F5>
     58  set cpo-=b
     59  nnoremap <F5> :pwd\<CR>\|let i = 1
     60  call assert_equal(':pwd\<CR>|let i = 1', maparg('<F5>'))
     61  let &cpo = save_cpo
     62  nunmap <F5>
     63 endfunc
     64 
     65 " Test for the 'B' flag in 'cpo'. A backslash in mappings, abbreviations, user
     66 " commands and menu commands has no special meaning.
     67 func Test_cpo_B()
     68  let save_cpo = &cpo
     69  new
     70  imap <buffer> x<Bslash>k Test
     71  set cpo-=B
     72  iabbr <buffer> abc ab\<BS>d
     73  exe "normal iabc "
     74  call assert_equal('ab<BS>d ', getline(1))
     75  call feedkeys(":imap <buffer> x\<C-A>\<C-B>\"\<CR>", 'tx')
     76  call assert_equal('"imap <buffer> x\\k', @:)
     77  %d
     78  set cpo+=B
     79  iabbr <buffer> abc ab\<BS>d
     80  exe "normal iabc "
     81  call assert_equal('abd ', getline(1))
     82  call feedkeys(":imap <buffer> x\<C-A>\<C-B>\"\<CR>", 'tx')
     83  call assert_equal('"imap <buffer> x\k', @:)
     84  bw!
     85  let &cpo = save_cpo
     86 endfunc
     87 
     88 " Test for the 'c' flag in 'cpo'.
     89 func Test_cpo_c()
     90  let save_cpo = &cpo
     91  set cpo+=c
     92  new
     93  call setline(1, ' abababababab')
     94  exe "normal gg/abab\<CR>"
     95  call assert_equal(3, searchcount().total)
     96  set cpo-=c
     97  exe "normal gg/abab\<CR>"
     98  call assert_equal(5, searchcount().total)
     99  bw!
    100  let &cpo = save_cpo
    101 endfunc
    102 
    103 " Test for the 'C' flag in 'cpo' (line continuation)
    104 func Test_cpo_C()
    105  let save_cpo = &cpo
    106  call writefile(['let l = [', '\ 1,', '\ 2]'], 'XfileCpoC', 'D')
    107  set cpo-=C
    108  source XfileCpoC
    109  call assert_equal([1, 2], g:l)
    110  set cpo+=C
    111  call assert_fails('source XfileCpoC', ['E697:', 'E10:'])
    112  let &cpo = save_cpo
    113 endfunc
    114 
    115 " Test for the 'd' flag in 'cpo' (tags relative to the current file)
    116 func Test_cpo_d()
    117  let save_cpo = &cpo
    118  call mkdir('XdirCpoD', 'R')
    119  call writefile(["one\tXfile1\t/^one$/"], 'tags', 'D')
    120  call writefile(["two\tXfile2\t/^two$/"], 'XdirCpoD/tags')
    121  set tags=./tags
    122  set cpo-=d
    123  edit XdirCpoD/Xfile
    124  call assert_equal('two', taglist('.*')[0].name)
    125  set cpo+=d
    126  call assert_equal('one', taglist('.*')[0].name)
    127 
    128  %bw!
    129  set tags&
    130  let &cpo = save_cpo
    131 endfunc
    132 
    133 " Test for the 'D' flag in 'cpo' (digraph after a r, f or t)
    134 func Test_cpo_D()
    135  CheckFeature digraphs
    136  let save_cpo = &cpo
    137  new
    138  set cpo-=D
    139  call setline(1, 'abcdefgh|')
    140  exe "norm! 1gg0f\<c-k>!!"
    141  call assert_equal(9, col('.'))
    142  set cpo+=D
    143  exe "norm! 1gg0f\<c-k>!!"
    144  call assert_equal(1, col('.'))
    145  set cpo-=D
    146  bw!
    147  let &cpo = save_cpo
    148 endfunc
    149 
    150 " Test for the 'e' flag in 'cpo'
    151 func Test_cpo_e()
    152  let save_cpo = &cpo
    153  let @a='let i = 45'
    154  set cpo+=e
    155  call feedkeys(":@a\<CR>", 'xt')
    156  call assert_equal(45, i)
    157  set cpo-=e
    158  call feedkeys(":@a\<CR>6\<CR>", 'xt')
    159  call assert_equal(456, i)
    160  let &cpo = save_cpo
    161 endfunc
    162 
    163 " Test for the 'E' flag in 'cpo' with yank, change, delete, etc. operators
    164 func Test_cpo_E()
    165  new
    166  call setline(1, '')
    167  set cpo+=E
    168  " yank an empty line
    169  call assert_beeps('normal "ayl')
    170  " change an empty line
    171  call assert_beeps('normal lcTa')
    172  call assert_beeps('normal 0c0')
    173  " delete an empty line
    174  call assert_beeps('normal D')
    175  call assert_beeps('normal dl')
    176  call assert_equal('', getline(1))
    177  " change case of an empty line
    178  call assert_beeps('normal gul')
    179  call assert_beeps('normal gUl')
    180  " replace a character
    181  call assert_beeps('normal vrx')
    182  " increment and decrement
    183  call assert_beeps('exe "normal v\<C-A>"')
    184  call assert_beeps('exe "normal v\<C-X>"')
    185  set cpo-=E
    186  bw!
    187 endfunc
    188 
    189 " Test for the 'f' flag in 'cpo' (read in an empty buffer sets the file name)
    190 func Test_cpo_f()
    191  let save_cpo = &cpo
    192  new
    193  set cpo-=f
    194  read test_cpoptions.vim
    195  call assert_equal('', @%)
    196  %d
    197  set cpo+=f
    198  read test_cpoptions.vim
    199  call assert_equal('test_cpoptions.vim', @%)
    200 
    201  bwipe!
    202  let &cpo = save_cpo
    203 endfunc
    204 
    205 " Test for the 'F' flag in 'cpo' (write in an empty buffer sets the file name)
    206 func Test_cpo_F()
    207  let save_cpo = &cpo
    208  new
    209  set cpo-=F
    210  write XfileCpoF
    211  call assert_equal('', @%)
    212  call delete('XfileCpoF')
    213  set cpo+=F
    214  write XfileCpoF
    215  call assert_equal('XfileCpoF', @%)
    216  bw!
    217  call delete('XfileCpoF')
    218  let &cpo = save_cpo
    219 endfunc
    220 
    221 " Test for the 'g' flag in 'cpo' (jump to line 1 when re-editing a file)
    222 func Test_cpo_g()
    223  let save_cpo = &cpo
    224  new test_cpoptions.vim
    225  set cpo-=g
    226  normal 20G
    227  edit
    228  call assert_equal(20, line('.'))
    229  " Nvim: no "g" flag in 'cpoptions'.
    230  " set cpo+=g
    231  " edit
    232  " call assert_equal(1, line('.'))
    233  bw!
    234  let &cpo = save_cpo
    235 endfunc
    236 
    237 " Test for inserting text in a line with only spaces ('H' flag in 'cpoptions')
    238 func Test_cpo_H()
    239  let save_cpo = &cpo
    240  new
    241  set cpo-=H
    242  call setline(1, '    ')
    243  normal! Ia
    244  call assert_equal('    a', getline(1))
    245  " Nvim: no "H" flag in 'cpoptions'.
    246  " set cpo+=H
    247  " call setline(1, '    ')
    248  " normal! Ia
    249  " call assert_equal('   a ', getline(1))
    250  bw!
    251  let &cpo = save_cpo
    252 endfunc
    253 
    254 " TODO: Add a test for the 'i' flag in 'cpo'
    255 " Interrupting the reading of a file will leave it modified.
    256 
    257 " Test for the 'I' flag in 'cpo' (deleting autoindent when using arrow keys)
    258 func Test_cpo_I()
    259  let save_cpo = &cpo
    260  new
    261  setlocal autoindent
    262  set cpo+=I
    263  exe "normal i    one\<CR>\<Up>"
    264  call assert_equal('    ', getline(2))
    265  set cpo-=I
    266  %d
    267  exe "normal i    one\<CR>\<Up>"
    268  call assert_equal('', getline(2))
    269  bw!
    270  let &cpo = save_cpo
    271 endfunc
    272 
    273 " Test for the 'j' flag in 'cpo' is in the test_join.vim file.
    274 
    275 " Test for the 'J' flag in 'cpo' (two spaces after a sentence)
    276 func Test_cpo_J()
    277  let save_cpo = &cpo
    278  new
    279  set cpo-=J
    280  call setline(1, 'one. two!  three? four."''  five.)]')
    281  normal 0
    282  for colnr in [6, 12, 19, 28, 34]
    283    normal )
    284    call assert_equal(colnr, col('.'))
    285  endfor
    286  for colnr in [28, 19, 12, 6, 1]
    287    normal (
    288    call assert_equal(colnr, col('.'))
    289  endfor
    290  set cpo+=J
    291  normal 0
    292  for colnr in [12, 28, 34]
    293    normal )
    294    call assert_equal(colnr, col('.'))
    295  endfor
    296  for colnr in [28, 12, 1]
    297    normal (
    298    call assert_equal(colnr, col('.'))
    299  endfor
    300  bw!
    301  let &cpo = save_cpo
    302 endfunc
    303 
    304 " TODO: Add a test for the 'k' flag in 'cpo'.
    305 " Disable the recognition of raw key codes in mappings, abbreviations, and the
    306 " "to" part of menu commands.
    307 
    308 " TODO: Add a test for the 'K' flag in 'cpo'.
    309 " Don't wait for a key code to complete when it is halfway a mapping.
    310 
    311 " Test for the 'l' flag in 'cpo' (backslash in a [] range)
    312 func Test_cpo_l()
    313  let save_cpo = &cpo
    314  new
    315  call setline(1, ['', "a\tc" .. '\t'])
    316  set cpo-=l
    317  exe 'normal gg/[\t]' .. "\<CR>"
    318  call assert_equal([2, 8], [col('.'), virtcol('.')])
    319  set cpo+=l
    320  exe 'normal gg/[\t]' .. "\<CR>"
    321  call assert_equal([4, 10], [col('.'), virtcol('.')])
    322  bw!
    323  let &cpo = save_cpo
    324 endfunc
    325 
    326 " Test for inserting tab in virtual replace mode ('L' flag in 'cpoptions')
    327 func Test_cpo_L()
    328  let save_cpo = &cpo
    329  new
    330  set cpo-=L
    331  call setline(1, 'abcdefghijklmnopqr')
    332  exe "normal 0gR\<Tab>"
    333  call assert_equal("\<Tab>ijklmnopqr", getline(1))
    334  set cpo+=L
    335  set list
    336  call setline(1, 'abcdefghijklmnopqr')
    337  exe "normal 0gR\<Tab>"
    338  call assert_equal("\<Tab>cdefghijklmnopqr", getline(1))
    339  set nolist
    340  call setline(1, 'abcdefghijklmnopqr')
    341  exe "normal 0gR\<Tab>"
    342  call assert_equal("\<Tab>ijklmnopqr", getline(1))
    343  bw!
    344  let &cpo = save_cpo
    345 endfunc
    346 
    347 " TODO: Add a test for the 'm' flag in 'cpo'.
    348 " When included, a showmatch will always wait half a second.  When not
    349 " included, a showmatch will wait half a second or until a character is typed.
    350 
    351 " Test for the 'M' flag in 'cpo' (% with escape parenthesis)
    352 func Test_cpo_M()
    353  let save_cpo = &cpo
    354  new
    355  call setline(1, ['( \( )', '\( ( \)'])
    356 
    357  set cpo-=M
    358  call cursor(1, 1)
    359  normal %
    360  call assert_equal(6, col('.'))
    361  call cursor(1, 4)
    362  call assert_beeps('normal %')
    363  call cursor(2, 2)
    364  normal %
    365  call assert_equal(7, col('.'))
    366  call cursor(2, 4)
    367  call assert_beeps('normal %')
    368 
    369  set cpo+=M
    370  call cursor(1, 4)
    371  normal %
    372  call assert_equal(6, col('.'))
    373  call cursor(1, 1)
    374  call assert_beeps('normal %')
    375  call cursor(2, 4)
    376  normal %
    377  call assert_equal(7, col('.'))
    378  call cursor(2, 1)
    379  call assert_beeps('normal %')
    380 
    381  bw!
    382  let &cpo = save_cpo
    383 endfunc
    384 
    385 " Test for the 'n' flag in 'cpo' (using number column for wrapped lines)
    386 func Test_cpo_n()
    387  let save_cpo = &cpo
    388  new
    389  call setline(1, repeat('a', &columns))
    390  setlocal number
    391  set cpo-=n
    392  redraw!
    393  call assert_equal('    aaaa', Screenline(2))
    394  set cpo+=n
    395  redraw!
    396  call assert_equal('aaaa', Screenline(2))
    397  bw!
    398  let &cpo = save_cpo
    399 endfunc
    400 
    401 " Test for the 'o' flag in 'cpo' (line offset to search command)
    402 func Test_cpo_o()
    403  let save_cpo = &cpo
    404  new
    405  call setline(1, ['', 'one', 'two', 'three', 'one', 'two', 'three'])
    406  set cpo-=o
    407  exe "normal /one/+2\<CR>"
    408  normal n
    409  call assert_equal(7, line('.'))
    410  set cpo+=o
    411  exe "normal /one/+2\<CR>"
    412  normal n
    413  call assert_equal(5, line('.'))
    414  bw!
    415  let &cpo = save_cpo
    416 endfunc
    417 
    418 " Test for the 'O' flag in 'cpo' (overwriting an existing file)
    419 func Test_cpo_O()
    420  let save_cpo = &cpo
    421  new XfileCpoO
    422  call setline(1, 'one')
    423  call writefile(['two'], 'XfileCpoO', 'D')
    424  set cpo-=O
    425  call assert_fails('write', 'E13:')
    426  set cpo+=O
    427  write
    428  call assert_equal(['one'], readfile('XfileCpoO'))
    429  bw!
    430  let &cpo = save_cpo
    431 endfunc
    432 
    433 " Test for the 'p' flag in 'cpo' is in the test_lispindent.vim file.
    434 
    435 " Test for the 'P' flag in 'cpo' (appending to a file sets the current file
    436 " name)
    437 func Test_cpo_P()
    438  let save_cpo = &cpo
    439  call writefile([], 'XfileCpoP', 'D')
    440  new
    441  call setline(1, 'one')
    442  set cpo+=F
    443  set cpo-=P
    444  write >> XfileCpoP
    445  call assert_equal('', @%)
    446  set cpo+=P
    447  write >> XfileCpoP
    448  call assert_equal('XfileCpoP', @%)
    449 
    450  bwipe!
    451  let &cpo = save_cpo
    452 endfunc
    453 
    454 " Test for the 'q' flag in 'cpo' (joining multiple lines)
    455 func Test_cpo_q()
    456  let save_cpo = &cpo
    457  new
    458  call setline(1, ['one', 'two', 'three', 'four', 'five'])
    459  set cpo-=q
    460  normal gg4J
    461  call assert_equal(14, col('.'))
    462  %d
    463  call setline(1, ['one', 'two', 'three', 'four', 'five'])
    464  set cpo+=q
    465  normal gg4J
    466  call assert_equal(4, col('.'))
    467  bw!
    468  let &cpo = save_cpo
    469 endfunc
    470 
    471 " Test for the 'r' flag in 'cpo' (redo command with a search motion)
    472 func Test_cpo_r()
    473  let save_cpo = &cpo
    474  new
    475  call setline(1, repeat(['one two three four'], 2))
    476  set cpo-=r
    477  exe "normal ggc/two\<CR>abc "
    478  let @/ = 'three'
    479  normal 2G.
    480  call assert_equal('abc two three four', getline(2))
    481  %d
    482  call setline(1, repeat(['one two three four'], 2))
    483  set cpo+=r
    484  exe "normal ggc/two\<CR>abc "
    485  let @/ = 'three'
    486  normal 2G.
    487  call assert_equal('abc three four', getline(2))
    488  bw!
    489  let &cpo = save_cpo
    490 endfunc
    491 
    492 " Test for the 'R' flag in 'cpo' (clear marks after a filter command)
    493 func Test_cpo_R()
    494  CheckUnix
    495  let save_cpo = &cpo
    496  new
    497  call setline(1, ['three', 'one', 'two'])
    498  set cpo-=R
    499  3mark r
    500  %!sort
    501  call assert_equal(3, line("'r"))
    502  %d
    503  call setline(1, ['three', 'one', 'two'])
    504  set cpo+=R
    505  3mark r
    506  %!sort
    507  call assert_equal(0, line("'r"))
    508  bw!
    509  let &cpo = save_cpo
    510 endfunc
    511 
    512 " TODO: Add a test for the 's' flag in 'cpo'.
    513 " Set buffer options when entering the buffer for the first time.  If not
    514 " present the options are set when the buffer is created.
    515 
    516 " Test for the 'S' flag in 'cpo' (copying buffer options)
    517 func Test_cpo_S()
    518  let save_cpo = &cpo
    519  new Xfile1
    520  set noautoindent
    521  new Xfile2
    522  set cpo-=S
    523  set autoindent
    524  wincmd p
    525  call assert_equal(0, &autoindent)
    526  wincmd p
    527  call assert_equal(1, &autoindent)
    528  set cpo+=S
    529  wincmd p
    530  call assert_equal(1, &autoindent)
    531  set noautoindent
    532  wincmd p
    533  call assert_equal(0, &autoindent)
    534  wincmd t
    535  bw!
    536  bw!
    537  let &cpo = save_cpo
    538 endfunc
    539 
    540 " Test for the 't' flag in 'cpo' is in the test_tagjump.vim file.
    541 
    542 " Test for the 'u' flag in 'cpo' (Vi-compatible undo)
    543 func Test_cpo_u()
    544  let save_cpo = &cpo
    545  new
    546  set cpo-=u
    547  exe "normal iabc\<C-G>udef\<C-G>ughi"
    548  normal uu
    549  call assert_equal('abc', getline(1))
    550  %d
    551  set cpo+=u
    552  exe "normal iabc\<C-G>udef\<C-G>ughi"
    553  normal uu
    554  call assert_equal('abcdefghi', getline(1))
    555  bw!
    556  let &cpo = save_cpo
    557 endfunc
    558 
    559 " TODO: Add a test for the 'v' flag in 'cpo'.
    560 " Backspaced characters remain visible on the screen in Insert mode.
    561 
    562 " Test for the 'w' flag in 'cpo' ('cw' on a blank character changes only one
    563 " character)
    564 func Test_cpo_w()
    565  let save_cpo = &cpo
    566  new
    567  " Nvim: no "w" flag in 'cpoptions'.
    568  " set cpo+=w
    569  " call setline(1, 'here      are   some words')
    570  " norm! 1gg0elcwZZZ
    571  " call assert_equal('hereZZZ     are   some words', getline('.'))
    572  " norm! 1gg2elcWYYY
    573  " call assert_equal('hereZZZ     areYYY  some words', getline('.'))
    574  set cpo-=w
    575  call setline(1, 'here      are   some words')
    576  norm! 1gg0elcwZZZ
    577  call assert_equal('hereZZZare   some words', getline('.'))
    578  norm! 1gg2elcWYYY
    579  call assert_equal('hereZZZare   someYYYwords', getline('.'))
    580  bw!
    581  let &cpo = save_cpo
    582 endfunc
    583 
    584 " Test for the 'W' flag in 'cpo' is in the test_writefile.vim file
    585 
    586 " Test for the 'x' flag in 'cpo' (Esc on command-line executes command)
    587 func Test_cpo_x()
    588  let save_cpo = &cpo
    589  set cpo-=x
    590  let i = 1
    591  call feedkeys(":let i=10\<Esc>", 'xt')
    592  call assert_equal(1, i)
    593  set cpo+=x
    594  call feedkeys(":let i=10\<Esc>", 'xt')
    595  call assert_equal(10, i)
    596  let &cpo = save_cpo
    597 endfunc
    598 
    599 " Test for the 'X' flag in 'cpo' ('R' with a count)
    600 func Test_cpo_X()
    601  let save_cpo = &cpo
    602  new
    603  call setline(1, 'aaaaaa')
    604  set cpo-=X
    605  normal gg4Rx
    606  call assert_equal('xxxxaa', getline(1))
    607  normal ggRy
    608  normal 4.
    609  call assert_equal('yyyyaa', getline(1))
    610  call setline(1, 'aaaaaa')
    611  set cpo+=X
    612  normal gg4Rx
    613  call assert_equal('xxxxaaaaa', getline(1))
    614  normal ggRy
    615  normal 4.
    616  call assert_equal('yyyyxxxaaaaa', getline(1))
    617  bw!
    618  let &cpo = save_cpo
    619 endfunc
    620 
    621 " Test for the 'y' flag in 'cpo' (repeating a yank command)
    622 func Test_cpo_y()
    623  let save_cpo = &cpo
    624  new
    625  call setline(1, ['one', 'two'])
    626  set cpo-=y
    627  normal ggyy
    628  normal 2G.
    629  call assert_equal("one\n", @")
    630  %d
    631  call setline(1, ['one', 'two'])
    632  set cpo+=y
    633  normal ggyy
    634  normal 2G.
    635  call assert_equal("two\n", @")
    636  bw!
    637  let &cpo = save_cpo
    638 endfunc
    639 
    640 " Test for the 'Z' flag in 'cpo' (write! resets 'readonly')
    641 func Test_cpo_Z()
    642  let save_cpo = &cpo
    643  call writefile([], 'XfileCpoZ', 'D')
    644  new XfileCpoZ
    645  setlocal readonly
    646  set cpo-=Z
    647  write!
    648  call assert_equal(0, &readonly)
    649  set cpo+=Z
    650  setlocal readonly
    651  write!
    652  call assert_equal(1, &readonly)
    653  bw!
    654  let &cpo = save_cpo
    655 endfunc
    656 
    657 " Test for the '!' flag in 'cpo' is in the test_normal.vim file
    658 
    659 " Test for displaying dollar when changing text ('$' flag in 'cpoptions')
    660 func Test_cpo_dollar()
    661  throw 'Skipped: use test/functional/legacy/cpoptions_spec.lua'
    662  new
    663  let g:Line = ''
    664  func SaveFirstLine()
    665    let g:Line = Screenline(1)
    666    return ''
    667  endfunc
    668  inoremap <expr> <buffer> <F2> SaveFirstLine()
    669  call test_override('redraw_flag', 1)
    670  set cpo+=$
    671  call setline(1, 'one two three')
    672  redraw!
    673  exe "normal c2w\<F2>vim"
    674  call assert_equal('one tw$ three', g:Line)
    675  call assert_equal('vim three', getline(1))
    676  set cpo-=$
    677  call test_override('ALL', 0)
    678  delfunc SaveFirstLine
    679  %bw!
    680 endfunc
    681 
    682 " Test for the '%' flag in 'cpo' (parenthesis matching inside strings)
    683 func Test_cpo_percent()
    684  let save_cpo = &cpo
    685  new
    686  call setline(1, '    if (strcmp("ab)cd(", s))')
    687  set cpo-=%
    688  normal 8|%
    689  call assert_equal(28, col('.'))
    690  normal 15|%
    691  call assert_equal(27, col('.'))
    692  normal 27|%
    693  call assert_equal(15, col('.'))
    694  call assert_beeps("normal 19|%")
    695  call assert_beeps("normal 22|%")
    696  set cpo+=%
    697  normal 8|%
    698  call assert_equal(28, col('.'))
    699  normal 15|%
    700  call assert_equal(19, col('.'))
    701  normal 27|%
    702  call assert_equal(22, col('.'))
    703  normal 19|%
    704  call assert_equal(15, col('.'))
    705  normal 22|%
    706  call assert_equal(27, col('.'))
    707  bw!
    708  let &cpo = save_cpo
    709 endfunc
    710 
    711 " Test for cursor movement with '-' in 'cpoptions'
    712 func Test_cpo_minus()
    713  throw 'Skipped: Nvim does not support cpoptions flag "-"'
    714  new
    715  call setline(1, ['foo', 'bar', 'baz'])
    716  let save_cpo = &cpo
    717  set cpo+=-
    718  call assert_beeps('normal 10j')
    719  call assert_equal(1, line('.'))
    720  normal G
    721  call assert_beeps('normal 10k')
    722  call assert_equal(3, line('.'))
    723  call assert_fails(10, 'E16:')
    724  bw!
    725  let &cpo = save_cpo
    726 endfunc
    727 
    728 " Test for the '+' flag in 'cpo' ('write file' command resets the 'modified'
    729 " flag)
    730 func Test_cpo_plus()
    731  let save_cpo = &cpo
    732  call writefile([], 'XfileCpoPlus', 'D')
    733  new XfileCpoPlus
    734  call setline(1, 'foo')
    735  write X1
    736  call assert_equal(1, &modified)
    737  set cpo+=+
    738  write X2
    739  call assert_equal(0, &modified)
    740  bw!
    741  call delete('X1')
    742  call delete('X2')
    743  let &cpo = save_cpo
    744 endfunc
    745 
    746 " Test for the '*' flag in 'cpo' (':*' is same as ':@')
    747 func Test_cpo_star()
    748  let save_cpo = &cpo
    749  let x = 0
    750  new
    751  set cpo-=*
    752  let @a = 'let x += 1'
    753  call assert_fails('*a', 'E20:')
    754  " Nvim: no "*" flag in 'cpoptions'.
    755  " set cpo+=*
    756  " *a
    757  " call assert_equal(1, x)
    758  bw!
    759  let &cpo = save_cpo
    760 endfunc
    761 
    762 " Test for the '<' flag in 'cpo' is in the test_mapping.vim file
    763 
    764 " Test for the '>' flag in 'cpo' (use a new line when appending to a register)
    765 func Test_cpo_gt()
    766  let save_cpo = &cpo
    767  new
    768  call setline(1, 'one two')
    769  set cpo-=>
    770  let @r = ''
    771  normal gg"Rye
    772  normal "Rye
    773  call assert_equal("oneone", @r)
    774  set cpo+=>
    775  let @r = ''
    776  normal gg"Rye
    777  normal "Rye
    778  call assert_equal("\none\none", @r)
    779  bw!
    780  let &cpo = save_cpo
    781 endfunc
    782 
    783 " Test for the ';' flag in 'cpo'
    784 " Test for t,f,F,T movement commands and 'cpo-;' setting
    785 func Test_cpo_semicolon()
    786  let save_cpo = &cpo
    787  new
    788  call append(0, ["aaa two three four", "    zzz", "yyy   ",
    789       \ "bbb yee yoo four", "ccc two three four",
    790       \ "ddd yee yoo four"])
    791  set cpo-=;
    792  1
    793  normal! 0tt;D
    794  2
    795  normal! 0fz;D
    796  3
    797  normal! $Fy;D
    798  4
    799  normal! $Ty;D
    800  set cpo+=;
    801  5
    802  normal! 0tt;;D
    803  6
    804  normal! $Ty;;D
    805 
    806  call assert_equal('aaa two', getline(1))
    807  call assert_equal('    z', getline(2))
    808  call assert_equal('y', getline(3))
    809  call assert_equal('bbb y', getline(4))
    810  call assert_equal('ccc', getline(5))
    811  call assert_equal('ddd yee y', getline(6))
    812  bw!
    813  let &cpo = save_cpo
    814 endfunc
    815 
    816 " Test for the '#' flag in 'cpo' (count before 'D', 'o' and 'O' operators)
    817 func Test_cpo_hash()
    818  let save_cpo = &cpo
    819  new
    820  set cpo-=#
    821  call setline(1, ['one', 'two', 'three'])
    822  normal gg2D
    823  call assert_equal(['three'], getline(1, '$'))
    824  normal gg2ofour
    825  call assert_equal(['three', 'four', 'four'], getline(1, '$'))
    826  normal gg2Otwo
    827  call assert_equal(['two', 'two', 'three', 'four', 'four'], getline(1, '$'))
    828  %d
    829  " Nvim: no "#" flag in 'cpoptions'.
    830  " set cpo+=#
    831  " call setline(1, ['one', 'two', 'three'])
    832  " normal gg2D
    833  " call assert_equal(['', 'two', 'three'], getline(1, '$'))
    834  " normal gg2oone
    835  " call assert_equal(['', 'one', 'two', 'three'], getline(1, '$'))
    836  " normal gg2Ozero
    837  " call assert_equal(['zero', '', 'one', 'two', 'three'], getline(1, '$'))
    838  bw!
    839  let &cpo = save_cpo
    840 endfunc
    841 
    842 " Test for the '&' flag in 'cpo'. The swap file is kept when a buffer is still
    843 " loaded and ':preserve' is used.
    844 func Test_cpo_ampersand()
    845  throw 'Skipped: Nvim does not support cpoptions flag "&"'
    846  call writefile(['one'], 'XfileCpoAmp', 'D')
    847  let after =<< trim [CODE]
    848    set cpo+=&
    849    preserve
    850    qall
    851  [CODE]
    852  if RunVim([], after, 'XfileCpoAmp')
    853    call assert_equal(1, filereadable('.XfileCpoAmp.swp'))
    854    call delete('.XfileCpoAmp.swp')
    855  endif
    856 endfunc
    857 
    858 " Test for the '\' flag in 'cpo' (backslash in a [] range in a search pattern)
    859 func Test_cpo_backslash()
    860  let save_cpo = &cpo
    861  new
    862  call setline(1, ['', " \\-string"])
    863  set cpo-=\
    864  exe 'normal gg/[ \-]' .. "\<CR>n"
    865  call assert_equal(3, col('.'))
    866  " Nvim: no "\" flag in 'cpoptions'.
    867  " set cpo+=\
    868  " exe 'normal gg/[ \-]' .. "\<CR>n"
    869  " call assert_equal(2, col('.'))
    870  bw!
    871  let &cpo = save_cpo
    872 endfunc
    873 
    874 " Test for the '/' flag in 'cpo' is in the test_substitute.vim file
    875 
    876 " Test for the '{' flag in 'cpo' (the "{" and "}" commands stop at a {
    877 " character at the start of a line)
    878 func Test_cpo_brace()
    879  let save_cpo = &cpo
    880  new
    881  call setline(1, ['', '{', '    int i;', '}', ''])
    882  set cpo-={
    883  normal gg}
    884  call assert_equal(5, line('.'))
    885  normal G{
    886  call assert_equal(1, line('.'))
    887  " Nvim: no "{" flag in 'cpoptions'.
    888  " set cpo+={
    889  " normal gg}
    890  " call assert_equal(2, line('.'))
    891  " normal G{
    892  " call assert_equal(2, line('.'))
    893  bw!
    894  let &cpo = save_cpo
    895 endfunc
    896 
    897 " Test for the '.' flag in 'cpo' (:cd command fails if the current buffer is
    898 " modified)
    899 func Test_cpo_dot()
    900  throw 'Skipped: Nvim does not support cpoptions flag "."'
    901  let save_cpo = &cpo
    902  new Xfoo
    903  call setline(1, 'foo')
    904  let save_dir = getcwd()
    905  set cpo+=.
    906 
    907  " :cd should fail when buffer is modified and 'cpo' contains dot.
    908  call assert_fails('cd ..', 'E747:')
    909  call assert_equal(save_dir, getcwd())
    910 
    911  " :cd with exclamation mark should succeed.
    912  cd! ..
    913  call assert_notequal(save_dir, getcwd())
    914 
    915  " :cd should succeed when buffer has been written.
    916  w!
    917  exe 'cd ' .. fnameescape(save_dir)
    918  call assert_equal(save_dir, getcwd())
    919 
    920  call delete('Xfoo')
    921  set cpo&
    922  bw!
    923  let &cpo = save_cpo
    924 endfunc
    925 
    926 " vim: shiftwidth=2 sts=2 expandtab