blob: ad051cca4565f5c57eea42c117d185c59a7ce65f [file] [log] [blame]
Bram Moolenaar27a82e32016-01-02 21:39:09 +01001" Tests for 'backspace' settings
2
Bram Moolenaar004a6782020-04-11 17:09:31 +02003func Exec(expr)
Bram Moolenaar27a82e32016-01-02 21:39:09 +01004 let str=''
5 try
6 exec a:expr
7 catch /.*/
8 let str=v:exception
9 endtry
10 return str
Bram Moolenaar004a6782020-04-11 17:09:31 +020011endfunc
Bram Moolenaar27a82e32016-01-02 21:39:09 +010012
13func 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 Moolenaaraa0489e2020-04-17 19:41:21 +020022 set backspace=nostop
23 call assert_equal('nostop', &backspace)
Bram Moolenaar27a82e32016-01-02 21:39:09 +010024 " 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 Moolenaaraa0489e2020-04-17 19:41:21 +020032 set backspace+=nostop
33 call assert_equal('indent,eol,start,nostop', &backspace)
Bram Moolenaar27a82e32016-01-02 21:39:09 +010034 " Delete the value
Bram Moolenaaraa0489e2020-04-17 19:41:21 +020035 set backspace-=nostop
36 call assert_equal('indent,eol,start', &backspace)
Bram Moolenaar27a82e32016-01-02 21:39:09 +010037 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 Moolenaaraa0489e2020-04-17 19:41:21 +020056 set backspace=3
57 call assert_equal('3', &backspace)
58 call assert_false(match(Exec('set backspace=4'), '.*E474'))
Bram Moolenaar27a82e32016-01-02 21:39:09 +010059 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 Moolenaare9c07272016-03-30 20:50:46 +020064 set nocompatible viminfo+=nviminfo
Bram Moolenaar27a82e32016-01-02 21:39:09 +010065endfunc
66
Bram Moolenaarfb222df2019-05-14 17:57:19 +020067" Test with backspace set to the non-compatible setting
68func 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>
89 exe "normal Avim3\<C-U>\<Esc>\<CR>"
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>
99 exe "normal A vim7\<C-U>\<C-U>\<Esc>\<CR>"
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 Moolenaaraa0489e2020-04-17 19:41:21 +0200112 " 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 Moolenaarfb222df2019-05-14 17:57:19 +0200145 set compatible&vim
146 set visualbell&vim
147 set backspace&vim
148 close!
149endfunc
150
Bram Moolenaar9e4d8212016-08-18 23:04:48 +0200151" vim: shiftwidth=2 sts=2 expandtab