comparison src/testdir/test_vartabs.vim @ 14175:2ad722003b36 v8.1.0105

patch 8.1.0105: all tab stops are the same commit https://github.com/vim/vim/commit/04958cbaf25eea27eceedaa987adfb354ad5f7fd Author: Bram Moolenaar <Bram@vim.org> Date: Sat Jun 23 19:23:02 2018 +0200 patch 8.1.0105: all tab stops are the same Problem: All tab stops are the same. Solution: Add the variable tabstop feature. (Christian Brabandt, closes #2711)
author Christian Brabandt <cb@256bit.org>
date Sat, 23 Jun 2018 19:30:07 +0200
parents
children 9ca8c36869ce
comparison
equal deleted inserted replaced
14174:d36eedd19166 14175:2ad722003b36
1 " Test for variable tabstops
2
3 if !has("vartabs")
4 finish
5 endif
6
7 func! Test_vartabs()
8 new
9 %d
10
11 " Test normal operation of tabstops ...
12 set ts=4
13 call setline(1, join(split('aaaaa', '\zs'), "\t"))
14 retab 8
15 let expect = "a a\<tab>a a\<tab>a"
16 call assert_equal(expect, getline(1))
17
18 " ... and softtabstops
19 set ts=8 sts=6
20 exe "norm! Sb\<tab>b\<tab>b\<tab>b\<tab>b"
21 let expect = "b b\<tab> b\<tab> b\<tab>b"
22 call assert_equal(expect, getline(1))
23
24 " Test variable tabstops.
25 set sts=0 vts=4,8,4,8
26 exe "norm! Sc\<tab>c\<tab>c\<tab>c\<tab>c\<tab>c"
27 retab 8
28 let expect = "c c\<tab> c\<tab>c\<tab>c\<tab>c"
29 call assert_equal(expect, getline(1))
30
31 set et vts=4,8,4,8
32 exe "norm! Sd\<tab>d\<tab>d\<tab>d\<tab>d\<tab>d"
33 let expect = "d d d d d d"
34 call assert_equal(expect, getline(1))
35
36 " Changing ts should have no effect if vts is in use.
37 call cursor(1, 1)
38 set ts=6
39 exe "norm! Se\<tab>e\<tab>e\<tab>e\<tab>e\<tab>e"
40 let expect = "e e e e e e"
41 call assert_equal(expect, getline(1))
42
43 " Clearing vts should revert to using ts.
44 set vts=
45 exe "norm! Sf\<tab>f\<tab>f\<tab>f\<tab>f\<tab>f"
46 let expect = "f f f f f f"
47 call assert_equal(expect, getline(1))
48
49 " Test variable softtabstops.
50 set noet ts=8 vsts=12,2,6
51 exe "norm! Sg\<tab>g\<tab>g\<tab>g\<tab>g\<tab>g"
52 let expect = "g\<tab> g g\<tab> g\<tab> g\<tab>g"
53 call assert_equal(expect, getline(1))
54
55 " Variable tabstops and softtabstops combined.
56 set vsts=6,12,8 vts=4,6,8
57 exe "norm! Sh\<tab>h\<tab>h\<tab>h\<tab>h"
58 let expect = "h\<tab> h\<tab>\<tab>h\<tab>h\<tab>h"
59 call assert_equal(expect, getline(1))
60
61 " Retab with a single value, not using vts.
62 set ts=8 sts=0 vts= vsts=
63 exe "norm! Si\<tab>i\<tab>i\<tab>i\<tab>i"
64 retab 4
65 let expect = "i\<tab>\<tab>i\<tab>\<tab>i\<tab>\<tab>i\<tab>\<tab>i"
66 call assert_equal(expect, getline(1))
67
68 " Retab with a single value, using vts.
69 set ts=8 sts=0 vts=6 vsts=
70 exe "norm! Sj\<tab>j\<tab>j\<tab>j\<tab>j"
71 retab 4
72 let expect = "j\<tab> j\<tab>\<tab>j\<tab> j\<tab>\<tab>j"
73 call assert_equal(expect, getline(1))
74
75 " Retab with multiple values, not using vts.
76 set ts=6 sts=0 vts= vsts=
77 exe "norm! Sk\<tab>k\<tab>k\<tab>k\<tab>k\<tab>k"
78 retab 4,8
79 let expect = "k\<tab> k\<tab>k k\<tab> k\<tab> k"
80 call assert_equal(expect, getline(1))
81
82 " Retab with multiple values, using vts.
83 set ts=8 sts=0 vts=6 vsts=
84 exe "norm! Sl\<tab>l\<tab>l\<tab>l\<tab>l\<tab>l"
85 retab 4,8
86 let expect = "l\<tab> l\<tab>l l\<tab> l\<tab> l"
87 call assert_equal(expect, getline(1))
88
89 " Check that global and local values are set.
90 set ts=4 vts=6 sts=8 vsts=10
91 call assert_equal(&ts, 4)
92 call assert_equal(&vts, '6')
93 call assert_equal(&sts, 8)
94 call assert_equal(&vsts, '10')
95 new
96 call assert_equal(&ts, 4)
97 call assert_equal(&vts, '6')
98 call assert_equal(&sts, 8)
99 call assert_equal(&vsts, '10')
100 bwipeout!
101
102 " Check that local values only are set.
103 setlocal ts=5 vts=7 sts=9 vsts=11
104 call assert_equal(&ts, 5)
105 call assert_equal(&vts, '7')
106 call assert_equal(&sts, 9)
107 call assert_equal(&vsts, '11')
108 new
109 call assert_equal(&ts, 4)
110 call assert_equal(&vts, '6')
111 call assert_equal(&sts, 8)
112 call assert_equal(&vsts, '10')
113 bwipeout!
114
115 " Check that global values only are set.
116 setglobal ts=6 vts=8 sts=10 vsts=12
117 call assert_equal(&ts, 5)
118 call assert_equal(&vts, '7')
119 call assert_equal(&sts, 9)
120 call assert_equal(&vsts, '11')
121 new
122 call assert_equal(&ts, 6)
123 call assert_equal(&vts, '8')
124 call assert_equal(&sts, 10)
125 call assert_equal(&vsts, '12')
126 bwipeout!
127
128 set ts& vts& sts& vsts& et&
129 bwipeout!
130 endfunc
131
132 func! Test_vartabs_breakindent()
133 if !exists("+breakindent")
134 return
135 endif
136 new
137 %d
138
139 " Test normal operation of tabstops ...
140 set ts=4
141 call setline(1, join(split('aaaaa', '\zs'), "\t"))
142 retab 8
143 let expect = "a a\<tab>a a\<tab>a"
144 call assert_equal(expect, getline(1))
145
146 " ... and softtabstops
147 set ts=8 sts=6
148 exe "norm! Sb\<tab>b\<tab>b\<tab>b\<tab>b"
149 let expect = "b b\<tab> b\<tab> b\<tab>b"
150 call assert_equal(expect, getline(1))
151
152 " Test variable tabstops.
153 set sts=0 vts=4,8,4,8
154 exe "norm! Sc\<tab>c\<tab>c\<tab>c\<tab>c\<tab>c"
155 retab 8
156 let expect = "c c\<tab> c\<tab>c\<tab>c\<tab>c"
157 call assert_equal(expect, getline(1))
158
159 set et vts=4,8,4,8
160 exe "norm! Sd\<tab>d\<tab>d\<tab>d\<tab>d\<tab>d"
161 let expect = "d d d d d d"
162 call assert_equal(expect, getline(1))
163
164 " Changing ts should have no effect if vts is in use.
165 call cursor(1, 1)
166 set ts=6
167 exe "norm! Se\<tab>e\<tab>e\<tab>e\<tab>e\<tab>e"
168 let expect = "e e e e e e"
169 call assert_equal(expect, getline(1))
170
171 " Clearing vts should revert to using ts.
172 set vts=
173 exe "norm! Sf\<tab>f\<tab>f\<tab>f\<tab>f\<tab>f"
174 let expect = "f f f f f f"
175 call assert_equal(expect, getline(1))
176
177 " Test variable softtabstops.
178 set noet ts=8 vsts=12,2,6
179 exe "norm! Sg\<tab>g\<tab>g\<tab>g\<tab>g\<tab>g"
180 let expect = "g\<tab> g g\<tab> g\<tab> g\<tab>g"
181 call assert_equal(expect, getline(1))
182
183 " Variable tabstops and softtabstops combined.
184 set vsts=6,12,8 vts=4,6,8
185 exe "norm! Sh\<tab>h\<tab>h\<tab>h\<tab>h"
186 let expect = "h\<tab> h\<tab>\<tab>h\<tab>h\<tab>h"
187 call assert_equal(expect, getline(1))
188
189 " Retab with a single value, not using vts.
190 set ts=8 sts=0 vts= vsts=
191 exe "norm! Si\<tab>i\<tab>i\<tab>i\<tab>i"
192 retab 4
193 let expect = "i\<tab>\<tab>i\<tab>\<tab>i\<tab>\<tab>i\<tab>\<tab>i"
194 call assert_equal(expect, getline(1))
195
196 " Retab with a single value, using vts.
197 set ts=8 sts=0 vts=6 vsts=
198 exe "norm! Sj\<tab>j\<tab>j\<tab>j\<tab>j"
199 retab 4
200 let expect = "j\<tab> j\<tab>\<tab>j\<tab> j\<tab>\<tab>j"
201 call assert_equal(expect, getline(1))
202
203 " Retab with multiple values, not using vts.
204 set ts=6 sts=0 vts= vsts=
205 exe "norm! Sk\<tab>k\<tab>k\<tab>k\<tab>k\<tab>k"
206 retab 4,8
207 let expect = "k\<tab> k\<tab>k k\<tab> k\<tab> k"
208 call assert_equal(expect, getline(1))
209
210 " Retab with multiple values, using vts.
211 set ts=8 sts=0 vts=6 vsts=
212 exe "norm! Sl\<tab>l\<tab>l\<tab>l\<tab>l\<tab>l"
213 retab 4,8
214 let expect = "l\<tab> l\<tab>l l\<tab> l\<tab> l"
215 call assert_equal(expect, getline(1))
216
217 " Check that global and local values are set.
218 set ts=4 vts=6 sts=8 vsts=10
219 call assert_equal(&ts, 4)
220 call assert_equal(&vts, '6')
221 call assert_equal(&sts, 8)
222 call assert_equal(&vsts, '10')
223 new
224 call assert_equal(&ts, 4)
225 call assert_equal(&vts, '6')
226 call assert_equal(&sts, 8)
227 call assert_equal(&vsts, '10')
228 bwipeout!
229
230 " Check that local values only are set.
231 setlocal ts=5 vts=7 sts=9 vsts=11
232 call assert_equal(&ts, 5)
233 call assert_equal(&vts, '7')
234 call assert_equal(&sts, 9)
235 call assert_equal(&vsts, '11')
236 new
237 call assert_equal(&ts, 4)
238 call assert_equal(&vts, '6')
239 call assert_equal(&sts, 8)
240 call assert_equal(&vsts, '10')
241 bwipeout!
242
243 " Check that global values only are set.
244 setglobal ts=6 vts=8 sts=10 vsts=12
245 call assert_equal(&ts, 5)
246 call assert_equal(&vts, '7')
247 call assert_equal(&sts, 9)
248 call assert_equal(&vsts, '11')
249 new
250 call assert_equal(&ts, 6)
251 call assert_equal(&vts, '8')
252 call assert_equal(&sts, 10)
253 call assert_equal(&vsts, '12')
254 bwipeout!
255
256 bwipeout!
257 endfunc