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