neovim

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

test_backspace_opt.vim (4191B)


      1 " Tests for 'backspace' settings
      2 
      3 func Test_backspace_option()
      4  set backspace=
      5  call assert_equal('', &backspace)
      6  set backspace=indent
      7  call assert_equal('indent', &backspace)
      8  set backspace=eol
      9  call assert_equal('eol', &backspace)
     10  set backspace=start
     11  call assert_equal('start', &backspace)
     12  set backspace=nostop
     13  call assert_equal('nostop', &backspace)
     14  " Add the value
     15  set backspace=
     16  set backspace=indent
     17  call assert_equal('indent', &backspace)
     18  set backspace+=eol
     19  call assert_equal('indent,eol', &backspace)
     20  set backspace+=start
     21  call assert_equal('indent,eol,start', &backspace)
     22  set backspace+=nostop
     23  call assert_equal('indent,eol,start,nostop', &backspace)
     24  " Delete the value
     25  set backspace-=nostop
     26  call assert_equal('indent,eol,start', &backspace)
     27  set backspace-=indent
     28  call assert_equal('eol,start', &backspace)
     29  set backspace-=start
     30  call assert_equal('eol', &backspace)
     31  set backspace-=eol
     32  call assert_equal('', &backspace)
     33  " Check the error
     34  call assert_fails('set backspace=ABC', 'E474:')
     35  call assert_fails('set backspace+=def', 'E474:')
     36  " NOTE: Vim doesn't check following error...
     37  "call assert_fails('set backspace-=ghi', 'E474:')
     38 
     39  " " Check backwards compatibility with version 5.4 and earlier
     40  " set backspace=0
     41  " call assert_equal('0', &backspace)
     42  " set backspace=1
     43  " call assert_equal('1', &backspace)
     44  " set backspace=2
     45  " call assert_equal('2', &backspace)
     46  " set backspace=3
     47  " call assert_equal('3', &backspace)
     48  call assert_fails('set backspace=4', 'E474:')
     49  call assert_fails('set backspace=10', 'E474:')
     50 
     51  " Cleared when 'compatible' is set
     52  " set compatible
     53  " call assert_equal('', &backspace)
     54  set nocompatible viminfo+=nviminfo
     55 endfunc
     56 
     57 " Test with backspace set to the non-compatible setting
     58 func Test_backspace_ctrl_u()
     59  new
     60  call append(0,  [
     61        \ "1 this shouldn't be deleted",
     62        \ "2 this shouldn't be deleted",
     63        \ "3 this shouldn't be deleted",
     64        \ "4 this should be deleted",
     65        \ "5 this shouldn't be deleted",
     66        \ "6 this shouldn't be deleted",
     67        \ "7 this shouldn't be deleted",
     68        \ "8 this shouldn't be deleted (not touched yet)"])
     69  call cursor(2, 1)
     70 
     71  " set compatible
     72  set backspace=2
     73 
     74  exe "normal Avim1\<C-U>\<Esc>\<CR>"
     75  exe "normal Avim2\<C-G>u\<C-U>\<Esc>\<CR>"
     76 
     77  set cpo-=<
     78  inoremap <c-u> <left><c-u>
     79  exe "normal Avim3\<*C-U>\<Esc>\<CR>"
     80  iunmap <c-u>
     81  exe "normal Avim4\<C-U>\<C-U>\<Esc>\<CR>"
     82 
     83  " Test with backspace set to the compatible setting
     84  set backspace= visualbell
     85  exe "normal A vim5\<Esc>A\<C-U>\<C-U>\<Esc>\<CR>"
     86  exe "normal A vim6\<Esc>Azwei\<C-G>u\<C-U>\<Esc>\<CR>"
     87 
     88  inoremap <c-u> <left><c-u>
     89  exe "normal A vim7\<*C-U>\<*C-U>\<Esc>\<CR>"
     90 
     91  call assert_equal([
     92        \ "1 this shouldn't be deleted",
     93        \ "2 this shouldn't be deleted",
     94        \ "3 this shouldn't be deleted",
     95        \ "4 this should be deleted3",
     96        \ "",
     97        \ "6 this shouldn't be deleted vim5",
     98        \ "7 this shouldn't be deleted vim6",
     99        \ "8 this shouldn't be deleted (not touched yet) vim7",
    100        \ ""], getline(1, '$'))
    101 
    102  " Reset values
    103  set compatible&vim
    104  set visualbell&vim
    105  set backspace&vim
    106 
    107  " Test new nostop option
    108  %d_
    109  let expected = "foo bar foobar"
    110  call setline(1, expected)
    111  call cursor(1, 8)
    112  exe ":norm! ianotherone\<c-u>"
    113  call assert_equal(expected, getline(1))
    114  call cursor(1, 8)
    115  exe ":norm! ianothertwo\<c-w>"
    116  call assert_equal(expected, getline(1))
    117 
    118  let content = getline(1)
    119  for value in ['indent,nostop', 'eol,nostop', 'indent,eol,nostop', 'indent,eol,start,nostop']
    120    exe ":set bs=".. value
    121    %d _
    122    call setline(1, content)
    123    let expected = " foobar"
    124    call cursor(1, 8)
    125    exe ":norm! ianotherone\<c-u>"
    126    call assert_equal(expected, getline(1), 'CTRL-U backspace value: '.. &bs)
    127    let expected = "foo  foobar"
    128    call setline(1, content)
    129    call cursor(1, 8)
    130    exe ":norm! ianothertwo\<c-w>"
    131    call assert_equal(expected, getline(1), 'CTRL-W backspace value: '.. &bs)
    132  endfor
    133 
    134  " Reset options
    135  set compatible&vim
    136  set visualbell&vim
    137  set backspace&vim
    138  close!
    139 endfunc
    140 
    141 " vim: shiftwidth=2 sts=2 expandtab