Bram Moolenaar | 27a82e3 | 2016-01-02 21:39:09 +0100 | [diff] [blame] | 1 | " Tests for 'backspace' settings |
| 2 | |
| 3 | :func Exec(expr) |
| 4 | let str='' |
| 5 | try |
| 6 | exec a:expr |
| 7 | catch /.*/ |
| 8 | let str=v:exception |
| 9 | endtry |
| 10 | return str |
| 11 | :endfunc |
| 12 | |
| 13 | func Test_backspace_option() |
| 14 | set backspace= |
| 15 | call assert_equal('', &backspace) |
| 16 | set backspace=indent |
| 17 | call assert_equal('indent', &backspace) |
| 18 | set backspace=eol |
| 19 | call assert_equal('eol', &backspace) |
| 20 | set backspace=start |
| 21 | call assert_equal('start', &backspace) |
| 22 | " Add the value |
| 23 | set backspace= |
| 24 | set backspace=indent |
| 25 | call assert_equal('indent', &backspace) |
| 26 | set backspace+=eol |
| 27 | call assert_equal('indent,eol', &backspace) |
| 28 | set backspace+=start |
| 29 | call assert_equal('indent,eol,start', &backspace) |
| 30 | " Delete the value |
| 31 | set backspace-=indent |
| 32 | call assert_equal('eol,start', &backspace) |
| 33 | set backspace-=start |
| 34 | call assert_equal('eol', &backspace) |
| 35 | set backspace-=eol |
| 36 | call assert_equal('', &backspace) |
| 37 | " Check the error |
| 38 | call assert_equal(0, match(Exec('set backspace=ABC'), '.*E474')) |
| 39 | call assert_equal(0, match(Exec('set backspace+=def'), '.*E474')) |
| 40 | " NOTE: Vim doesn't check following error... |
| 41 | "call assert_equal(0, match(Exec('set backspace-=ghi'), '.*E474')) |
| 42 | |
| 43 | " Check backwards compatibility with version 5.4 and earlier |
| 44 | set backspace=0 |
| 45 | call assert_equal('0', &backspace) |
| 46 | set backspace=1 |
| 47 | call assert_equal('1', &backspace) |
| 48 | set backspace=2 |
| 49 | call assert_equal('2', &backspace) |
| 50 | call assert_false(match(Exec('set backspace=3'), '.*E474')) |
| 51 | call assert_false(match(Exec('set backspace=10'), '.*E474')) |
| 52 | |
| 53 | " Cleared when 'compatible' is set |
| 54 | set compatible |
| 55 | call assert_equal('', &backspace) |
Bram Moolenaar | e9c0727 | 2016-03-30 20:50:46 +0200 | [diff] [blame] | 56 | set nocompatible viminfo+=nviminfo |
Bram Moolenaar | 27a82e3 | 2016-01-02 21:39:09 +0100 | [diff] [blame] | 57 | endfunc |
| 58 | |
Bram Moolenaar | fb222df | 2019-05-14 17:57:19 +0200 | [diff] [blame] | 59 | " Test with backspace set to the non-compatible setting |
| 60 | func Test_backspace_ctrl_u() |
| 61 | new |
| 62 | call append(0, [ |
| 63 | \ "1 this shouldn't be deleted", |
| 64 | \ "2 this shouldn't be deleted", |
| 65 | \ "3 this shouldn't be deleted", |
| 66 | \ "4 this should be deleted", |
| 67 | \ "5 this shouldn't be deleted", |
| 68 | \ "6 this shouldn't be deleted", |
| 69 | \ "7 this shouldn't be deleted", |
| 70 | \ "8 this shouldn't be deleted (not touched yet)"]) |
| 71 | call cursor(2, 1) |
| 72 | |
| 73 | set compatible |
| 74 | set backspace=2 |
| 75 | |
| 76 | exe "normal Avim1\<C-U>\<Esc>\<CR>" |
| 77 | exe "normal Avim2\<C-G>u\<C-U>\<Esc>\<CR>" |
| 78 | |
| 79 | set cpo-=< |
| 80 | inoremap <c-u> <left><c-u> |
| 81 | exe "normal Avim3\<C-U>\<Esc>\<CR>" |
| 82 | iunmap <c-u> |
| 83 | exe "normal Avim4\<C-U>\<C-U>\<Esc>\<CR>" |
| 84 | |
| 85 | " Test with backspace set to the compatible setting |
| 86 | set backspace= visualbell |
| 87 | exe "normal A vim5\<Esc>A\<C-U>\<C-U>\<Esc>\<CR>" |
| 88 | exe "normal A vim6\<Esc>Azwei\<C-G>u\<C-U>\<Esc>\<CR>" |
| 89 | |
| 90 | inoremap <c-u> <left><c-u> |
| 91 | exe "normal A vim7\<C-U>\<C-U>\<Esc>\<CR>" |
| 92 | |
| 93 | call assert_equal([ |
| 94 | \ "1 this shouldn't be deleted", |
| 95 | \ "2 this shouldn't be deleted", |
| 96 | \ "3 this shouldn't be deleted", |
| 97 | \ "4 this should be deleted3", |
| 98 | \ "", |
| 99 | \ "6 this shouldn't be deleted vim5", |
| 100 | \ "7 this shouldn't be deleted vim6", |
| 101 | \ "8 this shouldn't be deleted (not touched yet) vim7", |
| 102 | \ ""], getline(1, '$')) |
| 103 | |
| 104 | set compatible&vim |
| 105 | set visualbell&vim |
| 106 | set backspace&vim |
| 107 | close! |
| 108 | endfunc |
| 109 | |
Bram Moolenaar | 9e4d821 | 2016-08-18 23:04:48 +0200 | [diff] [blame] | 110 | " vim: shiftwidth=2 sts=2 expandtab |