robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
881d17a113
master
1" Tests for 'backspace' settings 2 3func Test_backspace_option () 4set backspace = 5call assert_equal ( '' , & backspace ) 6set backspace = indent 7call assert_equal ( 'indent' , & backspace ) 8set backspace = eol 9call assert_equal ( 'eol' , & backspace ) 10set backspace = start 11call assert_equal ( 'start' , & backspace ) 12set backspace = nostop 13call assert_equal ( 'nostop' , & backspace ) 14" Add the value 15set backspace = 16set backspace = indent 17call assert_equal ( 'indent' , & backspace ) 18set backspace += eol 19call assert_equal ( 'indent,eol' , & backspace ) 20set backspace += start 21call assert_equal ( 'indent,eol,start' , & backspace ) 22set backspace += nostop 23call assert_equal ( 'indent,eol,start,nostop' , & backspace ) 24" Delete the value 25set backspace -= nostop 26call assert_equal ( 'indent,eol,start' , & backspace ) 27set backspace -= indent 28call assert_equal ( 'eol,start' , & backspace ) 29set backspace -= start 30call assert_equal ( 'eol' , & backspace ) 31set backspace -= eol 32call assert_equal ( '' , & backspace ) 33" Check the error 34call assert_fails ( 'set backspace=ABC' , 'E474:' ) 35call 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) 48call assert_fails ( 'set backspace=4' , 'E474:' ) 49call assert_fails ( 'set backspace=10' , 'E474:' ) 50 51" Cleared when 'compatible' is set 52" set compatible 53" call assert_equal('', &backspace) 54set nocompatible viminfo += nviminfo 55endfunc 56 57" Test with backspace set to the non-compatible setting 58func Test_backspace_ctrl_u () 59new 60call 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)" ]) 69call cursor ( 2 , 1 ) 70 71" set compatible 72set backspace = 2 73 74exe "normal Avim1\<C-U>\<Esc>\<CR>" 75exe "normal Avim2\<C-G>u\<C-U>\<Esc>\<CR>" 76 77set cpo -= < 78inoremap < c-u > < left > <c-u > 79exe "normal Avim3\<*C-U>\<Esc>\<CR>" 80iunmap <c-u> 81exe "normal Avim4\<C-U>\<C-U>\<Esc>\<CR>" 82 83" Test with backspace set to the compatible setting 84set backspace = visualbell 85exe "normal A vim5\<Esc>A\<C-U>\<C-U>\<Esc>\<CR>" 86exe "normal A vim6\<Esc>Azwei\<C-G>u\<C-U>\<Esc>\<CR>" 87 88inoremap < c-u > < left > <c-u > 89exe "normal A vim7\<*C-U>\<*C-U>\<Esc>\<CR>" 90 91call 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 103set compatible & vim 104set visualbell & vim 105set backspace & vim 106 107" Test new nostop option 108 %d _ 109let expected = "foo bar foobar" 110call setline ( 1 , expected ) 111call cursor ( 1 , 8 ) 112exe ":norm! ianotherone\<c-u>" 113call assert_equal ( expected , getline ( 1 )) 114call cursor ( 1 , 8 ) 115exe ":norm! ianothertwo\<c-w>" 116call assert_equal ( expected , getline ( 1 )) 117 118let content = getline ( 1 ) 119for value in [ 'indent,nostop' , 'eol,nostop' , 'indent,eol,nostop' , 'indent,eol,start,nostop' ] 120exe ":set bs=" .. value 121 %d _ 122call setline ( 1 , content ) 123let expected = " foobar" 124call cursor ( 1 , 8 ) 125exe ":norm! ianotherone\<c-u>" 126call assert_equal ( expected , getline ( 1 ), 'CTRL-U backspace value: ' .. & bs ) 127let expected = "foo foobar" 128call setline ( 1 , content ) 129call cursor ( 1 , 8 ) 130exe ":norm! ianothertwo\<c-w>" 131call assert_equal ( expected , getline ( 1 ), 'CTRL-W backspace value: ' .. & bs ) 132endfor 133 134" Reset options 135set compatible & vim 136set visualbell & vim 137set backspace & vim 138close ! 139endfunc 140 141" vim: shiftwidth=2 sts=2 expandtab